23
Nov
Nov
Let’s start this blog off with quite a nice script. I needed this script during a project, because we needed to (pre)create Software Metering Rules in SCCM. We wanted to be able to start with the metering right from the start of the new SCCM implementation.
To do that the best as possible we decided to ‘read’ all the the executables from the available software in the Software Repository. All these applications were msi based and msi’s contain some sort of database which can be read. This allowed us to get all the executables from all the software and make a nice predefined inventory.
Below is the script which I created along with a colleague of mine.
get_exe_from_msi.vbs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ''''''''''''''''''''''''''''''''''''''''''''''''''''' ' AUTHOR : http://www.hican.net - @hicannet ' DATE : 12-10-2011 ' COMMENT : This script retrieves all the executables ' from the msi's in a specified folder. ''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit Const msiOpenDBReadOnly = 0 Const ForWriting = 2 Const ForReading = 1 Const ForAppending = 8 Dim Installer, Database, View, Record, Subfolder Dim objFolder, colFiles, objFile, objStartFolder Dim objFSO, WshShell Set Installer = Nothing Set WshShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set Installer = Wscript.CreateObject("WindowsInstaller.Installer") objStartFolder = "<DRIVE>:\<BASEFOLDER>" getMSI() Function getMSI() Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files For Each objFile in colFiles If LCase(Right(objFile.Name,3)) = LCase("msi") Then End If Next ShowSubfolders(objFSO.GetFolder(objStartFolder)) End Function Function ShowSubFolders(Folder) For Each Subfolder in Folder.SubFolders Set objFolder = objFSO.GetFolder(Subfolder.Path) Set colFiles = objFolder.Files For Each objFile in colFiles If LCase(Right(objFile.Name,3)) = LCase("msi") Then Set Database = Installer.OpenDatabase(Subfolder.Path & "\" & _ objFile.Name, msiOpenDBReadOnly) Set View = Database.OpenView("SELECT FileName FROM File") 'OUTPUT TO LOGFILE : VbCrLf & Subfolder.Path View.Execute Do Set Record = View.Fetch If Record Is Nothing Then Exit Do If LCase(Right(Record.StringData(1),3)) = LCase("exe") Then 'OUTPUT TO LOGFILE : Record.StringData(1) End If Loop Set View = Nothing End If Next ShowSubFolders(Subfolder) Next End Function |