?
Solved

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

Posted on 2004-09-14
7
Medium Priority
?
14,491 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
[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
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 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