Solved

Executing batch file using Wscript.Shell.Run on Windows NT

Posted on 2004-09-14
7
14,442 Views
Last Modified: 2011-08-18
Hi,
  I am using a vbscript to execute a batch file on Windows NT. I create an object of type WScript.Shell and then use the Run method. However, the script does not seem to get executed in Windows NT, though the same works on Windows 2000 and Windows XP. Any pointers on what can be the problem and how to solve it.

Thanks
0
Comment
Question by:nana79
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 12054596
Try passing it through the command interpreter:

"cmd /c e:\mybatchfile.bat"
0
 

Author Comment

by:nana79
ID: 12062879
That didn't help either.
0
 
LVL 8

Expert Comment

by:K_2K
ID: 12090530
What exactly is the error?
If you're not getting a runtime or compile error then it's not a vbscript problem, unless you forgot to comment out the "on error continue" line.

There's a lot more difference between NT and 2000 than meets the eye.  
I would start with setting several points in the batch file to echo status to a log file to see if it starts but is failing somewhere.

Then use something like this to get status of the batch:
strErrorReturned = objWShell.Run ("C:\WINNT\system32\cmd.exe /K file.bat", 1,True)
wscript.echo "Program file.bat returned code: " & strErrorReturned

Notice that to get the code you must add the () to run it as a function AND add the "True" to wait for the window to close.  The 1 is optional and only makes the window show up.


Best for last: Windows NT was delivered with runtimes to support vbscript version 1 and all the info on scripts is based on having runtimes 5.6.  While the shell object and the .run method were in version 1, there's no reason not to download the small executable and upgrade to 5.6 in case you want some of the other very commonly used version 3 and 5 features:
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp
0
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!

 
LVL 8

Expert Comment

by:K_2K
ID: 12090537
ps: the cmd /K is the same as cmd /C except the window is "K"ept open after the run so you can see what's there.  Of course you would probably want to use /C when done debugging.
0
 

Author Comment

by:nana79
ID: 12099489
I found out what really was the problem at last. Basically I was trying to execute something like this. String = ["C:\Program Files\my directory\script.bat" add "c:\program files\my directory\sybdir\paramfile.xml"] (basically the whole stuff in a single string). Then this string was used in Run in which case it was failing. I had to use the "" because of the space in the directory names. So in order to avoid this, I included a step where I converted the names to 8.3 format and then executed them within the Run function and they suceeded. Thanks for your suggetions anyway
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12327415
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

18 Experts available now in Live!

Get 1:1 Help Now