Hi, Hope that somebody can enlighten me... What's the difference between System.Diagnostics.Process and System.Diagnostics.ProcessStartInfo ? I've been browsing the www the last couple of day, trying to understand how C# works, but can't see the trees through the forest Noticed though that .Process is mainly used to call .vbs, and .ProcessStartInfo for CMD. Regards.
Two different classes for working with processes. In a first moment, ProcessStartInfo is enrolled with the Process class.
So which is the correct one to use for calling cmd.exe or slmgr.vbs? Also noticed differences in the line when it's used. example: 1) System.Diagnostics.Process Port = new System.Diagnostics.Process(); Port.StartInfo.FileName = @"C:\Windows\System32\cmd.exe"; Port.StartInfo.Arguments = "/c netstat -a"; Port.Start(); 2) System.Diagnostics.ProcessStartInfo Port = new System.Diagnostics.ProcessStartInfo("cmd", "/c netstat -a"); Both doing the same thing.
ok you know that Port.Startinfo is just the ProcessStartInfo class \ struct you can create a process with it like this Port.Start(ProcStartInfo); or do it the way you did.. in the post above
ProcessStartInfo is one enrolled class. It only will work as dependant for the Process class, such as: Code: ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); //Initializing the startInfo object. startInfo.WindowStyle = ProcessWindowStyle.Minimized; //Adding the WindowStyle property. startInfo.Arguments = "http://forums.mydigitallife.net"; //Adding the Arguments property. Process.Start(startInfo); //Starting a new process using the startInfo properties...
VS doesnt let me take those shortcuts (eg ProcessStartInfo startInfo = new ProcessStartInfo) in WFA, it wants me to always append System.Diagnostics. But i guess that i'm on the right track, just need to do some more digging... By the way, how can i run a elevated command, "runas" doesnt work, trows me a "OneClick app can not run as administrator" error, and from what i find on the www is that MS implemeted that restriction.
You need of run your main executable as administrator to automatically invoke other processes with administrator level. Here's the way to elevate it programatically: Code: ProcessStartInfo proc = new ProcessStartInfo(); proc.UseShellExecute = true; proc.WorkingDirectory = Environment.CurrentDirectory; proc.FileName = Application.ExecutablePath; proc.Verb = "runas"; try { Process.Start(proc); } catch { // The user refused the elevation. // Do nothing and return directly ... return; } Application.Exit(); // Quit itself Ah, if you're trying to execute shortcuts, you need of set this property: Code: proc.UseShellExecute = true;
remove the publishing bindings from your program or uncheck the sign the click once manifests. sounds like you are using visual studio 2008
Code: Process.Start("Runas"," /user:" + Environment.UserName + " whatever.exe"); This will prompt for the admin password before executing the application as administrator Just another way to do it i suppose.