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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enabling Win32_product on windows 2003 servers by VBScript

Status
Not open for further replies.
May 20, 2011
1
ES
Hi All,
I have been faced with enabling Win32_product WMI MSI functionality and having written a script to do it i'd thought i'd share it to save the next guy from having to write one...

Here it is

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2011
'
' NAME: enableWMIMSI
'
' AUTHOR: GrabASalad
' DATE : 19/05/2011
'
' COMMENT: this is to enable the wmi msi on the local host so we can audit it.
'
'==========================================================================
Dim strFile1, strFile2, strFile3, strFile4, strFolder1
strFile1 = "MSI.MFL"
strFile2 = "MSI.MOF"
strFile3 = "MSIPROV.DLL"
strFile4 = "answerfile.txt"
strFolder1 = "C:\WMIInstall"

If isWindows2003 Then
If Not FolderExists(strFolder1) Then
CreateFolder(strFolder1)
End If
writeAnswerFile(strFolder1& "\" & strFile4)
ExtractFile(strFile1)
ExtractFile(strFile2)
ExtractFile(strFile3)
registerDLL
execInstall
End If

Function isWindows2003
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Dim colResults, objResult, strWMIQuery
strWMIQuery = "SELECT * FROM win32_operatingsystem"
Set colResults = objWMI.ExecQuery(strWMIQuery)
For Each OS In colResults
If InStr(1,OS.Caption,"2003")> 0 Then
isWindows2003 = True
Else
isWindows2003 = False
End If
Next

End Function

Function Architecture 'Gets the archetecture of the machine x86 or X64
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Dim colResults, objResult, strWMIQuery
strWMIQuery = "SELECT * FROM win32_computersystem"
Set colResults = objWMI.ExecQuery(strWMIQuery)
For Each CS In colResults
If InStr (1,Ucase(CS.SystemType),"X86") > 0 Then
Architecture = "i386"
Else
Architecture = "AMD64"
End If
Next
End Function

Function instLocation
Dim objShell,strRegvalue, strValue
Set objShell = CreateObject("WScript.Shell")
strRegvalue = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\SourcePath"
instLocation = replace(objShell.RegRead(strRegvalue),"\\","\")
End Function

Function isAllreadyEnabled
Set objWMIService = GetObject("winmgmts://." )
Set colWMI=objWMIService.ExecQuery("Select * from Win32_Product")
On Error Resume Next
intCount = colWMI.Count
If Err.Number = 0 Then
isAllreadyEnabled = True
Else
isAllreadyEnabled = False
End If
End Function

Function ExtractFile(sourcefile)
If Not FileExists(sourceFile) Then
strcmd = "cmd /c expand " & instLocation & "\" & Architecture & "\" & left(sourceFile,Len(sourcefile)-1) & "_ " & systemDirectory & "\WBEM\" & sourcefile
Set objShell=CreateObject("WScript.Shell")
Set objExec=objShell.Exec(strCmd)
Do While objExec.StdOut.AtEndOfStream <> True
strResults= objExec.StdOut.ReadAll
Loop
WScript.Echo strResults
End If
End Function

Function systemDirectory
Set objWMIService = GetObject("winmgmts://." )
Set objWMIService = GetObject("winmgmts://." )
Dim colResults, objResult, strWMIQuery
strWMIQuery = "SELECT * FROM win32_operatingsystem"
Set colResults = objWMIService.ExecQuery(strWMIQuery)
For Each OS In colResults
systemDirectory = OS.SystemDirectory
Next
End Function

Function windowsDirectory
Set objWMIService = GetObject("winmgmts://." )
Dim colResults, objResult, strWMIQuery
strWMIQuery = "SELECT * FROM win32_operatingsystem"
Set colResults = objWMI.ExecQuery(strWMIQuery)
For Each OS In colResults
windowsDirectory = OS.WindowsDirectory
Next
End Function

Function writeAnswerFile(strFilePath)
Dim objFSO, objTS
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.CreateTextFile(strFilePath, True)
objTS.WriteLine "[Components]"
objTS.WriteLine "WbemMSI = On"
objTS.Close
End Function

Function execInstall
strcmd="cmd /c Sysocmgr /i:\c:\windows\inf\sysoc.inf /r /u:c:\WMIInstall\AnswerFile.txt > c:\WMIInstall\install.txt"
Set objShell=CreateObject("WScript.Shell")
Set objExec=objShell.Exec(strCmd)
Do While objExec.StdOut.AtEndOfStream <> True
strResults= objExec.StdOut.ReadAll
Loop
WScript.Echo strResults
End Function

Function CreateFolder(strFolderPath)
If Not FolderExists(strFolderPath) Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
WScript.Echo strFolderPath
objFSO.CreateFolder(strFolderPath)
End If
End Function

Function FolderExists(strFolderPath)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strFolderPath) Then
FolderExists = True
Else
FolderExists = False
End If
End Function

Function registerDLL
strcmd="regsvr32 /s " & systemDirectory &"\WBEM\msiprov.dll"
Set objShell=CreateObject("WScript.Shell")
Set objExec=objShell.Exec(strCmd)
Do While objExec.StdOut.AtEndOfStream <> True
strResults= objExec.StdOut.ReadAll
Loop
WScript.Echo strResults
End Function

Function FileExists(strFileName)
Dim objCheckFSO, objCheckFile
strFilename = systemDirectory & "\WBEM\" & strFilename
Set objCheckFSO = CreateObject("Scripting.FileSystemObject")
FileExists = objCheckFSO.FileExists(strFilename)
End function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top