Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know this question has been asked several times before. I’m working on a web application, and I need to execute a batch file on a remote machine.
I`v tried two approaches: psexec and WMI, and they worked, but both of them take a long time to acquire a connection to the remote machine (5-10 seconds) … !!! I wonder if there’s something I can do to enhance performance (in case of WMI), or maybe a third approach that i`m not aware of, yet…
thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 17-Oct-11 16:27pm    
Batch file is of course not good. Alternatives? It depends on what you want to do in this batch file, what's the purpose.
--SA
Chris Maunder 17-Oct-11 16:57pm    
What have you tried and what, through debugging, is being shown as the bottleneck? Help us to help you.

1 solution

my batch file (on the remote server) calls an application that extracts users information from AD and writes it to a .txt file...

In my web application i used to following code to execute that batch file.


<pre lang="c#">ConnectionOptions options = new ConnectionOptions();
options.Username = username;
options.Password = password;
options.Authority = authority;
ManagementScope scope = new ManagementScope("\\\\remoteServerIP\\root\\cimv2", options);
scope.Connect();

ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(scope, managementPath, objectGetOptions);
string sBatFile = "\\\\remoteServerIP\\c$\\nini.bat";
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = sBatFile;

ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);</pre>


i commented out the last line of code (InvokeMethod) to check the time required for acquiring a connection , without executing the batch file. When tested, it took 10 seconds to connect to the remote server !

i also tried to execute my remote batch using psexec on cmd, and it also took more than 5 minutes to connect and finish execution...

The link to that remote server is really bad (64 Kbit/sec) , so is there another way to execute that batch on the remote server?

thanks again :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900