Question: I have written a tool that is run on the command line.  

I can test it on the command line on my machine, and it works fine.  

I then remote into the target server machine and run it on the command line there, and it still works.  

**However**...this tool needs to remain running (*its a monitoring tool*).  

I can't leave my remote session to that machine open for too long, as other people need to use it, and when I close my remote session, that command line tool ends.  

I don't know how to, and would like to avoid needing to, write a windows service, but essentially I need that capability. I need to almost wrap my command line tool with a windows service that can remain running on the target machine while I disconnect.

Can anyone provide any insight/strategy on how to do this?

**Edit:**  

Both of the below posts are helpful.

Answer: 
If it's Windows Server 2003 or earlier you can use Srvany.exe to run any application as a service. See [here](http://support.microsoft.com/kb/137890) for details.

If it's Windows Server 2008, SrvAny isn't supported officially, but you might be able to hack it to work by copying it from Win2003 Resource Kit or earlier and then combining it with the instructions in Thomas answer in some way.

However, writing a proper Windows Service is really quite simple and it's the best way to make sure that it'll coexist happily with everything else.

Just create a Windows Service project in Visual Studio. In the OnStart you create a thread that runs your code. In the OnStop you use a flag to stop the service. Then you can make it better later.
An alternate solution is to use the [PsExec](http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) to launch your monitoring tool on the remote machine in detached mode, i.e.:

```
PsExec.exe \\remote_machine -d C:\...\monitoring_tool.exe

```

PsExec.exe launches monitoring\_tool.exe on the remote machine and then terminates itself. It does not wait for monitoring\_tool.exe to terminate.