Solved

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

Posted on 2004-09-14
7
14,453 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

13 Experts available now in Live!

Get 1:1 Help Now