HTA vs Vbs

In VBS this code tells you what bit version of windows is installed on the machine (32 vs 64 bit)
Set oShell = CreateObject("WScript.Shell")
WindowsProcessorArchitecture = oShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")

But in HTA this excact same code gives the wrong vaule!? If I run the code in a vbs file is gives me x86 on a 32 bit and AMD64 on a 64 bit windows.
But in HTA it gives me x86 on all version of windows. Is there another way to read Environment Strings in HTA?
Regard Brian
Who is Participating?
jostranderConnect With a Mentor Commented:
I think what's happening is the script is running in the 32bit environment.  oShell.ExpandEnvironmentStrings is probably returning the value from the "Process" environment.

Try the "System" environment:
Set oShell = CreateObject("WScript.Shell")
Set colEnvSystem = oShell.Environment("System")
WindowsProcessorArchitecture = colEnvSystem("PROCESSOR_ARCHITECTURE")

I have not tested this...
Just tested, and it returns AMD64 for me using System and x86 using Process
Brian_LarsenAuthor Commented:
Hey jostrander

I think you are right. I am reading about WOW64 as we speak. I will test your code and let you know ASAP.
But that will mean that HTA runs in a 32 bit enviroment and vbs dosen't? Anyway I also stumbleupon this site i my quest for answers wich explains it pretty well:

And there is some confusion about if this code will give the same result as well:
Get-WmiObject -class "Win32_Processor" -property "AddressWidth"
If the AddressWidth is "32" then you're on a 32-bit operating system. If the AddressWidth is "64" then you're on a 64-bit operating system. Some says it dos other that it dosen't. I can't really find any information from microsoft to verify this.

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Brian_LarsenAuthor Commented:
Ohh you replied while I was writing my comment. Well it sounds promising then. Will test it tomorrow at work, don't have a 64 bit computer at home. Thanks
Not sure, but I think you can change the environment that the HTA runs in... it's basically Internet Explorer, so I think if you set IE 64 bit as the default, it would change that.  I wouldn't recommend that though.
Brian_LarsenAuthor Commented:
Hey Jostrander

Just tested your code and it works as expected.
I also found out that you can test for the variable %PROCESSOR_ARCHITEW6432%. So if you run a 32 bit process in wow64 mode, then it creates an Environment Variable called PROCESSOR_ARCHITEW6432 in the "Process" (not "System").

Thanks for taking the time to help me out and put me in the right direction, really appreciate it.
Regards Brian
Brian_LarsenAuthor Commented:
spot on
All Courses

From novice to tech pro — start learning today.