Solved

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

Posted on 2004-09-14
7
14,479 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
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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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