sennett
sennett

Reputation: 8444

Can't run command from Process.Start

I can run this fine from the command line:

C:\Windows\System32\rundll32.exe "C:\Program Files (x86)\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen  C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg

Image opens no problem.

However, when I try and do this:

exe = "C:\\Windows\\System32\\rundll32.exe \"C:\\Program Files (x86)\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen  C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg";
Process.Start(exe);

I get a

System.ComponentModel.Win32Exception: The system cannot find the file specified

I have tried with quotes on both the command line and C#, and neither work with them. According to an answer I read on SO recently the last part should not be quoted.

What's going on?

Upvotes: 5

Views: 4960

Answers (1)

sennett
sennett

Reputation: 8444

Turns out one has to pass the command and arguments separately:

exe = "C:\\Windows\\System32\\rundll32.exe";
arguments = "\"C:\\Program Files (x86)\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen  C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg";
Process.Start(exe, arguments);

Upvotes: 13

Related Questions