• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

wshshell.run a program from Program Files

G

Gavaskar

#1
Ok

I'm having troubles trying to run a program with wshShell.run

The program takes two arguments ..... \myprogram.exe setconfig c:\filename

Here is what I'm doing, I have the user run a script from the folder that
myprogram is in.

C:\Program Files\My Company Name\Driver\version001\SetConfigpath.vbs

ScriptName = wscript.Scriptfullname 'gets me C:\Program Files\My Company
Name\Driver\version001\SetConfigpath.vbs

scriptpath = replace(ScriptName,"SetConfigpath.vbs","") ' removes
SetConfipath.vbs

Now I need to run C:\Program Files\My Company
Name\Driver\version001\myprogram.exe setconfig C:\filename

I think I need to do this, but the whitespaces and number of """ are giving
me grief.

wshShell.Run scriptpath & " setconfig " & "C:\filename", 3,true

I have to use the variable scriptpath, I can't hard code it, because it may
change.

Any Ideas????

Thanks
G
 

My Computer

B

Bukkake Face

#2
On Jul 8, 9:54 am, "Gavaskar" <[email protected]> wrote:

> Ok
>
> I'm having troubles trying to run a program with wshShell.run
>
> The program takes two arguments ..... \myprogram.exe setconfig c:\filename
>
> Here is what I'm doing, I have the user run a script from the folder that
> myprogram is in.
>
> C:\Program Files\My Company Name\Driver\version001\SetConfigpath.vbs
>
> ScriptName = wscript.Scriptfullname 'gets me C:\Program Files\My Company
> Name\Driver\version001\SetConfigpath.vbs
>
> scriptpath = replace(ScriptName,"SetConfigpath.vbs","") ' removes
> SetConfipath.vbs
>
> Now I need to run C:\Program Files\My Company
> Name\Driver\version001\myprogram.exe  setconfig  C:\filename
>
> I think I need to do this, but the whitespaces and number of """ are giving
> me grief.
>
> wshShell.Run scriptpath & " setconfig " & "C:\filename", 3,true
>
> I have to use the variable scriptpath, I can't hard code it, because it may
> change.
>
> Any Ideas????
>
> Thanks
> G
Use :

wshShell.Run chr(34) & scriptpath & chr(34) & " setconfig " & "C:
\filename", 3,true

chr(34) is the character code for " which will encapsulate your
scriptpath with " and enable you to use white spaces.
 

My Computer

R

Richard Mueller [MVP]

#3
"Bukkake Face" <[email protected]> wrote in message
news:[email protected]
On Jul 8, 9:54 am, "Gavaskar" <[email protected]> wrote:

> Ok
>
> I'm having troubles trying to run a program with wshShell.run
>
> The program takes two arguments ..... \myprogram.exe setconfig c:\filename
>
> Here is what I'm doing, I have the user run a script from the folder that
> myprogram is in.
>
> C:\Program Files\My Company Name\Driver\version001\SetConfigpath.vbs
>
> ScriptName = wscript.Scriptfullname 'gets me C:\Program Files\My Company
> Name\Driver\version001\SetConfigpath.vbs
>
> scriptpath = replace(ScriptName,"SetConfigpath.vbs","") ' removes
> SetConfipath.vbs
>
> Now I need to run C:\Program Files\My Company
> Name\Driver\version001\myprogram.exe setconfig C:\filename
>
> I think I need to do this, but the whitespaces and number of """ are
> giving
> me grief.
>
> wshShell.Run scriptpath & " setconfig " & "C:\filename", 3,true
>
> I have to use the variable scriptpath, I can't hard code it, because it
> may
> change.
>
> Any Ideas????
>
> Thanks
> G
Use :

wshShell.Run chr(34) & scriptpath & chr(34) & " setconfig " & "C:
\filename", 3,true

chr(34) is the character code for " which will encapsulate your
scriptpath with " and enable you to use white spaces.

---------
Alternatively, replace any quotes embedded in your string with two quotes.
For example:

strCmd = """" & scriptpath & """ setconfig " & """C:\filename"""
Wscript.Echo strCmd
wshShell.Run strCmd, 3, True

I added the Wscript.Echo command for troubleshooting only. If it displays
the correct command, with spaces and quotes in the correct places, you are
good to go. Not I also placed the last parameter in quotes in case it has
any spaces.

Actually, the usual practice is to use %comspec% to invoke the proper
command processor for your OS. For example:

strCmd = "%comspec% /c """ & scriptpath & """ setconfig " &
"""C:\filename"""

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

My Computer