Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a .vbs file from SYSTEM account 1

Status
Not open for further replies.

serializer

Programmer
May 15, 2006
143
SE
I have a problem running a .vbs file from a Windows service. I can succesfully run it if I specify the full path to cscript.exe as command and the vbs path as argument. The problem with that is that the exit code is not captured (it captures the exit code from cscript.exe).

The main reason why I have to run cscript.exe as command is because (I believe) the enviroment variables for the extensions are not set correctly.

How can I fix this?
 
why not convert the vbs code to .net and use a fully managed library to complete the task?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
That is not an option as the end users have no programming skills in .NET.
 
this might work
Code:
Process.Start("file name").WaitForExit();

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
The problem is not starting the process. The problem is that probably that, in the context, the engine for .vbs is not known.
 
have you tried it? this is how i launch bat files.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
It's because the recognition of .vbs files as script files is done by the Windows Shell (explorer.exe), which is your desktop environment.

When running as a service, there is no desktop, and thus no recognition of .vbs files. So you'll have to provide the full path to cscript.exe.

Not sure about being able to capture the exit code. Perhaps there's a property on the Process class for this?

Chip H.


____________________________________________________________________
www.chipholland.com
 
There is, but I just wondered if there is a way to map it (to cscript) like in the desktop.
 
You might check this registry key:

HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command


____________________________________________________________________
www.chipholland.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top