tags:

views:

663

answers:

4

Hi,

I have two applications running on W2k8 R2 x64, one is compiled as 64bit and the other one as 32bit as it has COM dependencies. In both I'm trying to call:

Process p = Process.Start("telnet.exe", string.Format("{0} {1}", address, port));

In the x64 it works perfectly fine, however in the 32bit one I get a System.ComponentModel.Win32Exception ("The system cannot find the file specified")?

Any idea what's going on here? Even if I call

Process.Start(@"C:\Windows\System32\telnet.exe")

I get the same exception?

Thanks,

Tom

A: 

Windows Server 2008 does not have a 32 bit telnet.exe client. It only installs a 64bit version in the windows\system32 folder.

nithins
hm, is there any way to launch the 64bit exe from the 32bit .NET process?
Tom Frey
A: 

\live.sysinternals.com\tools\procmon.exe and/or procexp always has the answer.

Have you looked at the path environment variable in the context of your process? Can you prefix it with the System\SysWow64 path to make it work?

Ruben Bartelink
I think the issue is as nithins indicated that there is no 32bit version of telnet on w2k8 R2 x64 and I'm trying to launch a 64bit exe from a 32bit process. Because as indicated in my original post, even calling telnet directly with the full path (@"C:\Windows\System32\telnet.exe") fails
Tom Frey
Ah, sorry for not reading. There should not be a problem running an x64 exe from an x86 process tho' - its only a problem if you're loading it into the same address space (e.g. doing Assembly.LoadFrom for a DLL).
Ruben Bartelink
Ah, you're getting virtualisation intercepting the c:\windows\system32 and translating it to syswow64 (i.e. 32 bit equivalent).
Ruben Bartelink
http://blog.joeware.net/2009/08/28/1688/ use sysnative instead of system32 (dont have an x64 box to hand to test, sorry)
Ruben Bartelink
SysNative only works on Vista or later. You might want to use File.Exists to come up with an OS neutral impl. Best keyword for googling is sysnative x64. And I found a post from Russinovich in 2005 figuring this out using filemon [which is a predecessor of procmon].
Ruben Bartelink
Ah, if I'd scrolled up I'd have seen tyranid's answer! +1 that...
Ruben Bartelink
+2  A: 

To launch a system32 located 64bit app from a 32bit app (at least on Vista,2k8,7, doesn't work on x64 XP or 2k3) run it from the sysnative directory, i.e. "C:\windows\sysnative\telnet.exe" (alternatively disable Wow64 but that is generally a bad idea).

tyranid
Perfect, that works great! thanks
Tom Frey
A: 

This drove me crazy... had one project that would find "telnet.exe" without the full path and one that refused to find it (even with the path, or never figured it out). My dev machine is 64-bit.

The problem was the target platform in build.

If it's set to x86 it will not find telnet.

set it to Any CPU it will find telnet.

sometimes you need to set it to x86, this allows your applications to see 32-bit drivers (such as odbc drivers) on 64-bit platforms

Scott Kramer