Is this a laptop or Pc? (detection)
Posted: Sun Aug 02, 2009 4:20 pm
Can somebody detect the Application is runed in a pc or laptop?
easiest way please
easiest way please
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
XIncludeFile "COMate.pbi"
Procedure CompSystem_Info()
Define.COMateObject objWMIService, CompSysInfo
colCompSysInfo.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colCompSysInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_ComputerSystem')")
If colCompSysInfo
CompSysInfo = colCompSysInfo\GetNextObject()
While CompSysInfo
Select CompSysInfo\GetIntegerProperty("PCSystemType")
Case 0
COMSYS_PCSystemType$ = "Unspecified"
Case 1
COMSYS_PCSystemType$ = "Desktop"
Case 2
COMSYS_PCSystemType$ = "Mobile" ; laptop
Case 3
COMSYS_PCSystemType$ = "Workstation"
Case 4
COMSYS_PCSystemType$ = "Enterprise Server"
Case 5
COMSYS_PCSystemType$ = "Small Office and Home Office (SOHO) Server"
Case 6
COMSYS_PCSystemType$ = "Appliance PC"
Case 7
COMSYS_PCSystemType$ = "Performance Server"
Case 8
COMSYS_PCSystemType$ = "Maximum"
Default
COMSYS_PCSystemType$ = "Unknown or Unspecified"
EndSelect
CompSysInfo\Release()
CompSysInfo = colCompSysInfo\GetNextObject()
Wend
colCompSysInfo\Release()
EndIf
objWMIService\Release()
Else
MessageRequester("Error", "COMSYSInfo")
EndIf
Debug COMSYS_PCSystemType$ ; if "Mobile" then is laptop most likely
EndProcedure
Code: Select all
battery.SYSTEM_POWER_STATUS
GetSystemPowerStatus_(@battery)
If battery\BatteryFlag = 128
Debug "This is either a laptop or the system is running on a UPS"
Else
Debug "Not a laptop"
EndIf
or.... use the below if:endif
If battery\BatteryFlag = -128 ; desltops return -128
Debug "Not a laptop"
Else
Debug "This is either a laptop or the system is running on a UPS"
EndIf
Code: Select all
If battery\BatteryFlag = -128 ; desltops return -128
Debug "Not a laptop"
Else
Debug "This is either a laptop or the system is running on a UPS"
EndIfCode: Select all
lRetVal.i
sRemMachName.s
lTopLevelKey.i
lHKeyhandle.i
sKeyName.s
lhkey.i
sValueName.s
vValue.s
msg.s ;
#ERROR_NONE = 0
Procedure.l QueryValueEx(lhkey.i, szValueName.s)
Define.l cch, lrc, lType, lValue
Define.s sValue
Shared vValue
cch = 255
sValue = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
If lrc = #ERROR_NONE
vValue = Left(sValue, cch-1)
Else
vValue = "Empty"
EndIf
ProcedureReturn lrc
EndProcedure
lTopLevelKey = #HKEY_LOCAL_MACHINE
sRemMachName = ""
sKeyName = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
sValueName = "ProcessorNameString"
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0
MessageRequester("CPU Name",vValue,#MB_ICONINFORMATION)
Else
msg = "An Error occured, Return value = " + Str(lRetVal)
MessageRequester("Error",msg, #MB_ICONERROR)
EndIf
M=Mobile?Laptop wrote:---------------------------
CPU Name
---------------------------
Intel(R) Celeron(R) M processor 1.60GHz
---------------------------
OK
---------------------------
or change to this:RASHAD wrote:Run as Administrator
Code: Select all
lRetVal.i
sRemMachName.s
lTopLevelKey.i
lHKeyhandle.i
sKeyName.s
lhkey.i
sValueName.s
vValue.s
msg.s ;
#ERROR_NONE = 0
Procedure.l QueryValueEx(lhkey.i, szValueName.s)
Define.l cch, lrc, lType, lValue
Define.s sValue
Shared vValue
cch = 255
sValue = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
If lrc = #ERROR_NONE
vValue = Left(sValue, cch - 1)
Else
vValue = "Empty"
EndIf
ProcedureReturn lrc
EndProcedure
lTopLevelKey = #HKEY_LOCAL_MACHINE
sRemMachName = ""
sKeyName = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
sValueName = "ProcessorNameString"
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_READ, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0
MessageRequester("CPU Name", vValue, #MB_ICONINFORMATION)
Else
msg = "An Error occured, Return value = " + Str(lRetVal)
MessageRequester("Error", msg, #MB_ICONERROR)
EndIf