WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System Info

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to detect a Laptop

Keywords:    laptop detection   PCMIA

Question:

I've found out an easy way to detect a laptop under NT and 95.
        laptop=RegOpenKey(@REGMACHINE,"Config\0002")
        If LastError()==1158 Then GoTo DeskTop
Comments?

Answer:

Hmmm. Might be a good heuristic, but it simply indicates the machine has more than one running hardware configuration. (In the case of a laptop - perhaps docked and undocked). I'd want something a bit more reliable.

For example, I have a laptop with NO multiple configurations and do NOT have a "2" there. What is better is to check for the PCMCIA key. It IS true that the key itself exists on desktops, but there are NO subkeys. On laptops, there is a subkey for each enabled PCMCIA slot, as well as an extra one (on mine, I think it's for the video).

The following code was able to determine the difference between a laptop and desktop for me, should work for you also.

        ; initialize PCMIA key to check
        PCMCIAKey="System\CurrentControlSet\Services\Class\PCMCIA"
        LapCheck=RegOpenKey(@REGMACHINE,PCMCIAKey)
        LapCheckList=RegQueryKeys(LapCheck)
        RegCloseKey(LapCheck)
        ; count number of subkeys of PCMIA key; if 0 then NOT a laptop
        LapCheckListCnt=ItemCount(LapCheckList,@TAB)
        If LapCheckListCnt!=0
           Display(3,"Laptop Test","This is a LAPTOP")
        Else
           Display(3,"Laptop Test","This is a DESKTOP")
        EndIf
BTW, the ONLY desktop computer(s) I have ever heard of with PCMCIA slots are the so called "green PC's" which IBM (and possibly others) put out a while ago. They used PCMCIA and a LCD display to keep the power consumption of the ENTIRE computer to about 35W.

And here's info from another user:

Question:

Is there some way to distinguish between a laptop and a desktop at run time?

Answer:

I usually check to see if the PCMCIA drivers are installed. Most desktops don't have them, most laptops do, e.g.,
if RegExistKey(@REGMACHINE,"Enum\PCMCIA")
Message("Probably","Laptop")
else
Message("Probably","Desktop")
endif
In addition to looking for some sort of PCMCIA or CardBus services, I would recommend looking for the presence of multiple hardware configurations. If multiple hardware configurations are found, check the descriptions of them and determine if any of them contain the text 'dock' or 'remote' or 'mobile'. Laptops generally have a docking station port on the back and the Win9x or WinNT installation and hardware detection routines can detect this and create appropriate hardware configurations.

The hardware configuration names are stored in the registry.

The following sample code is cut from a larger script that was used to automate the site-specific customization of Win95 laptops. One of the things that we specifically did was to configure the file system caching settings differently based on whether a system was a laptop or a desktop system. This code sample made the appropriate registry changes based on what it determined about the hardware configuration.

The following section of a .INI file contains the data used to determine the differnce between a laptop by checking for multiple configurations and for the presence of various types of hardware & drivers:

; The "Config Names" are actually fragments of text
; that may occur in the name of a system hardware profile
; on a laptop computer. We will prompt the user to confirm
; that the computer is a laptop if a configuration is found
; with any of the following text fragments in its name.

[PotentialLaptopConfigNames]
;
DIAL=
DOCK=
MOBILE=
MODEM=
OFFSITE=
REMOTE=
ROAM=
TRAVEL=


; The "Device Descriptions" are actually fragments of text
; that may occur in the device description of a device
; on a laptop computer. We will prompt the user to confirm
; that the computer is a laptop if a devices is found
; with any of the following text fragments in its description.

[PotentialLaptopDeviceDescriptions]
;
CARD BUS=
CARD SERVICES=
CARDBUS=
CARDSERVICES=
PC CARD=
PCCARD=
PCIC=
PCMCIA=
SOCKET=
DOCK=


This is the code that does the checking:

; Check to see if we are on a laptop system or a desktop system.
; Set some flags for later use...
; We could be an undiagnosed laptop if we have multiple configurations.
; We could be an undiagnosed laptop if we have a configuration name which contains
; one of several particular substrings.
; We could be an undiagnosed laptop if we have a certain type of hardware component
; that has been installed or recognized.

SystemType = ""
ConfigList = ""

ErrorMode(@OFF)
SystemType = RegQueryValue(@REGMACHINE,"Software\Microsoft\Windows\CurrentVersion\FS Templates")
TempKey = RegOpenKey(@REGMACHINE,"Config")
ConfigList = RegQueryKeys(TempKey)
RegCloseKey(TempKey)
Drop(TempKey)
ErrorMode(@CANCEL)

SystemType = StrUpper(SystemType)

for i = 1 to ItemCount(ConfigList,@TAB)
TempConfig = ItemExtract(i,ConfigList,@TAB)
TempConfigName = ""
ErrorMode(@OFF)
TempConfigName = RegQueryValue(@REGMACHINE,"System\CurrentControlSet\Control\IDConfigDB[FriendlyName%TempConfig%]")
ErrorMode(@CANCEL)
for j = 1 to ItemCount(PotentialConfigList,@TAB)
PotentialConfigName = ItemExtract(j,PotentialConfigList,@TAB)
if (StrIndexNc(TempConfigName,PotentialConfigName,0,@FWDSCAN) > 0) then MaybeLaptopFlag = @TRUE
next
next

Drop(ConfigList,TempConfig,TempConfigName)

if (RegExistKey(@REGMACHINE,"Enum\PCMCIA"))
MaybeLaptopFlag = @TRUE
endif

ErrorMode(@OFF)
TempKey = RegOpenKey(@REGMACHINE,"Enum\PCI")
PCIList1 = RegQueryKeys(TempKey)
RegCloseKey(TempKey)
Drop(TempKey)
ErrorMode(@CANCEL)

for i = 1 to ItemCount(PCIList1,@TAB)
TempKeyName1 = StrCat("Enum\PCI\",ItemExtract(i,PCIList1,@TAB))
ErrorMode(@OFF)
TempKey = RegOpenKey(@REGMACHINE,TempKeyName1)
PCIList2 = RegQueryKeys(TempKey)
RegCloseKey(TempKey)
Drop(TempKey)
ErrorMode(@CANCEL)
for j = 1 to ItemCount(PCIList2,@TAB)
TempKeyName2 = StrCat(TempKeyName1,"\",ItemExtract(j,PCIList2,@TAB))
ErrorMode(@OFF)
TempDeviceDesc = RegQueryValue(@REGMACHINE,StrCat(TempKeyName2,"[DeviceDesc]"))
ErrorMode(@CANCEL)
for k = 1 to ItemCount(PotentialDeviceList,@TAB)
PotentialDeviceDesc = ItemExtract(k,PotentialDeviceList,@TAB)
if (StrIndexNc(TempDeviceDesc,PotentialDeviceDesc,0,@FWDSCAN) > 0) then MaybeLaptopFlag = @TRUE
next
next
next 


if ((MaybeLaptopFlag) && (SystemType <> "MOBILE"))
Answer = AskYesNo(Title01,"Is your system a Laptop?")
if (Answer == @YES)
RegSetValue(@REGMACHINE,"Software\Microsoft\Windows\CurrentVersion\FS Templates","Mobile")
SystemType = "MOBILE"
endif
endif

if (SystemType == "DESKTOP")
DesktopFlag = @TRUE
LaptopFlag = @FALSE
Display(5,Title01,"You are running on a Desktop system")
else
if (SystemType == "MOBILE")
DesktopFlag = @FALSE
LaptopFlag = @TRUE
Display(5,Title01,"You are running on a Laptop system")
else
DesktopFlag = @FALSE
LaptopFlag = @FALSE
Message(Title01,"You are running on an Unknown system type. This system cannot run the Structure Update Utility.")
exit
endif
endif

And Another User's code to Detect a Laptop:

;*************** Get Windows Version **************************
ErrorMode(@OFF)

s_win_ver = ""

CheckReg = regexistVALUE(@REGMACHINE,"Software\Microsoft\Windows\CurrentVersion[Version]")

IF CheckReg == 0

    checkNT = regexistVALUE(@REGMACHINE, "software\microsoft\windows nt\currentversion[CurrentVersion]")

    IF checkNT == 0
        message("Notice:", "Windows Version not detected!!!")
    ELSE
        NTVersion = regqueryvalue(@regmachine, "Software\Microsoft\Windows nt\currentversion[CurrentVersion]")
        if NTVersion == "5.1" then s_win_ver = "XP Pro"
        if NTVersion == "5.0" then s_win_ver = "2000"
        if NTVersion == "4.0" then s_win_ver = "NT"
    ENDIF
ELSE
    
WindowsVersion = StrTrim(RegQueryValue(@REGMACHINE, "Software\Microsoft\Windows\CurrentVersion[Version]"))

If WindowsVersion == "Windows 98"

    VersionNumber = RegQueryValue(@REGMACHINE,"Software\Microsoft\Windows\CurrentVersion[VersionNumber]")

        IF VersionNumber == "4.10.1998" 
        	s_win_ver = "98"
        ENDIF
        
        IF VersionNumber == "4.10.2222" 
        	s_win_ver = "98SE"
        ENDIF
        
Endif

If WindowsVersion == "Windows Millennium Edition" 
 	s_win_ver = "ME"
Endif

If WindowsVersion == "Windows 95"
	s_win_ver = "95"
Endif

If s_win_ver == "" 
    	Display(10, "Notice:", "%@CRLF%Unable to Determine OS!!!!!!%@CRLF%")
Endif

ENDIF

ErrorMode(@CANCEL)


pc_type = "DESKTOP"			;Initialize PC Type default as Desktop

If (s_win_ver == "XP Pro")
	IF RegExistKey(@REGMACHINE, "SYSTEM\CurrentControlSet\Enum\PCMCIA")
		pc_type = "LAPTOP"
	ENDIF
Endif

If (s_win_ver == "2000")
	IF RegExistKey(@REGMACHINE, "SYSTEM\CurrentControlSet\Services\PCMCIA\Enum")
		pc_type = "LAPTOP"
	ENDIF
Endif

If (s_win_ver == "NT")
	IF RegExistKey(@REGMACHINE, "SYSTEM\CurrentControlSet\Services\PCMCIA\Enum")	
		pc_type="LAPTOP"
	ENDIF
Endif

If (s_win_ver == "95") || (s_win_ver == "98") || (s_win_ver == "98SE") || (s_win_ver == "ME")

	IF RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\Class\PCMCIA\0000") || RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\Class\PCMCIA\0001") 
		pc_type = "LAPTOP"
	ENDIF
	
	IF RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\Class\PCMCIA\0002") || RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\Class\PCMCIA\0003") 
		pc_type = "LAPTOP"
	ENDIF
	
	IF RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\Class\PCMCIA\0004") || RegExistKey(@REGMACHINE, "System\CurrentControlSet\Services\Class\PCMCIA\0005") 
		pc_type = "LAPTOP"
	ENDIF
Endif



Article ID:   W13145
Filename:   Detect a Laptop.txt
File Created: 2002:08:09:10:58:28
Last Updated: 2002:08:09:10:58:28