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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WSH Question > Call cmd.exe in background -possible?

Status
Not open for further replies.

RhythmAddict112

Programmer
Joined
Jun 17, 2004
Messages
625
Location
US
Hi all. Pretty simple question..I have a WSH script that needs to call another prog from the command line if certain conditions are met. Is there a way I can call the command line in the background, ie without having the cmd box pop up? My code for this is very simple. Id just liek to avoid the shell popping up and then going away if possible......Also, on an unrelated note...Let's say I have my script on a server with a shared drive..Let's say this drive is mapped as q:. If I start my script via my explorer window on the q: drive, why does wscript.exe remain in my tasks on my PC? IE, if i shut down my pc, the process will teriminate. Is there a way to avoid this assuming I do not have physical access to the box? Thank you, as always for your help.
 
OK,

You have 2 questions.

Firstly, the code below will run a batch file and not show the window

Code:
Dim oShell
Dim strCmd
Set oShell = CreateObject("WScript.Shell")
strCmd = "CMD /C COPY C:\A.TXT C:\TEMP\B.TXT"
oShell.Run strCmd,0

The 0 at the end of the last line will hide the cmd from view.

Your second problem looks to be a problem in the script meaning it wil not shut. If you have any On Error Resume Next commands, remove them and see if you get any failures.

Hope this helps

Spong
 
thanks for the tek tips. I appreciate it...The 2nd problem, concerning my script...The script is supposed to continually run using wscript.sleep.....I just want the script to run (on the remote comp) even if I shut down...
 
If you are looking for a script to keep on running actually on the server but started from a remote machine, you may want to try remote scripting. You need to have a registry key set on the server to enable this though.
 
Interesting. I've already got the script(s) created, would I just need to add something like this??

From what I understand, I need to get a key/digi cert from the Administrator of the server so the server will permit me to run this script. I guess assuming that isn't a problem, my next concern is modification to my current code...

If you can give me any more info, or links on this it'd be great. Thank you for your help!
 
It is likely that if you are not an admin on the machine that you will need to get the registry keys added as detailed in the web page that you listed. If the IT chaps are concerned about security, they can give access rights on the registry key directly to stop malicious usage.

I would then suggest that you modify the script as though it were to run on the remote machine and then use the example of code in the link to run it.

One small note which the page failed to mention that I saw. You cannot do any GUI interaction with remote scripts, i.e. echo statements or running programs. All other admin (copying files, registry access, emailling), can still be done. If this is a problem, then remote scripting would likely be ruled out :(

Spong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top