C# pnputil not recognized
public void InstallPrinter(PrinterInfo printer)
{
string script = $@"script to install printer. install driver using pnputil."
using (PowerShell ps = PowerShell.Create())
{
ps.AddScript(script);
try
{
var results = ps.Invoke();
if (ps.HadErrors)
{
foreach (var error in ps.Streams.Error)
{
Console.WriteLine($"Error: {error}");
}
}
else
{
foreach (var result in results)
{
Console.WriteLine(result.ToString());
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
I checked the log and the error occur during the driver installation and it's because it doesn't recognize pnputil. No problem running in powershell console.
15 Replies
show the script you're trying to run
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/but
ps1
instead of cs
@The Guythe entire script?
at least the pnputil bits
oh okay
also the exact error message you're getting would help
BlazeBin - syfsaaqkdzoo
A tool for sharing your source code with the world!
2024-06-10 14:41:41 - Failed to add driver to the driver store. Error: The term 'pnputil' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
2024-06-10 15:10:11 - Driver added to the driver store successfully.
2024-06-10 15:10:12 - Failed to register printer driver. Error: The specified driver does not exist in the driver store.
huh, yeah that looks fine...
I will say, you may want to use raw strings for your own sanity https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
Raw string literals - ''' - C# reference
Raw string literals can contain any arbitrary text without the need for special escape sequences. You begin and end a raw string literal with a minimum of three double-quote characters.
like, this line here I assume you meant to interpolate that, but the double brace means it's escaped, so no interpolation
so just wrap the string script in 3 double quotes? or do i need to make any other adjustment?
I would do
(ignore the weird coloring, discord's formatter hasn't been updated)
okay, i will try that. thanks!