Kimi
Kimi

Reputation: 563

How to run a specific DOS Command

I tried various methods possible to run this specific DOS command through C#. I do not want to use a batch file. Whatever I try, it keeps taking only first word from Printer name and not the entire name, in this case, it says Printer POS is not connected instead of saying Printer POS Lexmark is not connected. What could the error be? Thanks guys!

The DOS command is:

rundll32 printui, PrintUIEntry /o /n "POS Lexmark"

My code is as follows:

string command = string.Format("/c rundll32 printui, PrintUIEntry /o /n" + " POS Lexmark"); 
ProcessStartInfo cmdsi = new ProcessStartInfo("cmd.exe");
cmdsi.Arguments = command;
cmdsi.CreateNoWindow = false;
Process cmd = Process.Start(cmdsi); 

Upvotes: 1

Views: 2142

Answers (1)

ekolis
ekolis

Reputation: 6776

You forgot to include the quotes around POS Lexmark:

string command = string.Format("/c rundll32 printui, PrintUIEntry /o /n" + "\" POS Lexmark\"");

Upvotes: 5

Related Questions