• Advertisement
Sign in to follow this  

how to run a cmd command on a remote machine(server) with code

This topic is 994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi.

 

i have  game server that i need to run a exe file and send some parameteres to it and after some calculations it should be closed. i think something like a batch file should be happened. i dont know what is best way to do that. maybe its better to make a socket program on server and send data to that server socket and that socket do things on server machine but some one said there are some telnet services and a program named PSexec and...

 

can you tell me what is the best to run a cmd code for running a exe file on a server and send a some parameters to it with c# code and how to read those parameteres in exe program?

 

 

thank you for helping

Share this post


Link to post
Share on other sites
Advertisement
You can use something simple like HTTP to send requests to the server and have it respond to them. Depending on what your program needs to do, writing it as a web service might make sense, or might not. It's hard to say without knowing more details about the software in question.

Using stuff like PSExec should be treated with extreme caution. If an attacker can run arbitrary programs, or send arbitrary input to a known target program, he can probably take over your machine easily.

Share this post


Link to post
Share on other sites

Another option for allowing well-authenticated users to run commands on a remote server is to use PowerShell over SSH: http://www.extremetech.com/computing/207364-windows-powershell-and-openssh-together-at-last-after-nearly-a-decade

 

 

can you give me more explanations? the link you gave it just says you can use powershell with ssh but i dont know how you can set powershell and ssh. some link says you have to start a ssh session and after that run powershell commands but i cant find anything usefull. thanks for your help

Edited by moeen k

Share this post


Link to post
Share on other sites
TO start an SSH session from one machine to another, use an SSH client on the first machine (making sure a SSH server is running on the other.)
A commonly used SSH client for Windows is Putty. You can download this from the internet.
You need to generate a private/public key pair for the users allowed to connect to the server. The user loads the private key into the Putty session (or more commonly, using Pageant that comes with Putty,) and the public key is manually installed on the server; this lets the server know which clients are allowed to connect.
Once connected, you type shell commands in the Putty window, and see the responses.

If you need to automate this, you can use the "plink.exe" command that also comes with Putty; it allows you to use file redirect to send/receive commands.
Another option is to use the command-line OpenSSH implementation; for Windows, the easiest way to get this is Cygwin.

If you go with Cygwin, you can also use the Cygwin sshd to be the SSH server. You would then issue BASH commands over the SSH connection (because Cygwin uses the BASH shell.)
http://www.noah.org/ssh/cygwin-sshd.html

Note that this requires some trust in the users you allow to connect to the server, as they will have shell access.
If you want to expose certain functions to the greater internet, you're better off using a web server with some support for scripting -- ASP, CGI-BIN, WSGI, or somesuch, where the specific commands that can be run by the server is controlled by your server-side code.
The easiest way to get started with this is likely to use the built-in Internet Information Server / ASP.NET that comes with Windows and Visual Studio, although to scale that up to lots of users you're going to have to pay a lot in license fees to Microsoft.

Okay, I think I've done enough guessing about what it is you really want -- if you have a more specific request, I'm sure me and others on the forum would be happy to give more specific answers. Edited by hplus0603

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement