What's different betwen running CMD via WinBatch and via Windows Explorer

Started by jtrask, October 28, 2013, 09:08:33 AM

Previous topic - Next topic

jtrask

I'm trying to execute manage-bde.exe (Included with Windows 7), via a WinBatch script.  It's not working.  I receive a message that the file doesn't exist.

I changed my script to execute this via the command prompt (CMD /K C:\Windows\System32\manage-bde.exe <parameters>), my command prompts opens (as administrator because that's how WinBatch Studio is running) and receive a message "'C:\Windows\System2\manage-bde.exe' is not recognized as an internal or external command.'

If, in that same command prompt, I CD to C:\Windows\System32, and type 'Dir man*.*', the only result is the manifestore directory.

If, I execute CMD.exe as administrator, I CD to C:\Windows\System32 and type 'Dir man*.*', I receive, manage-bde.exe, manage-bde.wsf, and the manifeststore directory.

Why is this behaving this way?

Deana

What you are dealing with is something called File Redirection. When launching the Windows Command Shell (CMD.EXE), Windows decides automatically which bit depth to load, depending on the calling application. e.g. 32 bit for 32 bit, 64 bit for 64 bit. ; On a 64-bit Architecture

Code (winbatch) Select

; By default 32-bit WinBatch launches the 32-bit CMD.EXE
; By default 64-bit WinBatch launches the 64-bit CMD.EXE
Run( Environment("COMSPEC"), '' )
Exit


What if you donââ,¬â,,¢t want that? Then you must explicitly run specific bitness of CMD.EXE by specifying full path name as follows:

To explicitly run the 32-bit version of a command:   
Code (winbatch) Select
cmd_32 = DirWindows(0):'syswow64\CMD.EXE'
Run( cmd_32, '' )
Exit


To explicitly run the 64-bit version of a command:   
Code (winbatch) Select
cmd_64 = DirWindows(0):'Sysnative\CMD.EXE'
Run( cmd_64, '' )
Exit

Deana F.
Technical Support
Wilson WindowWare Inc.

td

Quote from: Deana on October 28, 2013, 10:04:54 AM
...

To explicitly run the 32-bit version of a command:   
Code (winbatch) Select
cmd_32 = DirWindows(0):'syswow64\CMD.EXE'
Run( cmd_32, '' )
Exit


To explicitly run the 64-bit version of a command:   
Code (winbatch) Select
cmd_64 = DirWindows(0):'Sysnative\CMD.EXE'
Run( cmd_64, '' )
Exit


The above works for 32-bit WinBatch but using "Sysnative" in a script executed via 64-bit WinBatch will cause a WinExec error, i.e., the system could not find the file.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jtrask

Interesting, but on my 64-bit machine, the System32 folder is the System32 folder regardless of which command interpreter I'm running, right?

Or will the 32-bit CMD only show me 32-bit files?

Deana

If running on a 64-bit system....The %windir%\System32 directory is reserved for 64-bit applications. 32-bit versions of the files are stored in a different directory. WOW64 hides this difference by using a file system redirector. In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64.

Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx
Deana F.
Technical Support
Wilson WindowWare Inc.

jtrask

Thank you.  I should have known that.  I know that when I install 32-bit software, it knows to use SysWOW64.  I don't know why it would be any different when I access it via WinBatch.  I just didn't put 2 & 2 together.