-4

I have a windows application hosted on web server and a exe placed in D drive in another server. Now i want to run that exe from my web server on button click using WMI DLL. Also, I need to pass some arguments.???

I am able to open the notepad in remote computer but not able to run the exe.

string processPath = "path of exe"; 
var processToRun = new[] { processPath }; 
var connection = new ConnectionOptions(); 
connection.Username = 
connection.Password = 
var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", "Server Name"), connection); 
var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()); 
var result = wmiProcess.InvokeMethod("Create", processToRun);
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Sahil Gupta
  • 13
  • 1
  • 8
  • If any body knows please help me – Sahil Gupta Mar 20 '15 at 10:14
  • Do you get an error message? Are you sure your application isn't launching and crashing immediately? Are you only having problems with the arguments? There aren't enough details on this question for people to reliably help you to answer it - try adding some more. – Dan Puzey Mar 20 '15 at 11:31
  • I didnot how to provide the path to exe as the current code will take me to c://windows/system32 – Sahil Gupta Mar 21 '15 at 14:52

1 Answers1

-1

string exec = "your exe name with argument if needed";

        System.Diagnostics.ProcessStartInfo psi =
                new System.Diagnostics.ProcessStartInfo("cmd.exe");
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardError = true;
        psi.CreateNoWindow = true;

        System.Diagnostics.Process proc =
                   System.Diagnostics.Process.Start(psi);

        System.IO.StreamReader strm = proc.StandardError;

        System.IO.StreamReader sOut = proc.StandardOutput;

        System.IO.StreamWriter sIn = proc.StandardInput;
                    sIn.WriteLine("d:");//this line moves you to the d drive  
        sIn.WriteLine("cd "+Server.MapPath("Screenshot").ToString());//here screenshot is a my directory which containing the my .exe you can chamge it with yours 
        sIn.WriteLine(exec);//here your exe runs
        strm.Close();

       sIn.WriteLine("EXIT");

       proc.Close();

       string results = sOut.ReadToEnd().Trim();

        sIn.Close();
        sOut.Close();
Jigs Patel
  • 16
  • 1