Search This Blog

Thursday, April 10, 2008

Detecting XP64 versus XP32 - Autolisp Function

Do you need a function that detects whether AutoCAD is running under XP32 or XP64? I had the need today. This is what I came up with:

;;; Begin code

;;; =========================================================================
;;; Function: RLB:XP64Detector
;;; Purpose : Function to detect running under 64 or 32bit XP
;;; Author : Richard Binning
;;; Date : 4/10/2008
;;; Call : (RLB:XP64Detector "Wow6432Node")
;;; Example : (if (= 0 (RLB:XP64Detector "Wow6432Node"))
;;; (alert "32 Bit Detected")
;;; (alert "64 Bit Detected")
;;; )
;;; Params : subKey: Name of XP64 Registry Key for installing 32bit apps
;;;
;;; Local : keyVal: Value of key sought
;;; : profileStr
;;; Returns : a number greater than 0 if running under XP64
;;; Notes : Placed in use to load correct version
;;; ================================================================================
(defun RLB:XP64Detector (subKey / keyVal retVal profilesStr)
(setq keyVal nil)
(setq profilesStr (strcat "HKEY_LOCAL_MACHINE\\SOFTWARE\\" subKey))
(setq keyVal (reverse (vl-registry-descendents profilesStr)))
(vl-list-length keyVal); return value
)

;;; end code

Anyone like to test this under vista?

2 comments:

Anonymous said...

(setq pltfrm (getvar "platform"))
(cond
((wcmatch pltfrm "*(x64)")
(setq pltfrm "64")
)
((wcmatch pltfrm "*(x86)")
(setq pltfrm "64")
)
(T nil)
) ;_ENDc

Richard Binning said...

Thanks anonymous,

Looks like there was a typo in the code you suggested. In the second condition if the pltfrm matches (X86) then the variable should be set to 32 not 64.

This code works well in XP 32. I'll try it in 64 bit vista this evening. Here is the corrected code:

(setq pltfrm (getvar "platform"))
(cond
((wcmatch pltfrm "*(x64)")
(setq pltfrm "64")
)
((wcmatch pltfrm "*(x86)")
(setq pltfrm "32")
)
(T nil)
) ;_ENDc

~Richard