cannot call ServerManagerCmd.exe in C#

jiangok

Member
Joined
Jun 15, 2009
Messages
2
Hi,

I try to call ServerManagerCmd.exe in C#. Below is my code:

ProcessStartInfo startInfo = new ProcessStartInfo("ServerManagerCmd.exe", "");
Process process = Process.Start(startInfo);

However, running this code always throws error "System.ComponentModel.Win32Exception: The system cannot find the file specified".

I have verified ServerManagerCmd.exe is in c:\windows\system32 and I can run it in a command window without specifying the full path.

Also there is no problem to run some other exe files in the same directory through the C# code, for example, wevtutil.exe.

I also called ServerManagerLauncher.exe in C#. It has the same problem as ServerManagerCmd.exe.

Why I cannot call any ServerManager*.exe in C# code?

Thanks a lot for your help.


Thanks
Leon

 
Late reply, quick note to others baffled searching for an answer.

The system cannot find the file specified.
I have verified ServerManagerCmd.exe is in c:\windows\system32 and I can run it in a command window

Just ran into the same behaviour. Took me a while to figure out what was happening, thinking this had something to do along the line of starting the process without elevated rights, running the executable from a less-trusted file share or anything like that. The answer was less obvious than expected:

You are running your code as a 32 bit application in a 64 bit Windows Server environment.

The operating system uses the %SystemRoot%\system32 directory for its 64 bit executables. When executing 32 bit applications, WOW64 (Windows on Windows) redirects requests for DLLs from that directory to %SystemRoot%\sysWOW64. The process you're spawning should search for its files in a different location. A couple of suggestions when you can't find system DLLs you know are there:


Code:
Solution 1. Build your program 64 bit.
Code:
Solution 2. @"%WINDIR%\Sysnative\ServerManagerCmd.exe"
Code:
Solution 3, @"%WINDIR%\SysWow64\ServerManagerCmd.exe"
Code:
Solution 4. Start %windir%\SysWoW64\cmd.exe; set PATH=%systemroot%\SysWOW64;%PATH%;

Regards,

Patrick de Kleijn
 
Back
Top