Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run command line (cmd) that require "Security Message"

I want to run the command line pnputil in c# program. The program needs to install USB driver. I know how to run cmd in c# program, but I have a different problem:

The driver that I want to install does't have permission of windows.

If I Install the driver via the "device manager->update driver" and choose the path of the driver, I get "Security Message" from windows that "windows can't verify the publisher of this drive software" and let me choose if install the driver or not (of course, if I choose to install - the installing succeeds).

If I run the command from the cmd pnputil -a <path_name_inf> I get this message too and I can install the driver.

But when I try to run the command via c# program - the program runs but the driver is not installed (I also don't get this message).

my code in c#:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = @"/C Pnputil -a <path_name_inf>";
process.StartInfo = startInfo;
process.Start();

How can I do that?

like image 765
user1994587 Avatar asked Jun 30 '26 02:06

user1994587


1 Answers

You could try to run the cmd using the runas verb:

startInfo.Verb = "runas";
startInfo.UseShellExecute = true;

This parameter causes a privileges elevation. The same thing could be reached when you use "Run as administrator" in explorer.

like image 179
Dmitry Avatar answered Jul 02 '26 15:07

Dmitry