Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Create a path string

Reply
 
Old 04-08-2009   #1 (permalink)
John Denver


 
 

Create a path string

Hello

I've got a program that I run quite a few times, and I've been doing it via
cmd line, and I'd like to create a VBscript and use wshshell.run to excute
this.


I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe
disable "Local Area Connection"

Now I can't seem to get my path correct for wshshell.run I think whats
really giving me issues is that I need "" around the Local Area Connection.

I've got a variable setup for the program path

Const Mystring = "c:\Program Files\Some Folder\program.exe" then
Const Constring = "Local Area Connection "

wshShell.run Mystring & " disable " & """ & connectionstring & """", 3, true


Any ideas on the correct way to do this?

Thanks







My System SpecsSystem Spec
Old 04-08-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Create a path string


"John Denver" <nospam@xxxxxx> wrote in message
news:OB%23%23$TGuJHA.4632@xxxxxx
Quote:

> Hello
>
> I've got a program that I run quite a few times, and I've been doing it
> via cmd line, and I'd like to create a VBscript and use wshshell.run to
> excute this.
>
>
> I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe
> disable "Local Area Connection"
>
> Now I can't seem to get my path correct for wshshell.run I think whats
> really giving me issues is that I need "" around the Local Area
> Connection.
>
> I've got a variable setup for the program path
>
> Const Mystring = "c:\Program Files\Some Folder\program.exe" then
> Const Constring = "Local Area Connection "
>
> wshShell.run Mystring & " disable " & """ & connectionstring & """", 3,
> true
>
>
> Any ideas on the correct way to do this?
>
> Thanks
If you want the simplest of all solutions to automate this process then the
answer is a humble batch file:

@echo off
"c:\Program Files\Some Folder\program.exe" disable "Local Area Connection"


My System SpecsSystem Spec
Old 04-08-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Create a path string


"John Denver" <nospam@xxxxxx> wrote in message
news:OB%23%23$TGuJHA.4632@xxxxxx
Quote:

> Hello
>
> I've got a program that I run quite a few times, and I've been doing it
> via cmd line, and I'd like to create a VBscript and use wshshell.run to
> excute this.
>
>
> I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe
> disable "Local Area Connection"
>
> Now I can't seem to get my path correct for wshshell.run I think whats
> really giving me issues is that I need "" around the Local Area
> Connection.
>
> I've got a variable setup for the program path
>
> Const Mystring = "c:\Program Files\Some Folder\program.exe" then
> Const Constring = "Local Area Connection "
>
> wshShell.run Mystring & " disable " & """ & connectionstring & """", 3,
> true
>
>
> Any ideas on the correct way to do this?
>
> Thanks
>
Because the path has spaces, it must be enclosed in quotes. Embedded quotes
in a quotes string must be doubled. I would try something similar to:

