Solved

Run cmd line from vbs

Posted on 2008-06-18
6
3,157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
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…

707 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