Solved

Run cmd line from vbs

Posted on 2008-06-18
6
3,119 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
Comment Utility
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
Comment Utility
WshShell.Run "cmd.exe /c" & chr(34) & strCmdLine & strUserID & chr(34),1,TRUE
0
 
LVL 3

Author Comment

by:james_tubberville
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:ysfx
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now