strCmd = "%comspec% /c ""c:\Program Files\Some Folder\program.exe"" disable
""Local Area Connection"""
Wscript.Echo "Command to run: " & strCmd
Set wshShell = CreateObject("Wscript.Shell")
wshShell.Run strCmd, 3, True

The Wscript.Echo statement is for troubleshooting, but it should display
what will be run. The %comspec% ensures that the correct command processor
for your OS is used, the /c closes the command shell when the command
completes.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 04-08-2009   #4 (permalink)
gimme_this_gimme_that


 
 

Re: Create a path string


Const Mystring = "c:\Program Files\Some Folder\program.exe"
Const Constring = "Local Area Connection "
Set WSH = CreateObject("WScript.Shell")
WSH.Run(escape(Mystring) & " " & Chr(34) & Constring & Chr(34))
My System SpecsSystem Spec
Old 04-08-2009   #5 (permalink)
ekkehard.horner


 
 

Re: Create a path string

gimme_this_gimme_that@xxxxxx schrieb:
Quote:

> Const Mystring = "c:\Program Files\Some Folder\program.exe"
> Const Constring = "Local Area Connection "
> Set WSH = CreateObject("WScript.Shell")
> WSH.Run(escape(Mystring) & " " & Chr(34) & Constring & Chr(34))
See

(1) Richard Mueller's solution to understand, why double quotes
are needed for the file specification of the executable

(2) the VBScript Docs, Topic "Escape Function" to understand, why
the use of the Escape function is misguided

(3) the VBScript Docs, Topic "VBScript Procedures" to understand,
why the () in the .Run statement are wrong/misleading
My System SpecsSystem Spec
Old 04-08-2009   #6 (permalink)
gimme_this_gimme_that


 
 

Re: Create a path string

Quote:

> (1) Richard Mueller's solution to understand, why double quotes
> * * *are needed for the file specification of the executable
Isn't char(34) and a double quote the same thing?
Quote:

> (2) the VBScript Docs, Topic "Escape Function" to understand, why
> * * *the use of the Escape function is misguided
Did you know the script56.chm, the "VBScript Docs" document at M$ is
corrupted?

Quote:

> (3) the VBScript Docs, Topic "VBScript Procedures" to understand,
> * * *why the () in the .Run statement are wrong/misleading
What I posted works. I thought the OP wanted a solution. Not you.




My System SpecsSystem Spec
Old 04-08-2009   #7 (permalink)
John Denver


 
 

Re: Create a path string

Thanks for the tips, got it working.

now, will the WshShell.run return me the completion status of c:\Program
Files\Some Folder\program.exe


"John Denver" <nospam@xxxxxx> wrote in message
news:OB%23%23$TGuJHA.4632@xxxxxx
Quote:

> Hello
>
> I've got a program that I run quite a few times, and I've been doing it
> via cmd line, and I'd like to create a VBscript and use wshshell.run to
> excute this.
>
>
> I normally type from a cmd prompt c:\Program Files\Some Folder\program.exe
> disable "Local Area Connection"
>
> Now I can't seem to get my path correct for wshshell.run I think whats
> really giving me issues is that I need "" around the Local Area
> Connection.
>
> I've got a variable setup for the program path
>
> Const Mystring = "c:\Program Files\Some Folder\program.exe" then
> Const Constring = "Local Area Connection "
>
> wshShell.run Mystring & " disable " & """ & connectionstring & """", 3,
> true
>
>
> Any ideas on the correct way to do this?
>
> Thanks
>
>
>
>
>
>

My System SpecsSystem Spec
Old 04-08-2009   #8 (permalink)
Richard Mueller [MVP]


 
 

Re: Create a path string

In some cases, yes. If the program returns an exit code and does not spawn
another process, you can retrieve the exit code. A zero would indicate no
error. For example:

intError = wshShell.Run(strCmd, 3, True)
Wscript.Echo "Exit code: " & CStr(intError)

You must use True as the third parameter (indicating to wait for the program
to complete) for this to work.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"John Denver" <nospam@xxxxxx> wrote in message
news:%23AUy6VJuJHA.5172@xxxxxx
Quote:

> Thanks for the tips, got it working.
>
> now, will the WshShell.run return me the completion status of c:\Program
> Files\Some Folder\program.exe
>
>
> "John Denver" <nospam@xxxxxx> wrote in message
> news:OB%23%23$TGuJHA.4632@xxxxxx
Quote:

>> Hello
>>
>> I've got a program that I run quite a few times, and I've been doing it
>> via cmd line, and I'd like to create a VBscript and use wshshell.run to
>> excute this.
>>
>>
>> I normally type from a cmd prompt c:\Program Files\Some
>> Folder\program.exe disable "Local Area Connection"
>>
>> Now I can't seem to get my path correct for wshshell.run I think whats
>> really giving me issues is that I need "" around the Local Area
>> Connection.
>>
>> I've got a variable setup for the program path
>>
>> Const Mystring = "c:\Program Files\Some Folder\program.exe" then
>> Const Constring = "Local Area Connection "
>>
>> wshShell.run Mystring & " disable " & """ & connectionstring & """", 3,
>> true
>>
>>
>> Any ideas on the correct way to do this?
>>
>> Thanks
>>
>>
>>
>>
>>
>>
>
>

My System SpecsSystem Spec
Old 04-08-2009   #9 (permalink)
Paul Randall


 
 

Re: Create a path string


<gimme_this_gimme_that@xxxxxx> wrote in message
news:0acb211c-e855-471b-8740-1618ecb1dbac@xxxxxx
Quote:

> (2) the VBScript Docs, Topic "Escape Function" to understand, why
> the use of the Escape function is misguided
Did you know the script56.chm, the "VBScript Docs" document at M$ is
corrupted?

Hi, gimme

What exactly do you mean about the script56.chm's being corrupted?
Maybe it is just a security problem.

Here is an example:
You go to msdn.microsoft.com and do a search that results in a URL like the
following:
http://www.microsoft.com/downloads/e...&stype=s_basic
This gives you a list of about 80 .CHM-related links.
You might click on a link like:
Windows PowerShell Graphical Help File (Version 2.0)
which in this case links you to a page with a download button.
The file downloaded is PowerShell2Help.exe, which turns out
to be a self-extracting ZIP file. The extracted file is named
PowerShell.chm.
When you double click PowerShell.chm, you get a security warning that
mentions
that the publisher is unknown, and you have the choices of 'Open' or
'Cancel'.
Open attempts to open the help file, and the left pane looks like a normal
contents list, but the right pane says Action canceled and has a useless
'Please try the following:" suggestion.

Here is the secret.
Right click PowerShell.chm, and choose 'Properties'.
Near the bottom of the properties window, you will probably see a Security
entry
that says this file came from another computer and might be blocked to help
protect this computer, followed by an "Unblock" button. After you click
the Unblock button and choose 'apply', this security info area is grayed out
or is removed. The help file should then open and display properly with no
questions asked.

-Paul Randall






My System SpecsSystem Spec
Old 04-09-2009   #10 (permalink)
ekkehard.horner


 
 

Re: Create a path string

gimme_this_gimme_that@xxxxxx schrieb:

For reference:

gimme_this_gimme_that@xxxxxx schrieb:
Quote:

> Const Mystring = "c:\Program Files\Some Folder\program.exe"
> Const Constring = "Local Area Connection "
> Set WSH = CreateObject("WScript.Shell")
> WSH.Run(escape(Mystring) & " " & Chr(34) & Constring & Chr(34))
Quote:
Quote:

>> (1) Richard Mueller's solution to understand, why double quotes
>> are needed for the file specification of the executable
>
> Isn't char(34) and a double quote the same thing?
My fault; I should have written: ... double quotes are needed for
the file specification of the executable *as well*.
Quote:
Quote:

>> (2) the VBScript Docs, Topic "Escape Function" to understand, why
>> the use of the Escape function is misguided
>
> Did you know the script56.chm, the "VBScript Docs" document at M$ is
> corrupted?
I couldn't, because it isn't. More to the point: Escape "Encodes a
string so it contains only ASCII characters". If you apply this function
to a path

WScript.Echo Escape("c:\Program Files\Some Folder\program.exe")
==>
c%3A%5CProgram%20Files%5CSome%20Folder%5Cprogram.exe

the result is not suitable for .Run or .Exec.
Quote:
Quote:

>> (3) the VBScript Docs, Topic "VBScript Procedures" to understand,
>> why the () in the .Run statement are wrong/misleading
>
> What I posted works. I thought the OP wanted a solution. Not you.
"It works" does not necessarily mean "correct code". Using () when
calling Sub is wrong. The code I cited above is no solution. Quality
of code does not depend on the person you give it to.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Extracting drive, path, filebasename WITH string functions and NOT system function ??? VB Script
Create Directory on a UNC Path PowerShell
Extract folder from dir path (String) PowerShell
How do I escape the wildcard character in a path string? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46