How to find system type?

Just starting out? Need help? Post your questions and find answers here.
mRbrS
User
User
Posts: 17
Joined: Sun May 24, 2020 11:41 pm

How to find system type?

Post by mRbrS »

https://prnt.sc/su3jkz
a code example with autoit do this

Code: Select all

If @OSArch = "x86" Then
	MsgBox(0,"", "Your Operating System x86")
Else
	MsgBox(0,"", "Your Operating System x64")
EndIf
Is there a short example of this in Purebasic?
BarryG
Addict
Addict
Posts: 3293
Joined: Thu Apr 18, 2019 8:17 am

Re: How to find system type?

Post by BarryG »

mRbrS wrote:Is there a short example of this in Purebasic?
Yes -> viewtopic.php?p=256374#p256374

Returns 1 on a 64bit OS, or 0 on a 32bit OS.

Hint: I found this by searching these forums for "detect 64bit".
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: How to find system type?

Post by Marc56us »

Is there a short example of this in Purebasic?
Yes -> viewtopic.php?p=256374#p256374
Returns 1 on a 64bit OS, or 0 on a 32bit OS.
Does not works for Linux (Ligne 6: Structure not found: SYSTEM_INFO.)


For Windows you can check system environment variable ProgramFiles(x86) with GetEnvironmentVariable()

Code: Select all

If GetEnvironmentVariable("ProgramFiles(x86)") = ""
  MessageRequester("Info", "Windows 32 bits")
Else
  MessageRequester("Info", "Windows 64 bits")
EndIf
To see all environment variable available, type SET in shell (cmd)


For Linux there is HOSTTYPE, but I don't know why this does not works. :(

Code: Select all

GetEnvironmentVariable("HOSSTYPE")
= Nothing
But this works in shell (bash)

Code: Select all

# echo $HOSTTYPE
X86_64

Some environment variables are accessible to PB but not all of them while they are all accessible in the console (with the same user).
:?:
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: How to find system type?

Post by Tenaja »

Check the size of type int.

Nevermind, that's just for your program. Some 64 bit os's allow running 32 bit programs.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to find system type?

Post by mk-soft »

Tenaja wrote:Check the size of type int.

Nevermind, that's just for your program. Some 64 bit os's allow running 32 bit programs.
No,
PB program compiled as x86 is integer always 32 bit
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: How to find system type?

Post by StarWarsFan »

How about this:

Code: Select all

Procedure GetProcessorArchitechture()
   If GetEnvironmentVariable("PROCESSOR_ARCHITEW6432") = "AMD64"     : ProcedureReturn 64 ; OS is 64-Bit, but program is 32-Bit
   ElseIf GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") = "AMD64" : ProcedureReturn 64 ; OS and program are both 64-Bit
   ElseIf GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") = "x86"   : ProcedureReturn 32 ; both are 32-Bit
   EndIf   ; return 0, if failed
 EndProcedure
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: How to find system type?

Post by Marc56us »

Yes and no, it lacks IA64, ARM64

%PROCESSOR_ARCHITECTURE% can return differents values : AMD64, IA64, ARM64
https://docs.microsoft.com/fr-fr/window ... dfrom=MSDN

:arrow: possible solution: Check "64" at end

Code: Select all

Debug Right(GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"), 2) ; 64 
:wink:
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: How to find system type?

Post by NicTheQuick »

On Linux you could use the command "uname -i" for the OS type and "uname -p" or "uname -m" for the processor/machine type. See also here: https://unix.stackexchange.com/a/188572
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
mRbrS
User
User
Posts: 17
Joined: Sun May 24, 2020 11:41 pm

Re: How to find system type?

Post by mRbrS »

Thanks everyone :)
I love you PureBasic :)
Post Reply