Page 1 of 1 1
Topic Options
#185841 - 2008-02-29 08:08 PM Is my Windows 64 bit or 32 bit or other?
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I want to write a script that finds if my Windows is 64 bit or 32 bit (or another taste) to decide which installation package should be used.

Has anybody a better suggestion then trying to find an environment variable like ProgramFiles(x86) or CommonProgramFilesx(86)?

 Code:
Break On

;Declare variables
Dim $CommonProgramFiles
Dim $CommonProgramFilesx86
Dim $ProgramFiles
Dim $ProgramFilesx86

;Code
$ProgramFilesx86 = '%ProgramFiles(x86)%'
If Not $ProgramFilesx86 = ''
	? '64 bit OS'
Else
	? 'Not 64 bit OS'
	$ProgramFiles = '%ProgramFiles%'
	If Not $ProgramFiles = ''
		? '32 bit OS'
	EndIf
EndIf

$CommonProgramFilesx86 = '%CommonProgramFilesx(86)%'
If Not $CommonProgramFilesx86 = ''
	? '64 bit OS'
Else
	? 'Not 64 bit OS'
	$CommonProgramFiles  = '%CommonProgramFiles%'
	If Not $CommonProgramFiles  = ''
		? '32 bit OS'
	EndIf
EndIf

Top
#185842 - 2008-02-29 09:08 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Witto]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
You mean something besides $PROCESSOR_ARCHITECTURE% ???

If it exists in your environment, it's accurate. If it isn't there, it's X86 by default.

WMI - Win32_OperatingSystem : OSArchitecture - will return the O/S architecture type as well.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185843 - 2008-02-29 09:23 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Actually looked into this a while back, and have a "bits.kix" that tested the logic that was presented in the whitepaper.

As it relies on env vars, it's only useful for local processing, unlike WMI. There's actually two examples of the same thing shown below - inline code and a UDF.
 Code:
Break On
If InStr('%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%', 'AMD64')
  '64-bit' ?
Else
  '32-bit' ?
EndIf

CPUArchitecture() ?

Function CPUArchitecture()
  $CPUArchitecture = IIf(InStr('%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%', 'AMD64'), 'x64', 'x86')
EndFunction

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185845 - 2008-02-29 09:51 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Apparently the WMI object I referenced in the first post isn't always available.

"Win32_Processor : DataWidth" seems like a valid way to determine the hardware bits, and given that my second example seems to give very accurate results, I'd use WMI-Win32_Environment : Caption and search for < SYSTEM >\PROCESSOR_ARCHITECTURE to get the type of OS and apply the above logic. Microsoft uses "X86" for 32bit and "AMD64" for 64 bit O/S versions.

Glenn

PS - you'll find an updated WMISysInfo UDF on my web site after 8pm EST tonight that correctly identifies both the hardware datawidth (32/64) and O/S type (32-bit/64-bit) values, along with lots of other stuff.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185856 - 2008-03-01 05:17 AM Re: Is my Windows 64 bit or 32 bit or other? [Re: Glenn Barnas]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Thanks Glenn.
HOWTO: Detect Process Bitness
What about this to start?
; ===========================================================================================
;
;     Script Information
;    
;     Title:       WinNT32or64
;     Author:      Wim Rotty
;     Description: Find if Windows is 32 or 64 bit
;    
;
; ===========================================================================================
;Script Options

If Not @LOGONMODE
    Break On
Else
    Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
    $RC = SetOption("WrapAtEOL", "On")
EndIf

;Declare variables
Dim
 
$OS
Dim $PROCESSOR_ARCHITECTURE
Dim $PROCESSOR_ARCHITEW6432
Dim $bit

;Initialize variables
$OS = '%OS%'
$PROCESSOR_ARCHITECTURE = '%PROCESSOR_ARCHITECTURE%'
$PROCESSOR_ARCHITEW6432 = '%PROCESSOR_ARCHITEW6432%'

;Code
Select
    Case Not $OS = 'Windows_NT'
        Exit 1150
   
Case $PROCESSOR_ARCHITECTURE = 'amd64' Or $PROCESSOR_ARCHITEW6432 = 'amd64'
        $bit = '64'
    Case $PROCESSOR_ARCHITECTURE = 'x86' And $PROCESSOR_ARCHITEW6432 = ''
        $bit = '32'
    Case 1
       
Exit 1150
EndSelect

? $bit    

Top
#185858 - 2008-03-01 10:09 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Witto]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Well, if you really want to reverse-golf it, it's a start.
 Code:
$Bits = IIf(InStr('%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%', 'AMD64'), 64, 32)
'Bits: ' $Bits ?

brings the core code for local system detection to one line. It's so small and simple I haven't even bothered with a UDF, especially since when I need this, I need to know remotely, and the WMISysInfo UDF supplies the HW/OS info I need.

If you read the article, it basically says that if either of the Env Vars contain "AMD64", you are running on a 64 bit OS. The only alternative (for Kix, at least) is 32 bit x86. The logic above tests both vars for AMD64 in one pass. If you need to further determine if you're in a WOW64 session, you can read the %PROCESSOR_ARCHITEW6432% value directly.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185859 - 2008-03-02 04:04 AM Re: Is my Windows 64 bit or 32 bit or other? [Re: Glenn Barnas]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
don't we already have some macro for this?
@wow or something?
_________________________
!

download KiXnet

Top
#185863 - 2008-03-02 01:57 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
come on guys.
what's the idea, what I'm missing?

what the env var version provides that the kixtart macro doesn't?
_________________________
!

download KiXnet

Top
#185872 - 2008-03-02 05:56 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Lonkero]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I don't know what you're missing.
I want to create a script to install a piece of software. I have a two packages:
- 1 for Windows NT 32 bit
- 1 for Windows NT 64 bit
I want to create a script that decides for me which package will be installed. That is all.

Top
#185874 - 2008-03-02 06:35 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
indeed.
so, what's wrong with:
 Code:
if @onwow64
 ;install x64
else
 ;install x86
endif
_________________________
!

download KiXnet

Top
#185875 - 2008-03-02 08:55 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Lonkero]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Mmm. Most probably you are right. Thanks.
I presume this will work as long as there is no 64 bit version of kixtart?

Top
#185877 - 2008-03-02 11:14 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, at least for that long.
then you will have the dilemma of calling either wkix32.exe or wkix64.exe \:\)
_________________________
!

download KiXnet

Top
#185878 - 2008-03-02 11:15 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or ruud will switch to .net

but, think those days are far in the future yet.
_________________________
!

download KiXnet

Top
#185882 - 2008-03-03 11:21 AM Re: Is my Windows 64 bit or 32 bit or other? [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Current word from Ruud is that he is working on UNICODE KiXtart support.
Top
#185893 - 2008-03-03 08:01 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
that is a transition that might also introduce new build environment and maybe even x64 code...
_________________________
!

download KiXnet

Top
#198509 - 2010-04-29 08:24 PM Re: Is my Windows 64 bit or 32 bit or other? [Re: Lonkero]
MattColeman Offline
Fresh Scripter

Registered: 2008-05-19
Posts: 12
Loc: Kitchener-Waterloo, ON
thanks for the @ONWOW64 heads up lonkero... works like a charm!
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.066 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org