Proplem with c# and pnputil

  • Thread starter Thread starter Marti95
  • Start date Start date
M

Marti95

Guest
Hello


I have the problem that i cant call the pnputil function over c#.


My code:

static void ExecuteCommand(string command)
{
int exitCode;
ProcessStartInfo processInfo;
Process process;

processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;

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

// *** Read the streams ***
// Warning: This approach can lead to deadlocks, see Edit #2
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();

exitCode = process.ExitCode;

Console.WriteLine("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
Console.WriteLine("ExitCode: " + exitCode.ToString(), "ExecuteCommand");
process.Close();
}

ExecuteCommand("pnputil /add-driver " + inffilepath);

Result:

output>>(none)
error>>Der Befehl "pnputil" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

ExitCode: 1

Error in eglish:

The command "pnputil" is either misspelled or
could not be found.

I use Windows 10 and .NET Framework 4.6.1

I i start cmd and type the command it is working.

I dont find the problem.

Can someone help me?

Thanks

Continue reading...
 
Back
Top