C # run command as administrator

I am trying to run csript as an administrator (the account has administrator rights). installing startinfo.verb on runas does not work.

ProcessStartInfo p1 = new ProcessStartInfo();
p1.UseShellExecute = true;
p1.Verb = "runas";
p1.FileName = "cscript";
p1.Arguments = "I:\\WPKG\\wpkg.js /synchronize /quiet /nonotify";
Process p = new Process();
p.StartInfo = p1;
p.Start();

The only way to get him to start with privileges is to manually set the username and password. However, I cannot hard-code this information or put it in a configuration. Is there any way to add cmd without login information?

I also tried adding using (System.Security.Principal.WindowsIdentity.GetCurrent (). Impersonate ()) around the above code and no luck.

Note. If I run the bat file directly, it works, if I run with a hard password code, it works. It not only cannot start a launch from C # without logging in.

+5
2

:

0

All Articles