4

I'd like to be able to launch a page.hta in 32bit and 64bit versions of the mshta.exe.

Create the file c:\page.hta

<body onclick="if(confirm('Close? (onclick)')){self.close();}">
<h1>Test Page</h1>
<script type="text/javascript">
var elem = [
  "UserAgent="+window.navigator.userAgent,
  "Platform="+window.navigator.platform
];
var taBegin = "<textarea style='width:100%' rows='"+((elem.length+1)*1.5)+"'>";
var taEnd = "</textarea>";
document.write(taBegin+elem.join("\n")+taEnd);
</script>
</body>

Now here is the batch file to attemp to load the page differently.

@echo off
rem Launch 32bit
c:\Windows\SysWOW64\mshta.exe c:\page.hta

rem Launch 64bit
c:\Windows\System32\mshta.exe c:\page.hta

Another interesting thing, try changing the default handler to notepad for .hta files. If you execute the previous commands, and it launches notepad. It appears that mshta has some logic that only launches the .hta via the default handler.

Whatever command is specified as the default handler is used.

TJR
  • 3,617
  • 8
  • 38
  • 41

2 Answers2

1

Maybe it's a OS version issue (?) I can't tell, as your test run as expected on my XP x64.

[EDIT] The code I run:

Rem run32.bat
%WinDir%\SysWOW64\mshta.exe c:\page.hta

Rem run64.bat
%WinDir%\System32\mshta.exe c:\page.hta

Here is what I get: test screenshot

Panayot Karabakalov
  • 3,109
  • 3
  • 19
  • 28
  • So from the same 64bit OS, did you use the batch file to launch the hta with both mshta.exe? – TJR Mar 24 '13 at 23:30
  • Yes, I used batch file as you did, it run the .hta using both `mshta.exe` (from `SysWOW64` and `System32`). – Panayot Karabakalov Mar 24 '13 at 23:40
  • This is true of the command shell _`cmd.exe` is 64 bit_. If you run _32 bit version of `cmd.exe`_ (`%WinDir%\SysWOW64\cmd.exe`), then in both cases 32 bit version of `mshta.exe` will be started, and the page will show `Platform=Win32`. – Alexey Ivanov Mar 29 '13 at 10:23
  • @AlexeyIvanov - So, em I the only one lucky running `mshta.exe` as 64 bit process? I think we can make our comments more useful if we mention our OS version. – Panayot Karabakalov Mar 29 '13 at 16:16
  • @PanayotKarabakalov I tested it on Windows 7, 64 bit. You didn't write what you see. Does it always launch 64 bit version? How do you launch your batch file? – Alexey Ivanov Apr 01 '13 at 08:13
  • @AlexeyIvanov - I'm not sure why you run 32 bit version of `cmd.exe` and expect it to run 64 bit version of `mshta.exe`. Run your 64 bit version of `cmd.exe` (it's default on x64 OS). – Panayot Karabakalov Apr 01 '13 at 12:51
  • @PanayotKarabakalov Maybe I wasn't clear enough. If `cmd.exe` is 64 bit, then I get the results presented in this answer: the page reports Win32 and Win64 platform correspondingly. If I use 32 bit version of `cmd.exe`, then platform is Win32 in both cases. What version is default depends on the current environment: 64 bit version is started from a 64 bit process by default, and 32 bit version is started from a 32 bit process. So _default_ is a relative notion in 64 bit OS. – Alexey Ivanov Apr 01 '13 at 13:25
  • @AlexeyIvanov - Yes, I said the same. – Panayot Karabakalov Apr 01 '13 at 14:04
  • @PanayotKarabakalov My comment was addressed to the OP, and added some details to your answer regarding 32 bit version of `cmd.exe`. It is still unclear what problem the OP has, so I thought adding another bit of information wouldn't hurt. – Alexey Ivanov Apr 01 '13 at 14:16
0

the system32/systemwow64 folders are "virtual" in the sense that their content is determined by the OS depending on the bitness of the accessing application - in your case cmd.exe is probably the 64 Bit version so it will always start the 64 Bit-version of the mshta.exe

for starting a command prompt in 32 bit see http://astatalk.com/thread/7382/0/How_to_Open_and_Run_32-bit_Command_Prompt_in_x64_Windows/

it could also help to use SysNative instead of system32 and see how mshta.exe acts then...

mshata.exe seems to just use the standard settings for .hta so that it propbably won't matter whether you start the 32bit or the 64bit version of mshta.exe - you can try by associating .hta with 32 bit sersion of your browser...

IF you want to bypass that then you could just call the browser (32 bit or 64 bit) directly in your batch file...

EDIT - as per comment:

For 64 Bit execution you could use "C:\Program Files\Internet Explorer\iexplore.exe" in your batch file and
for 32 Bit execution you use "C:\Program Files (x86)\Internet Explorer\iexplore.exe".

Depending on youd system you need to open up a command shell with the desired bitness - see the link above.

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • Could you be more specific on how to bypass the default handler? – TJR Aug 06 '11 at 15:59
  • I'm confused why you bring in iexplore.exe? I never mention iexplore.exe in the question. – TJR Aug 08 '11 at 14:32
  • you wanted to bypass the default handler... ultimately .hta are html application which the IE can execute... with the above you could choose between 32 and 64 Bit – Yahia Aug 08 '11 at 16:13
  • IE and MSHTA may both use http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx but that doesn't mean they are the same. – TJR Aug 11 '11 at 16:08
  • I know that they are not the same but I suspect that IE is the nearest thing to bypass the default handler and choose between 32 and 64 bit. – Yahia Aug 11 '11 at 16:10