Run command prompt (cmd) which requires "Security message"

I want to run a command line pnputil

in a C # program. The program needs to install the USB driver. I know how to run cmd in a C # program, but I have a different problem:

The driver I want to install does not have windows permission.

If I install the driver using "device driver -> update driver" and select the driver path, I get a "Security Message" from windows that "Windows cannot verify the publisher of this software" and let me choose if to install the driver or no (of course, if I want to install, the installation will be successful).

If I run the command from cmd pnputil -a <path_name_inf>

I also get this message and I can install the driver.

But when I try to run a command using a C # program - the program starts 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 this?

+3


source to share


3 answers


You can try running cmd with runas

verb:

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

      



This parameter causes privilege escalation. The same can be done when you use "Run as administrator" in File Explorer.

+1


source


Your questions are about installing unsigned drivers.

You can try the following steps: Open a command prompt as administrator and type:



bcdedit -set TESTSIGNING ON

      

See the MSDN link for more information on test signature. Test signing can place watermark as TEST in desktop newspaper

0


source


I know this is old, but I wanted to share my solution in case it can help someone else.

My specific scenario is that I wanted to add an unsigned driver package to the driver store in Windows 7 Home Premium 64-bit.

As of the OP, this worked as expected (meaning I received a security warning and the driver package was added to the driver store) if I executed pnputil -a <path_to_inf>

from the command line using the Run as Administrator command.

Windows cannot verify the publisher of this driver

However, if I tried to call pnputil from C #, I was never able to get a security warning and the driver package was not added to the driver store. I have tried various options (eg Verb = "runas", UseShellExecute = true, etc.) with FileName given as "pnputil" or "cmd".

Ultimately what worked for me was creating a simple batch file containing the following:

%windir%\sysnative\pnputil /a <path_to_inf>

      

My C # application will then call this batch file like this:

Process proc = new Process();
proc.StartInfo.FileName = "<path_to_bat_file>";
proc.StartInfo.Verb = "runas";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
proc.Start();

      

The user will be prompted first because I asked to run at elevated permission, followed by the expected security warning. The driver package will then be added to the driver store as expected.

User account management

If that doesn't work as expected, you can add a "pause" (without quotes) on a new line after the last command in the batch file, and remove the WindowStyle and CreateNoWindow lines from the C # code to see what's going on on the command line.

0


source







All Articles