Solved

Run cmd line from vbs

Posted on 2008-06-18
6
3,139 Views
Last Modified: 2013-11-25
I'm trying to run a command line program with a user provided switch using vbs (command with userid as switch. I have copied the problem portion of the script and several variations below.

strUserID = Inputbox("Enter USER ID","USERID","EX: LastFM")
                        If strUser = "" Then
                        WScript.Quit
                        End If

strCmdLine = "C:\Progra~1\ARPR\arw00\arw00 " & strUserID
set WshShell = CreateObject("WScript.Shell")
WshShell.Run"cmd.exe /c" & strCmdLine,1,TRUE

also tried

strCmdLine = "C:\Progra~1\ARPR\arw00\arw00 "
set WshShell = CreateObject("WScript.Shell")
WshShell.Run"cmd.exe /c" & strCmdLine & strUserID,1,TRUE

and also

set objShell = wscript.createObject("wscript.shell")
objShell.Run("cmd.exe /c" & "C:\Progra~1\ARPR\arw00\arw00 " & strUserID, 1, TRUE)

I been working on several long scripts for the past two weeks and this simple task (one of those 30 second scirpts) is driving me crazy...I believe my brian is done for the month!
What am I overlooking? Assigning 500 due to need not difficulty!!!
0
Comment
Question by:james_tubberville
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:ysfx
ID: 21814968
You need to include chr(34) in your /c parameter:
cmd.exe /c"c:\...\program parameter"

It's probably not working correctly because it sees it as cmd.exe /cc:\...\program parameter
which then parameter is passed to cmd.exe not c:\...\program.
0
 
LVL 6

Expert Comment

by:ysfx
ID: 21814978
WshShell.Run "cmd.exe /c" & chr(34) & strCmdLine & strUserID & chr(34),1,TRUE
0
 
LVL 3

Author Comment

by:james_tubberville
ID: 21815219
Clarification:
Program opens as follows
arw00 userid
running batch containing arw00 %username% works for a local user
The program is designed not to open in windows (database error occurs)
Using an inputbox in vbs to provide userid i need the vbs script to run as if running a command line

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 6

Expert Comment

by:ysfx
ID: 21816224
WshShell.Run will execute the program as if executed from a command line, so I don't understand your last post.
0
 
LVL 15

Accepted Solution

by:
sr75 earned 500 total points
ID: 21816373
I have always been partial to the WShell.Exec() method for such things.  Why not give that a try if WshShell.Run doesn't work for you?
strServer = inputbox("Please provide the Server Name or IP Address")
 
set WShell = CreateObject("WScript.Shell")
set objExec = WShell.Exec("ping -n 2 -w 1000 " & strServer)
strPingResults = LCase(objExec.StdOut.ReadAll)
 
wscript.echo strPingResults

Open in new window

0
 
LVL 3

Author Comment

by:james_tubberville
ID: 21816545
I've never had the problem with WshShell.Run not executing as it should. WShell.Exec executed the program including the switch as the database delimiter.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question