none
Windows 7 x64: Execute a 64bit exe/script from a 32bit command prompt?

    Question

  • Anyone have any tricks up their sleeve to do as the title says?  For example:

    I'm working within a 32bit app that calls a command using cmd.exe.  In taskmanager we see cmd.exe*32
    From that cmd.exe, say we want to launch notepad.exe.  Obviously taskmanager will show notepad.exe*32.  We want plain old "notepad.exe" running in 64bit mode.

    Thoughts:
    I've been unable to do this using vbscript and may try a .NET console application next.
    Another thought is to set up a schtask, run it, then delete it....but that sounds messy.

    Am I missing something that would make this extremely easy?

    Thursday, December 23, 2010 5:31 PM

Answers

  • Well, I'm working within WiseScript Editor and SMS Installer. They are 32bit compiled scripting languages so, if I launch notepad.exe from within the compiled Wise or SMS Installer scripts, using either their built-in Execute Program command the OS always launches the process as a 32bit process as the parent process is 32bit even when trying to specify notepad.exe in %WINDIR%\system32.

    I did, however, find a solution using vb.net.  I compiled the following code as a console app named cmdx64.exe

    Module Module1

        Sub Main()
            Dim arrArgs As Array
            Dim Args As String = ""
            Dim intCount As Integer = 0

            arrArgs = System.Environment.GetCommandLineArgs()
            For Each Arg In arrArgs
                If intCount <> 0 Then Args = Args & " " & Arg
                intCount = intCount + 1
            Next
            Shell("cmd.exe /C" & Args, AppWinStyle.NormalFocus, True)
        End Sub

    End Module

    Now when I run "cmdx64.exe notepad.exe" from within WiseScript Editor and SMS Installer instead of getting notepad.exe*32 I now get the 64bit flavor. So...I guess I answered my own question but it required a custom console command.  I was hoping for a native solution.

    • Edited by robsons Thursday, December 23, 2010 6:39 PM code looked funny
    • Marked as answer by robsons Friday, December 24, 2010 6:27 AM
    Thursday, December 23, 2010 6:37 PM

