How do I detect a 64 bit version of Windows?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I detect a 64 bit version of Windows?

Vernon D. Cole
This is a reworded re-post of a question which I just placed to the IronPython list.  I repeat it here, because I hope to get a general answer which will work on CPython, too, since the database driver I support works on both implementations. I have code which detects the "width" of the Python I am running, but that is unimportant. I need to know which size of Windows is running.

I am testing adodbapi using my new laptop which I have set up as an everything in 64-bit test bed. 

My default test database is an .mdb (so-called ACCESS database) file.  Microsoft has decided that the JET engine, which has historically been used to read and write that format is to be deprecated, so there is no 64 bit version of it.  It is replaced by the Access Database Engine 2010 redistributable. Of course, the new software requires a different connection string, one containing "Provider=Microsoft.ACE.OLEDB.12.0;".

So, how can I tell which "width" of Windows I am running, so I know which connection string to use?
--
Vernon


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Gremlin-5

This may help:

 

WIN64 = 'PROGRAMFILES(X86)' in os.environ

 

Best regards

 


Von: python-win32-bounces+gremlin=[hidden email] [mailto:python-win32-bounces+gremlin=[hidden email]] Im Auftrag von Vernon Cole
Gesendet: Samstag, 18. Februar 2012 17:53
An: [hidden email]
Betreff: [python-win32] How do I detect a 64 bit version of Windows?

 

This is a reworded re-post of a question which I just placed to the IronPython list.  I repeat it here, because I hope to get a general answer which will work on CPython, too, since the database driver I support works on both implementations. I have code which detects the "width" of the Python I am running, but that is unimportant. I need to know which size of Windows is running.

I am testing adodbapi using my new laptop which I have set up as an everything in 64-bit test bed. 

My default test database is an .mdb (so-called ACCESS database) file.  Microsoft has decided that the JET engine, which has historically been used to read and write that format is to be deprecated, so there is no 64 bit version of it.  It is replaced by the Access Database Engine 2010 redistributable. Of course, the new software requires a different connection string, one containing "Provider=Microsoft.ACE.OLEDB.12.0;".


So, how can I tell which "width" of Windows I am running, so I know which connection string to use?
--
Vernon


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Brian Curtin
On Sat, Feb 18, 2012 at 13:22, Gremlin <[hidden email]> wrote:

> This may help:
>
> WIN64 = 'PROGRAMFILES(X86)' in os.environ
>
> Best regards
> ________________________________
>
> Von: python-win32-bounces+gremlin=[hidden email]
> [mailto:python-win32-bounces+gremlin=[hidden email]] Im Auftrag von
> Vernon Cole
> Gesendet: Samstag, 18. Februar 2012 17:53
> An: [hidden email]
> Betreff: [python-win32] How do I detect a 64 bit version of Windows?
>
>So, how can I tell which "width" of Windows I am running, so I know which
> connection string to use?

import platform
platform.machine()

That will return "AMD64" on 64 bit. I don't have a 32-bit machine
available but I believe it returns "x86".


ps, I can't find your thread on the IronPython list right now, but
platform.architecture() will help you find the architecture Python is
compiled for.
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Gelonida N
On 02/18/2012 09:07 PM, Brian Curtin wrote:
> On Sat, Feb 18, 2012 at 13:22, Gremlin <[hidden email]> wrote:
>
> import platform
> platform.machine()
>
> That will return "AMD64" on 64 bit. I don't have a 32-bit machine
> available but I believe it returns "x86".
This suggestion will not work for the OP.

It will tell you the platform, for which python was compiled and not the
real platform of the machine you're running on.

If you installed a 32 bit version of python on a 64 bit machine You will
get 'x86', which would be the wrong answer considering the OP's
requirements.


>
>
> ps, I can't find your thread on the IronPython list right now, but
> platform.architecture() will help you find the architecture Python is
> compiled for.


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Mark Hammond-4
In reply to this post by Vernon D. Cole
You can check for "64 bit" in sys.version (or use the platform module as
suggested by Brian) - if it is there it *must* be a 64bit Windows.  If
it is not there (ie, it is a 32bit Python), then call
win32process.IsWow64Process() - if it returns True it is a 64bit
windows, otherwise 32bits.

This is basically the same advice as in
http://blogs.msdn.com/b/oldnewthing/archive/2005/02/01/364563.aspx

Cheers,

Mark

On 19/02/2012 3:53 AM, Vernon Cole wrote:

