Smaug
Smaug

Reputation: 2673

Pop up window triggers if i run process with administrative privillage c#

As I want to run the cmd with administrative privilege in the process, but the pop up open up even set the WindowStyle to hidden.

 ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + @"cscript.exe DTCSECURITY.vbs");
 ProcessInfo.CreateNoWindow = true;.
 ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;

 // Here with i pass the privillage
 ProcessInfo.UserName = @"administrator";
 ProcessInfo.Password = StringToSecureString("password12$");    

 process = Process.Start(ProcessInfo);
 process.WaitForExit();

But if I comment the privillage code no pop up blinks.

Upvotes: 2

Views: 583

Answers (2)

Bojan Komazec
Bojan Komazec

Reputation: 9526

Try to set ProcessStartInfo.UseShellExecute to false (it is true by default).

ProcessStartInfo.CreateNoWindow Property says:

If the UseShellExecute property is true or the UserName and Password properties are not null, the CreateNoWindow property value is ignored and a new window is created.

Upvotes: 1

Soner Gönül
Soner Gönül

Reputation: 98750

I think you should set WorkingDirectory property. From MSDN;

The WorkingDirectory property must be set if UserName and Password are provided. If the property is not set, the default working directory is %SYSTEMROOT%\system32.


If the UserName property is not null or an empty string, the UseShellExecute property must be false, or an InvalidOperationException will be thrown when the Process.Start(ProcessStartInfo) method is called.

Upvotes: 1

Related Questions