Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to start a command from the cmd command line in Windows 7 and have it run completely in the background.

Basically I'm looking for the functionality that the *nix & provides.

So far I've found start which starts the command in a new cmd window, and I've found start /B which doesn't open a new window, drops back to the command line, but keeps the process attached to the cmd.exe process from which it was started (so if you close cmd.exe it kills the process).

Is this possible? It's so simple in *nix I'm having trouble believing it can't be done, but who knows.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

The only easy way I know from cmd is using psexec from Sysinternals process tools.

psexec -d your_command

could do the trick. (That tool has a bunch of useful options, and it can start processes on remote machines too. Quite useful.)

I remember having had to resort to at and/or schtasks in a tight spot, but... don't do that ;)

If you don't want a new window at all, but can stand one that disappears immediately (you'll see it pop up then leave), you can use a VBScript wrapper. (There are a few variations on this all over the tubes.)

launcher.vbs

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run "your_cmd_file_with_full_path.cmd", 0
Set WshShell = Nothing

Then:

psexec -d cscript launcher.vbs
share|improve this answer
    
D'oh, still opens a window. To be fair this may be the fault of vboxheadless and not your methodology. –  Josh May 22 '12 at 19:15
    
Well, don't know how to do it with absolutely no disturbance. Added another layer in there that hides itself pretty fast. That's about all I know, hopefully someone who actually knows Windows will come up with a real solution :) –  Mat May 22 '12 at 19:42
    
Interesting, I'll try it in a minute. It seems rdp to my headless vm from the host (which itself was over rdp) has borked something along along the way. –  Josh May 22 '12 at 19:50
    
It seems the executing this script directly with cscript had the desired effect. I find it hard to believe there's not a simpler way considering it's a single character in *nix –  Josh May 22 '12 at 19:56
add comment

open a powershell window (just type in powershell in command area in windows start menu), start-job -command "whatever your command is"

share|improve this answer
    
Cannot bind paramter 'ScriptBlock'. Cannot convert value... etc. –  Josh May 22 '12 at 19:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.