Click here to Skip to main content
12,892,320 members (49,890 online)
Rate this:
Please Sign up or sign in to vote.
See more: VBScript
I have a little problem and im stuck with my application since im not sure if it will work correctly on a x64 bit version.
Now im trying to create a VBScript which will check for OS bit and install the msi according to the OS bit.
I have found a lot of trash by googling for this solution which i think im not sure if it will work.

I have found another interesting code which will check if ProgramFilesx86 exist but the problem is only win7 has this option to check for xp and vista this folder seems not to exists. My processor is 32bit and i cant install an OS x64 to check it myself what differences are there to ensure what OS architecture it is.
I ask for help if somebody could tell me which folders or files or system files are different to a 32bit OS so to make a script to make sure which msi i can install(i will embed both assemblies on the main package)
Some scripts try to check from registry which will not work to all win versions.
Please refer me to the right answer, thanks Begi
Posted 26-Sep-12 10:05am
Sergey Alexandrovich Kryukov 26-Sep-12 16:14pm
Do you mean instruction-set architecture?
Sergey Alexandrovich Kryukov 26-Sep-12 16:19pm
I'm just curious: what makes you using VBScript for such things? What would you do if the script tells you the answer? Execute or install appropriate version of some application? If this is your goal, this would not be the best way to deploy the application. In particular, you can pack all the required checks in the MSI itself, but it depends on what instruments do you use for development of application, its build, and for creation of MSI. Chances are, there is much better way.
begi21 26-Sep-12 16:25pm
No i want it to check via VBScript. "André Kraak" just answered my question.
Sergey Alexandrovich Kryukov 26-Sep-12 16:59pm
The question is: why?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The way I check the bit version of the OS is by checking for the presence of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node[^].
If this key is not present you are on a 32-bit OS and 64-bit when it is present.
begi21 26-Sep-12 16:23pm
So this means this registry key exists on ALL WINDOWS VERSIONS OF 64 BIT? then you made my day brother!
Sergey Alexandrovich Kryukov 26-Sep-12 17:01pm
Great, but I'm afraid OP and I still don't know how to do it with VBScript or Windows Scripting Host. Any more info? (I voted 4.)
begi21 26-Sep-12 17:27pm
Look i have for example 2 Applications 86.exe and 64.exe and A VBSCRIPT that checks if the above mentioned registry key exists. If key exists it must be a 64 os so i run 64.exe else 86.exe

All these 3 files i archive into the Winrar and make it a selfextracting executable file. Call it "MySetupCreatedUnderWinrar.exe" under winrar i give some paths where these 3 files should be extarcted and which should be firstly executed when the user hits twice the "MySetup...exe" file on his computer!
Sergey Alexandrovich Kryukov 26-Sep-12 17:35pm
Yes, I exactly understand why do you need something like that. (But you don't need it in pure-.NET applications which can use "AnyCPU" target, due to JIT. Did you know that?)
The thing is: I would prefer applications which do not need installations (or self-install, with minimal to no footprint), you already do MSI. Once you already do it, it would be much nicer to have different versions for different instruction-set architectures to be chosen during installation. Got my point?
begi21 26-Sep-12 17:46pm
Yes thats something i can learn from you brother. Im aware of the AnyCPU option but as i researched on internet i found very very topics about this topic. And this topic confuses me very much so far as ive seen on web. Some people say like you some others say No you must first register it under Wow64 in cmd.exe before you can run, some others say it is CPU dependent if i create it in my pc which is 32bit processor it will not run in a 64 bit processor since ive created it via my processor 32 bit and lots of trash which has me confused that ive decided to make 2 apps 86 and 64.
What is your opinion about AnyCPU i want to know and whats about JIT? And further i am not creating games or complex apps, the more complexed thing i use in my App are APIs
I wait for your response to bring some more light into this darkness!
Sergey Alexandrovich Kryukov 26-Sep-12 18:40pm
This is all about .NET (well, a must-know for every .NET developer), you can find it in Wikipedia, in particular. But you did not tell me you platform.
This is simple. All types except managed pointers are not architecture dependent. All codes are compiled into IL, and finally compiled to CPU instructions by JIT, usually on per-call basics (at the time of first call of each method). This way, instruction-set architecture is out of equation -- it is calculated out by JIT compiler. This nice schema is broken when a developer uses some native platform calls via P/Invoke, which can be only 32-bit or one of the two (or more) 64-bit architectures. Then detection of CPU is needed again.

Any more questions, so far?
begi21 26-Sep-12 20:13pm
So far i dont have to be worried about when i select AnyCPU, only P/Invoke code is not compatible with AnyCPU. I dont even know what P/Invoke means but i think it is something which doesnt need .Net .dll files does this mean an "Unmanaged Code"?
If so i can without worries target my project into AnyCPU (from32bit os xp, 32bit processor) to make it work on both bit Platforms(86 and 64)?
Thank you for your efforts.
Sergey Alexandrovich Kryukov 26-Sep-12 20:30pm
Yes, this is how unmanaged code loaded and used by managed. Yes, without such things, you set "AnyCPU" and run exact same application on different machines without recompilation -- the executable code is finally JIT-compiled into CPU instruction code depending on CPU after it is already loaded.

You not gonna believe that -- even on different OS: Linux, Mac OS X, iOP, Android and more. For these systems (and for OS), there is alternative CLI implementation called Mono. You only need to use only standard library, and some non standard, like Forms or ADO.NET. Most of my own applications, even with UI, runs on Linux without recompilation, on different instruction-set architectures, of course.

begi21 26-Sep-12 21:32pm
Thank you very much for helping me, now i can compile it in any cpu and i will research if APIs are managed or unmanaged codes thats namely my last worry.
Thank you again for your help, Regards Begi
Sergey Alexandrovich Kryukov 26-Sep-12 22:18pm
You are welcome.
If you want to ask a particular question (there are still some delicate moments), as another question and notify me by commenting on this post.
begi21 27-Sep-12 12:21pm
I have a last question for you:D because im using APIs which i researched on WEB and found out that this is not written in .NET language which brings me to the conclusion that they are Unmanaged libraries: For example this codeline below refers to "user32"

Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal Hook As Integer, ByVal KeyDelegate As KDel, ByVal HMod As Integer, ByVal ThreadId As Integer) As Integer

Now the rest of my code will work with anyCPU but when it will come to this point it will throw most surely BadImageException because user32.dll doesnt exist in 64 bit OS
Should i rename it to "user64" to make it working or does this not exist such like user64.dll or should i embed user32.dll into my resources to refer there which is again the problem because you can either use 32 process or 64 bit process but noth both together combined.
Sergey Alexandrovich Kryukov 27-Sep-12 12:26pm
This line is "P/Invoke", but the thing is here: if you work on 64 platform, and none of your assemblies override "AnyCPU" (that is, ALL of them are targeted to "AnyCPU", SetWindowsHookExA can still be used, because it becomes 32-bit on 32-bit platforms, 64-bit on others, so this "AnyCPU" approach can still work.
begi21 27-Sep-12 12:35pm
Okay thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100