Change the Class Context Case

Description:

This script will change the Class context case. For example, Inprocserver32 is replaced by InprocServer32.

Usage

CScript.exe {Script} {MSI} {Transform 1} {Transform 2} {Transform x..} (or if transform ordering is not important, drag an MSI and multiple MSTs onto the VBS file)

Script

'set up log file
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'create a name/path for log file
Dim MSIPath : Set MSIPath = fso.GetFile(WScript.Arguments(0))  
Dim logFile : logFile = Left(MSIPath.Path, InStrRev(MSIPath.Path, ".") - 1) & ".log"
Dim objLogFile : Set objLogFile = fso.OpenTextFile(logFile, ForAppending, True)
WriteLog "Modifying Context Case"
WriteLog "Processing: " & MSIPath.Name
'create 2 constants - one for when we want to just query the MSI (read) and one for when we want to make changes (write)
Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
Const msiViewModifyReplace = 4
'create WindowsInstaller.Installer object
Dim oInstaller : Set oInstaller = CreateObject("WindowsInstaller.Installer")
'open the MSI (the first argument supplied to the vbscript)
Dim oDatabase : Set oDatabase = oInstaller.OpenDatabase(WScript.Arguments(0),msiOpenDatabaseModeTransact) 
Dim tempKey : tempKey = ""
Dim currentContext : currentContext = ""
Dim tempKeyArray, tableView, tableRec, originalValue, tempValue
If oDatabase.TablePersistent("Registry") = 1 Then
Set Tableview = oDatabase.OpenView("SELECT `Key` FROM `Registry`")
Tableview.Execute
Set TableRec = Tableview.Fetch
While Not TableRec Is Nothing
originalValue = TableRec.StringData(1)
tempValue = originalValue
If (InStr(1,tempValue,"inprocserver",1) > 0) And Not (InStr(1,tempValue,"InprocServer",0) > 0) _
Or (InStr(1,tempValue,"inprochandler",1) > 0) And Not (InStr(1,tempValue,"InprocHandler",0) > 0) _
Or (InStr(1,tempValue,"localserver",1) > 0) And Not (InStr(1,tempValue,"LocalServer",0) > 0) _
Or (InStr(1,tempValue,"toolboxbitmap",1) > 0) And Not (InStr(1,tempValue,"ToolBoxBitmap",0) > 0) Then
tempValue = Replace(tempValue,"inprocserver","InprocServer",1,-1,1)											
tempValue = Replace(tempValue,"inprochandler","InprocHandler",1,-1,1)
tempValue = Replace(tempValue,"localserver","LocalServer",1,-1,1)
tempValue = Replace(tempValue,"toolboxbitmap","ToolBoxBitmap",1,-1,1)
TableRec.StringData(1) = tempValue
Tableview.Modify msiViewModifyReplace, TableRec
WriteLog "Modifying Registry Key: " & originalValue & " and changing to: " & tempValue								
End If	
Set TableRec = Tableview.Fetch
Wend
End If
If oDatabase.TablePersistent("Class") = 1 Then
Set Tableview = oDatabase.OpenView("SELECT `Context` FROM `Class`")
Tableview.Execute
Set TableRec = Tableview.Fetch
While Not TableRec Is Nothing
originalValue = TableRec.StringData(1)
tempValue = originalValue
If (InStr(1,tempValue,"inprocserver",1) > 0) And Not (InStr(1,tempValue,"InprocServer",0) > 0) _
Or (InStr(1,tempValue,"inprochandler",1) > 0) And Not (InStr(1,tempValue,"InprocHandler",0) > 0) _
Or (InStr(1,tempValue,"localserver",1) > 0) And Not (InStr(1,tempValue,"LocalServer",0) > 0) _
Or (InStr(1,tempValue,"toolboxbitmap",1) > 0) And Not (InStr(1,tempValue,"ToolBoxBitmap",0) > 0) Then
tempValue = Replace(tempValue,"inprocserver","InprocServer",1,-1,1)											
tempValue = Replace(tempValue,"inprochandler","InprocHandler",1,-1,1)
tempValue = Replace(tempValue,"localserver","LocalServer",1,-1,1)
tempValue = Replace(tempValue,"toolboxbitmap","ToolBoxBitmap",1,-1,1)
TableRec.StringData(1) = tempValue
Tableview.Modify msiViewModifyReplace, TableRec	
WriteLog "Modifying Class Context: " & originalValue & " and changing to: " & tempValue			
End If				     			
Set TableRec = Tableview.Fetch
Wend
End If
oDatabase.Commit	
objLogFile.Close
Set fso = Nothing
Set objLogFile = Nothing	
Set oDatabase = Nothing
Set oInstaller = Nothing
Sub WriteLog(LogMessage)
WScript.echo Now() & ": " & LogMessage
objLogFile.Writeline(Now() & ": " & LogMessage)
End Sub