Solved

Run cmd line from vbs

Posted on 2008-06-18
6
3,131 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

25 Experts available now in Live!

Get 1:1 Help Now