Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS Help to better detect a laptop using WMI

Status
Not open for further replies.

trytofixalot

Technical User
Jun 28, 2010
8
GB
Hi, I have a script that works(ish) however the code to identify laptops on Dell hardware specifically is failing which i think due to Dell's WMI extensions.
Is there a way to better detect laptops, for example detecting an onboard battery or something ?
I have enclosed my script, would be grateful if someone has any better ideas and would kindly update the script for me.
many thanks.

'*************************************************************************
' ConfigSEP.vbs
' Copyright (c) 2010
'*************************************************************************
'Modified by Users

Option Explicit

dim objWMIService, objOperatingSystem, objItem, objShell, fso
dim colOperatingSystems, colOperatingSystem, colChassis
dim bIsLaptop, file
dim strComputer, strArchitecture, strVersion, strProgramPath, strProgramParams, strRegKey, FileRenameFrom, FileRenameTo, CommandToRun
Dim TaskKillPath, TaskParam, RegValue1, RegValue2, delFile
dim retVal

'bIsLaptop=-1 when true, 0 when false

strRegKey = "HKLM\SOFTWARE\MyCompany\ConfigSEP\SEPFix"

set objShell = createobject("Wscript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")


On Error Resume Next
retVal = objShell.regRead(strRegKey)
If Err.Number <> 0 then
retVal="0"
Err.Clear
End If

On Error Goto 0

'Only run the script if it hasn't been run before
If retVal <> "1" then

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Determine OS version and type
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
strArchitecture = objOperatingSystem.OSArchitecture
strVersion = left(objOperatingSystem.Version,3)
Next

'Determine the chassis type
Set colChassis = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure where tag='System Enclosure 0'")
For each objItem in colChassis
if objItem.ChassisTypes(0) >= 3 or objItem.ChassisTypes(0) <= 7 then
bIsLaptop = False
End If
if objItem.ChassisTypes(0) >= 8 or objItem.ChassisTypes(0) <= 10 then
bIsLaptop = True
End If
Next

'Set the path to the executable
strProgramPath = "\\emea-lon-av\SEP\SylinkDrop\SylinkDrop.exe -silent"

'If strVersion = "6.1" then
'32-bit machines
If strArchitecture = "32-bit" Then
'This file is common to both Laptops and Desktops
FileRenameFrom = "C:\Program Files\Common Files\Symantec Shared\HWID\sephwid.xml"
FileRenameTo = "C:\Program Files\Common Files\Symantec Shared\HWID\sephwid.old"
If bIsLaptop=0 Then
strProgramParams = "\\servername\SEP\Sylink XMF Files\My Company_Canary Wharf_Workstations_32-Bit_sylink.xml"

else
strProgramParams = "\\servername\SEP\Sylink XMF Files\My Company_Canary Wharf_Laptops_32-Bit_sylink.xml"
End If
'64-bit machines
Else
FileRenameFrom = "C:\Program Files (x86)\Common Files\Symantec Shared\HWID\sephwid.xml"
FileRenameTo = "C:\Program Files (x86)\Common Files\Symantec Shared\HWID\sephwid.old"
If bIsLaptop=0 then
strProgramParams = "\\servername\SEP\Sylink XMF Files\My Company_Canary Wharf_Workstations_64-Bit_sylink.xml"

else
strProgramParams = "\\servername\SEP\Sylink XMF Files\My Company_Canary Wharf_Laptops_64-Bit_sylink.xml"

End If
End If
'End If
'We need to stop the SMC.exe process before re-running the SylinkDrop
TaskKillPath = "c:\windows\system32\taskkill.exe"
TaskParam = " /IM smc.exe /F"
retVal = objShell.Run(TaskKillPath & TaskParam, 0, true)
If retVal = "0" Then
'Check if the old file already exists, then delete
If (fso.FileExists(FileRenameTo)) Then Set DelFile = fso.DeleteFile(FileRenameTo, True)
'Now we need to rename the existing xml file
If (fso.FileExists(FileRenameFrom)) Then
set file = fso.GetFile(FileRenameFrom)
file.name = "sephwid.old"
set file = Nothing
End If
'We need to delete the REG Key if it exists
RegValue1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink\ComputerID"
RegValue2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink\HardwareID"
On Error Resume Next
objShell.RegRead(RegValue1)
'Catch the error
Select Case Err
Case 0:
'Error Code 0 = 'success'
objShell.RegDelete(RegValue1)
End Select
On Error Resume Next
objShell.RegRead(RegValue2)
'Catch the error
Select Case Err
Case 0:
'Error Code 0 = 'success'
objShell.RegDelete(RegValue2)
End Select
'Run the command passing in the required parameters
retVal = objShell.Run(strProgramPath & " " & Chr(34) & strProgramParams & Chr(34), 0, true)
If retVal = "0" then
objShell.RegWrite strRegKey, "1", "REG_SZ"
End If
End If
End If

'Remove object reference
set objShell = Nothing
set fso = Nothing
 
I'd replace this:
if objItem.ChassisTypes(0) >= 3 or objItem.ChassisTypes(0) <= 7 then
with this:
if objItem.ChassisTypes(0) >= 3 AND objItem.ChassisTypes(0) <= 7 then

and this:
if objItem.ChassisTypes(0) >= 8 or objItem.ChassisTypes(0) <= 10 then
with this:
if objItem.ChassisTypes(0) >= 8 AND objItem.ChassisTypes(0) <= 10 then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top