Jump to content

Need help debugging a vbscript that installs a program


Recommended Posts

On first login. It checks what type of machine type it is and based on that I would like it to install this program that is proprietary to our organization. Right now I am testing in a virtual machine so that why the script has been modified for use with a Virtual.

I am calling it via the sysprep.

I get the following error

Get the SMBIOS asset tag from the Win32_SystemEnclosure class

Dim objWMI
Set objResults = objWMI.InstancesOf("Win32_SystemEnclosure")


Option Explicit
Dim strComputer, strChassis
Dim objWMIService, objInstance, objResults, objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set objResults = objWMIService.ExecQuery _
("Select * from Win32_SystemEnclosure",,16)

Dim bIsLaptop, bIsDesktop, bIsServer, bIsVirtual, sAssetTag, objShellApp, isRunning

bIsLaptop = false
bIsDesktop = false
bIsServer = false
bIsVirtual = false
For each objInstance in objResults

If objInstance.ChassisTypes(0) = 12 or objInstance.ChassisTypes(0) = 21 then
' Ignore docking stations
Else

If not IsNull(objInstance.SMBIOSAssetTag) then
sAssetTag = Trim(objInstance.SMBIOSAssetTag)
End if
Select Case objInstance.ChassisTypes(0)
Case "2"
bIsVirtual = true
Case "8", "9", "10", "11", "12", "14", "18", "21"
bIsLaptop = true
Case "3", "4", "5", "6", "7", "15", "16"
bIsDesktop = true
Case "23"
bIsServer = true
Case Else
' Do nothing
End Select

End if

Next

If bIsVirtual = true then
Set objShellApp = CreateObject("WScript.Shell")
Set isRunning = objShellApp.Exec("msiexec /i C:\WINDOWS\Clara.msi /passive /norestart")
End if

post-78994-12764457335_thumb.png

Link to comment
Share on other sites


This compiled and ran just fine:

Option Explicit
Dim strComputer, strChassis
Dim objWMIService, objInstance, objResults, objItem
Dim bIsLaptop, bIsDesktop, bIsServer, bIsVirtual, sAssetTag, objShellApp, isRunning
bIsLaptop = False
bIsDesktop = False
bIsServer = False
bIsVirtual = False

RunMeWithCScript()

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set objResults = objWMIService.ExecQuery( _
"SELECT * FROM Win32_SystemEnclosure",,48)

For Each objInstance in objResults
If objInstance.ChassisTypes(0) = 12 or objInstance.ChassisTypes(0) = 21 Then
' Ignore docking stations
Else
If Not IsNull(objInstance.SMBIOSAssetTag) Then
sAssetTag = Trim(objInstance.SMBIOSAssetTag)
End If
Select Case objInstance.ChassisTypes(0)
Case "2"
bIsVirtual = True
Case "8", "9", "10", "11", "12", "14", "18", "21"
bIsLaptop = True
Case "3", "4", "5", "6", "7", "15", "16"
bIsDesktop = True
Case "23"
bIsServer = True
Case Else
' Do nothing
End Select
End If
Next

If bIsVirtual = False Then
Set objShellApp = CreateObject("WScript.Shell")
Set isRunning = objShellApp.Exec("msiexec /i C:\WINDOWS\Clara.msi /passive /norestart")
End If


Sub RunMeWithCScript()
Dim ScriptEngine, engineFolder, Args, arg, scriptName, argString, scriptCommand

ScriptEngine = UCase(Mid(WScript.FullName, InstrRev(WScript.FullName, "\") + 1))
engineFolder = Left(WScript.FullName, InstrRev(WScript.FullName, "\"))
argString = ""
'WScript.Echo ScriptEngine

If ScriptEngine = "WSCRIPT.EXE" Then
Dim Shell
Set Shell = CreateObject("WScript.Shell")
Set Args = WScript.Arguments

For Each arg in Args 'loop though argument array as a collection to rebuild argument string
If InStr(arg, " ") > 0 Then arg = """" & arg & """" 'If the argument contains a space wrap it in double quotes
argString = argString & " " & Arg
Next

'Create a persistent command prompt for the cscript output window and call the script with its original arguments
scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & WScript.ScriptFullName & """" & argString

Shell.Run scriptCommand, , False
WScript.Quit
Else
Exit Sub 'Already Running with Cscript Exit this Subroutine
End If
End Sub

Link to comment
Share on other sites

if this is the first line of the script

Get the SMBIOS asset tag from the Win32_SystemEnclosure class

it should be like this to avoid the error, your missing the comment out '

' Get the SMBIOS asset tag from the Win32_SystemEnclosure class

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...