All replies

  • I'm working within a 32bit app that calls a command using cmd.exe.  In taskmanager we see cmd.exe*32
    From that cmd.exe, say we want to launch notepad.exe.  Obviously taskmanager will show notepad.exe*32.  We want plain old "notepad.exe" running in 64bit mode.


    I observe different results. Here is what I tried on my Windows 7 machine:
    - Click Start / Search
    - Type this command:  timethis.exe cmd /c d:\test.vbs
    (timethis.exe is a 32-bit application)

    This gave me the following:
    - a 32-bit instance of cmd.exe
    - a 32-bit instance of cscript.exe
    - a 64-bit instance of iexplore.exe

    d:\test.vbs
    Set oWshShell = CreateObject("WScript.Shell")
    sCmd = "cmd.exe /c """"c:\Program Files\Internet Explorer\IExplore.exe"""""
    owshshell.Exec sCmd
    msgbox "Running IE 64-bit"

    Thursday, December 23, 2010 6:07 PM
  • Would it help to specify the path to notepad.exe? I find the exe in the paths:

    c:\Windows\SysWOW64

    c:\Windows\System32

    The only code I've found for handling 32 vs 64 bit versions either uses "c:\Program Files" vs "c:\Program Files (x86)", or uses WbemScripting.SWbemNamedValueSet to read different parts of the registry. Neither technique would help here.

    Richard Mueller


    MVP ADSI
    Thursday, December 23, 2010 6:16 PM
    Moderator
  • Well, I'm working within WiseScript Editor and SMS Installer. They are 32bit compiled scripting languages so, if I launch notepad.exe from within the compiled Wise or SMS Installer scripts, using either their built-in Execute Program command the OS always launches the process as a 32bit process as the parent process is 32bit even when trying to specify notepad.exe in %WINDIR%\system32.

    I did, however, find a solution using vb.net.  I compiled the following code as a console app named cmdx64.exe

    Module Module1

        Sub Main()
            Dim arrArgs As Array
            Dim Args As String = ""
            Dim intCount As Integer = 0

            arrArgs = System.Environment.GetCommandLineArgs()
            For Each Arg In arrArgs
                If intCount <> 0 Then Args = Args & " " & Arg
                intCount = intCount + 1
            Next
            Shell("cmd.exe /C" & Args, AppWinStyle.NormalFocus, True)
        End Sub

    End Module

    Now when I run "cmdx64.exe notepad.exe" from within WiseScript Editor and SMS Installer instead of getting notepad.exe*32 I now get the 64bit flavor. So...I guess I answered my own question but it required a custom console command.  I was hoping for a native solution.

    • Edited by robsons Thursday, December 23, 2010 6:39 PM code looked funny
    • Marked as answer by robsons Friday, December 24, 2010 6:27 AM
    Thursday, December 23, 2010 6:37 PM
  • It has me curious -- why does it matter?

    Bill

    Thursday, December 23, 2010 10:27 PM
    Moderator
  • When you run the "Execute Program" function in SMS Installer and WiseScript you only get 32bit processes.  Even specifying %WINDIR%\system32\cmd.exe on a Win7 x64 box, both SMS Installer and WiseScript only opens a cmd.exe*32. The root of the problem is 1) SMS Installer is 32bit only and is no longer supported, and 2) Altiris seems to have no intention of making their WiseScript Editor 64bit compliant.

    Our application deployment process leans heavily on the usage of WiseScript Editor for quickly automating the deployment and configuration of applications and the OS.  With Win7 x64 on the horizon we need to start making changes, thats for sure, but at least now we can still use WiseScript in the interim.

    Why exactly does it work?  I'm not entirely sure as I dont really know how those scripting engines execute programs.  What I do know is that the x64 OS redirects everything to the x86 locations when using WiseScript. At least now if we install a 64bit application and then need to configure an INI or registry key for that application we can do so using that 64bit console app I wrote in the WiseScript "Execute Program" function.  Otherwise, our WiseScripts would only have access to the WOW6432node, Program Files (x86), and other similar locations that 32bit apps get redirected to.

    Friday, December 24, 2010 6:24 AM
  • I must have not explained my original question correctly. The problem was this:

    1) From the run box execute: %WINDIR%\sysWOW64\cmd.exe /K
    2) Note that this console is running in taskmanager as cmd.exe*32.
    3) From this 32bit console start notepad.exe in 64bit mode by specifying the 64bit location: %WINDIR%\system32\notepad.exe
    4) Step 3 fails to launch notepad in 64bit mode. Notepad runs as notepad.exe*32 even tho we specified the 64bit location of notepad.

    This is expected behavior as the 64bit OS tries to sandbox 32bit applications.  I need a way out of this sandbox while using some 32bit scripting engines such as WiseScript and SMS Installer. The 64bit console app I marked as an answer somehow gets me out of this 32bit sandbox when used in WiseScript and SMS Installer.

    If there is any other way to get out of this 32bit sandbox, such as opening a 64bit console using a vbscript launched from %WINDIR%\sysWOW64\cscript.exe, then that would be great.

    Friday, December 24, 2010 5:31 PM
  • 3) From this 32bit console start notepad.exe in 64bit mode by specifying the 64bit location: %WINDIR%\system32\notepad.exe
    Try fc.exe /b in order to compare what you think are the 32-bit and 64-bit versions of notepad.exe. They look identical to me. This suggests that notepad.exe can run in 64-bit or in 32-bit mode, depending on how it gets invoked. If you invoked a true 64-bit program such as IExplore.exe then you would get what you expect, which is what I tried to demonstrate in the code I posted earlier.
    Friday, December 24, 2010 6:15 PM
  • Try fc.exe /b in order to compare what you think are the 32-bit and 64-bit versions of notepad.exe. They look identical to me. This suggests that notepad.exe can run in 64-bit or in 32-bit mode, depending on how it gets invoked. If you invoked a true 64-bit program such as IExplore.exe then you would get what you expect, which is what I tried to demonstrate in the code I posted earlier.

    That is odd...I don't see that at all on my Windows 7 x64 machine...are you sure about that?

     

    C:\>dir C:\Windows\System32\notepad.exe
     Volume in drive C has no label.
    
     Directory of C:\Windows\System32
    
    07/13/2009 06:39 PM   193,536 notepad.exe
        1 File(s)  193,536 bytes
    
    C:\>dir C:\Windows\SysWOW64\notepad.exe
     Volume in drive C has no label.
    
     Directory of C:\Windows\SysWOW64
    
    07/13/2009 06:14 PM   179,712 notepad.exe
        1 File(s)  179,712 bytes
    
    
    Bill

     

    Thursday, January 06, 2011 7:51 PM
    Moderator
  • I think the best answer is to get a 64-bit version of your installer engine...

    Bill

    Thursday, January 06, 2011 7:56 PM
    Moderator
  • I agree. Also, I see the same two copies of Notepad.exe on my Win7 machine, and both are version 6.1.7600.16385.

    Richard Mueller


    MVP ADSI
    Friday, January 07, 2011 1:21 AM
    Moderator
  • Does 'c:\windows\sysnative' not work?
    Monday, January 24, 2011 12:05 PM
  • I am also looking for a solution to a very similar problem. If you are in 32-bit command shell (not necessarily cmd.exe, thats part of the problem!) and you can not easily switch to a 64-bit version, but you need to launch a 64-bit console application, how can you do that?

    Just trying to run it, gets you: "This version of C:\P.exe is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher."

    I see that you can run a 32-bit console application fine under a 64-bit command shell, but not the other way around.

    I did think you could be clever and shell out to the 64-bit version of cmd.exe and pass it a command line argument, but of course Windows hides the 64-bit cmd.exe from a 32-bit command shell. Dir cmd.exe /s etc. will not find it.

    The must be some clever little way... Some clever way of invoking shellexecute or getting the desktop manager to execute a cmd.exe /xxx for you which would get you the 64-bit version of it?


    Friday, February 18, 2011 10:33 PM
  • Are you asking if you can run an x64 program on an x86 computer?

    Bill

    Friday, February 18, 2011 11:20 PM
    Moderator
  • I am also looking for a solution to a very similar problem. If you are in 32-bit command shell (not necessarily cmd.exe, thats part of the problem!) and you can not easily switch to a 64-bit version, but you need to launch a 64-bit console application, how can you do that?

    %systemroot%\sysnative\cmd.exe

    %systemroot%\sysnative\cmd.exe /c notepad.exe

    • Proposed as answer by -Nick Monday, March 14, 2011 10:32 AM
    Monday, February 21, 2011 8:52 AM
  • awesome.  I was looking for this as well!

    Our issue is we use an old x86 program for login scripts, and one of the test scripts is to kill explorer.exe and restart it to refresh a background image.  Not pretty, but it works.  with the 32bit cmd it opens windows explorer instead of the actual explorer process.  using the %systemroot%\sysnative\cmd.exe /c explorer.exe allowed it to open the x64 explorer.  This is just on our test lab but it was frustrating first figuring out what it was doing, and then finding a solution that didn't involve a complex script.

    Monday, March 14, 2011 10:32 AM
  • Thanks a bunch !

    I was trying to launch a vbs script on a Windows Server 2008 R2 64 bits from a Linux 32-bits scheduler.

    This script need to be run in 64-bits mode.

    Neither did "C:\windows\system32\cscript myscript.vbs" nor "C:\windows\system32\cmd /c myscript.vbs" work.

    %systemroot%\sysnative\cmd.exe /c myscript.vbs did !

    Thanks again !

    Tuesday, May 31, 2011 11:20 AM
  • Thanks a lot.  Been looking for a solution to this problem for a while.

    %systemroot%\sysnative\cmd.exe /c myscript.vbs work for me!


    • Edited by icampbell Friday, July 04, 2014 3:03 PM
    Friday, July 04, 2014 3:02 PM