Solved

Run cmd line from vbs

Posted on 2008-06-18
6
3,150 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Attention Please 10 47
VB Script: create txt file with DateStamp and IP Adress 6 27
Error with a code discussed on this page 5 29
checkbox to hide entire section 10 40
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

809 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