Solved

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

Posted on 2004-09-14
7
14,463 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

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…
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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

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