Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run command from Process.Start

Tags:

c#

.net

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?

like image 405
sennett Avatar asked Jun 12 '12 01:06

sennett


1 Answers

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);
like image 198
sennett Avatar answered Oct 12 '22 23:10

sennett