> This is a reworded re-post of a question which I just placed to the
> IronPython list.  I repeat it here, because I hope to get a general
> answer which will work on CPython, too, since the database driver I
> support works on both implementations. I have code which detects the
> "width" of the Python I am running, but that is unimportant. I need to
> know which size of Windows is running.
>
> I am testing adodbapi using my new laptop which I have set up as an
> everything in 64-bit test bed.
>
> My default test database is an .mdb (so-called ACCESS database) file.
> Microsoft has decided that the JET engine, which has historically been
> used to read and write that format is to be deprecated, so there is no
> 64 bit version of it.  It is replaced by the Access Database Engine 2010
> redistributable.
> <http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255>
> Of course, the new software requires a different connection string, one
> containing "Provider=Microsoft.ACE.OLEDB.12.0;".
>
> So, how can I tell which "width" of Windows I am running, so I know
> which connection string to use?
> --
> Vernon
>
>
>
> _______________________________________________
> python-win32 mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/python-win32

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Brian Curtin
In reply to this post by Gelonida N
On Sat, Feb 18, 2012 at 21:11, Gelonida N <[hidden email]> wrote:

> On 02/18/2012 09:07 PM, Brian Curtin wrote:
>> On Sat, Feb 18, 2012 at 13:22, Gremlin <[hidden email]> wrote:
>>
>> import platform
>> platform.machine()
>>
>> That will return "AMD64" on 64 bit. I don't have a 32-bit machine
>> available but I believe it returns "x86".
> This suggestion will not work for the OP.
>
> It will tell you the platform, for which python was compiled and not the
> real platform of the machine you're running on.
>
> If you installed a 32 bit version of python on a 64 bit machine You will
> get 'x86', which would be the wrong answer considering the OP's
> requirements.

This is false.

platform.machine() is about the the computer itself - I fixed it in
2.6 to function properly, as it used to operate similar to
platform.architecture() due to looking in the wrong place.
platform.architecture() is about how Python was compiled.
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Gelonida N
On 02/19/2012 08:20 AM, Brian Curtin wrote:

> On Sat, Feb 18, 2012 at 21:11, Gelonida N <[hidden email]> wrote:
>> On 02/18/2012 09:07 PM, Brian Curtin wrote:
>>> On Sat, Feb 18, 2012 at 13:22, Gremlin <[hidden email]> wrote:
>>>
>>> import platform
>>> platform.machine()
>>>
>>> That will return "AMD64" on 64 bit. I don't have a 32-bit machine
>>> available but I believe it returns "x86".
>> This suggestion will not work for the OP.
>>
>> It will tell you the platform, for which python was compiled and not the
>> real platform of the machine you're running on.
>>
>> If you installed a 32 bit version of python on a 64 bit machine You will
>> get 'x86', which would be the wrong answer considering the OP's
>> requirements.
>
> This is false.
>
> platform.machine() is about the the computer itself - I fixed it in
> 2.6 to function properly, as it used to operate similar to
> platform.architecture() due to looking in the wrong place.
> platform.architecture() is about how Python was compiled.

Hmmm.
 I use python 2.6.4 on a 64 bit machine and get 'x86' as result.
perhaps it's only fixed in the newer 2.6 releases?



_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Mark Hammond-4
In reply to this post by Brian Curtin
On 19/02/2012 6:20 PM, Brian Curtin wrote:

> On Sat, Feb 18, 2012 at 21:11, Gelonida N<[hidden email]>  wrote:
>> On 02/18/2012 09:07 PM, Brian Curtin wrote:
>>> On Sat, Feb 18, 2012 at 13:22, Gremlin<[hidden email]>  wrote:
>>>
>>> import platform
>>> platform.machine()
>>>
>>> That will return "AMD64" on 64 bit. I don't have a 32-bit machine
>>> available but I believe it returns "x86".
>> This suggestion will not work for the OP.
>>
>> It will tell you the platform, for which python was compiled and not the
>> real platform of the machine you're running on.
>>
>> If you installed a 32 bit version of python on a 64 bit machine You will
>> get 'x86', which would be the wrong answer considering the OP's
>> requirements.
>
> This is false.
>
> platform.machine() is about the the computer itself - I fixed it in
> 2.6 to function properly, as it used to operate similar to
> platform.architecture() due to looking in the wrong place.
> platform.architecture() is about how Python was compiled.

Cool - that is good to know!  However, like gelonida, on 2.6 (and from a
2 week old hg build which is reporting itself as 2.6.7+) I don't see the
behaviour you suggest:

