2

I've a batch file which is located on a server A on our company's network. I've a .Net/C# application running on user's machine on the network, through which I need to execute this batch file programmatically(using C#) on server A.Is this possible? If yes, any pointers please?

Thanks for your help.

user74042
  • 729
  • 5
  • 14
  • 28

5 Answers5

2

Look into WCF and Systen.Diagnostics.Process.

Community
  • 1
  • 1
LueTm
  • 2,366
  • 21
  • 31
  • Nope, like V-X points out, he'll ned authentication and authorization. Executing batch files shouln't be possible otherwise. – LueTm Jan 05 '14 at 08:04
  • C# is full of such overkills. With enough security, WCF is an acceptable overkill... (Let's try to find and adapt some simple example) – V-X Jan 05 '14 at 08:09
  • I don't see the problem though. WCF is a useful enough skill to have. Also, if you already know about it, WCF is set up quite quickly and the hard (security) work is already done. What's not to like? Nowadays it's even quite portable with Mono. I don't see the huge problem. – LueTm Jan 05 '14 at 08:12
  • because its overkill! – Mitch Wheat Jan 05 '14 at 08:25
2

Have a look at PsExec v2.0:

Utilities like Telnet and remote control programs like Symantec's PC Anywhere let you execute programs on remote systems, but they can be a pain to set up and require that you install client software on the remote systems that you wish to access. PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software. PsExec's most powerful uses include launching interactive command-prompts on remote systems and remote-enabling tools like IpConfig that otherwise do not have the ability to show information about remote systems.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
0

Having the possibility to execute batch files on the server is a security hole!

I'd advise to create a server application on the server machine.

V-X
  • 2,979
  • 18
  • 28
0

If you need a .NET solution you are best to implement a PowerShell integrated one. Specifically look at the PowerShell Running Remote Commands documentation. Specifically look at the Invoke-Command cmdlet running a script on remotes.

Windows PowerShell Remoting

Windows PowerShell remoting, which uses the WS-Management protocol, lets you run any Windows PowerShell command on one or many remote computers. It lets you establish persistent connections, start 1:1 interactive sessions, and run scripts on multiple computers.

mockinterface
  • 14,452
  • 5
  • 28
  • 49
0

with "pure" batch commands and without external tools:

wmic  /NODE:Server /USER:user /PASSWORD:pass process call create "command parameters","c:\workdir"

Although WMIC is not available for Windows XP home editions (but WMI classes are available so you can use C# queries).

It uses WIN32_PROCESS class .Here how it can be used with C# . More C#\WMI examples

From vista and above you have also WINRS command (may is possible to used with XP also with some resource kits):

winrs -r:myserver command /domain:testdomain /userd:user /password:pass

You can also check XCMD which in some cases works better than the PsExec.

npocmaka
  • 55,367
  • 18
  • 148
  • 187