tags:

views:

133

answers:

3

I have a windows server 2003 up in the internet. But sometime I need to restart it. After restart, I want one of the applications to run.

I want to do this all programatically. I can now remotely restart the server.

But the question is how can I ask that piece of software to be executed (more precisely, I want to execute a .BAT file to ask a tomcat to run)? Because I don't want to manually log in to the machine and start that application. That is time consuming. Is there any possible way, once the machine is started, my application will be run as well?

A: 

You can install Cygwin and then do it the same way we'd do it on a Linux box: via ssh, using keys.

OpenSSH is not part of the default Cygwin install, so be sure to select it. It's in the Net category.

Then, after you've installed Cygwin and sshd, read /usr/share/doc/Cygwin/openssh.README to learn how to set up sshd as a service, so it will answer requests automatically, without you having to start the ssh daemon manually.

Finally, set up keys, as described in the link above.

Part of the ssh protocol is a way to ask a remote machine to launch a program. Setting it up with keys lets you do it without needing a password.

Warren Young
hmm..sounds good.....but one thing...i want to execute a bat file, which is to launch a tomcat. in cygwin, i don`t think it can lanuch a bat file....
shrimpy
Of course you can: "cmd /c myscript.bat"
Warren Young
+1  A: 

If you're developing an application that should always be running on the server, you probably need to implement it as a Windows service. For C#, see the classes in the System.ServiceProcess namespace -- you will need to inherit from ServiceBase.

Alternatively, you can set the program to be run as a scheduled task on boot. See the Task Scheduler API to do this.

Jeffrey Hantin
the task scheduler is perfect..it can allow application to be execute a the start up..
shrimpy
A: 

You could try xCmd, which is a freeware app to run a command on a remote machine.

Greg