% py -2.6-32 -c "import platform, sys; print sys.version; print
platform.machine()"

2.6.7+ (unknown, Feb 20 2012, 09:54:27) [MSC v.1500 32 bit (Intel)]
x86

but it does work as you describe in 3.3:

% py -3.3-32 -c "import platform, sys; print(sys.version);
print(platform.machine())"

3.3.0a0 (default, Jan 28 2012, 15:39:56) [MSC v.1500 32 bit (Intel)]
AMD64

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

marceepoo
In reply to this post by Gelonida N
Dear Gelonida:

The following is a vbscript that will return the info you want.  You might want to run it in a python subprocess.



On Error Resume Next

' ------ SCRIPT CONFIGURATION ------
strComputer = "."   ' e.g. rallen-srv01
' ------ END CONFIGURATION ---------

set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")

set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
for each objOS in colOS
strOs32OR64bit = objOS.OSArchitecture
sOSname = objOS.Caption
Next

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WScript.Echo "Line 21:  strOs32OR64bit = objOS.OSArchitecture = " & strOs32OR64bit

Hope that helps.

                                  Marc



On Sun, Feb 19, 2012 at 12:53 PM, Gelonida N <[hidden email]> wrote:
On 02/19/2012 08:20 AM, Brian Curtin wrote:
> On Sat, Feb 18, 2012 at 21:11, Gelonida N <[hidden email]> wrote:
>> On 02/18/2012 09:07 PM, Brian Curtin wrote:
>>> On Sat, Feb 18, 2012 at 13:22, Gremlin <[hidden email]> wrote:
>>>
>>> import platform
>>> platform.machine()
>>>
>>> That will return "AMD64" on 64 bit. I don't have a 32-bit machine
>>> available but I believe it returns "x86".
>> This suggestion will not work for the OP.
>>
>> It will tell you the platform, for which python was compiled and not the
>> real platform of the machine you're running on.
>>
>> If you installed a 32 bit version of python on a 64 bit machine You will
>> get 'x86', which would be the wrong answer considering the OP's
>> requirements.
>
> This is false.
>
> platform.machine() is about the the computer itself - I fixed it in
> 2.6 to function properly, as it used to operate similar to
> platform.architecture() due to looking in the wrong place.
> platform.architecture() is about how Python was compiled.

Hmmm.
 I use python 2.6.4 on a 64 bit machine and get 'x86' as result.
perhaps it's only fixed in the newer 2.6 releases?



_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32



--

 ******************************************************************** 

The Law Offices of Marc B. Hankin, Inc.

Post Office Box 3668, Beverly Hills, California  90212 (Not for mail:509S.BeverlyDr.)

Tel: (310) 552-3005     Fax: (310) 382-2416

Email: [hidden email]    Website:  www.marchankin.com

     This e-mail message is generated from the law firm of the Law Offices of Marc B. Hankin, Inc., and may contain information that is confidential and may be privileged as an attorney/client communication or as attorney work product.  The information is intended to be disclosed solely to the addressee(s). 

     If you are not the intended recipient, any disclosure, copying, distribution or use of the contents of this e-mail information is prohibited.  If you have received this e-mail in error, please notify the sender by return e-mail and delete it from your computer system.

******************************************************************** 



_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: How do I detect a 64 bit version of Windows?

Gelonida N
Thanks Mark,


On 02/20/2012 03:28 AM, Marc Hankin wrote:

> Dear Gelonida:
>
> The following is a vbscript that will return the info you want.  You
> might want to run it in a python subprocess.
>
>
>
> On Error Resume Next
>
> ' ------ SCRIPT CONFIGURATION ------
> strComputer = "."   ' e.g. rallen-srv01
> ' ------ END CONFIGURATION ---------
>
> set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")
>
> set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
> for each objOS in colOS
> strOs32OR64bit = objOS.OSArchitecture
> sOSname = objOS.Caption
> Next
>
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> WScript.Echo "Line 21:  strOs32OR64bit = objOS.OSArchitecture = " &
> strOs32OR64bit
>

The solution in your other post works as well if you have win32process
process installed.


Y> ou can check for "64 bit" in sys.version (or use the platform module
> as suggested by Brian) - if it is there it *must* be a 64bit Windows.
> If it is not there (ie, it is a 32bit Python), then call
> win32process.IsWow64Process() - if it returns True it is a 64bit
> windows, otherwise 32bits.


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32