If you have ever sequenced an application using Microsoft App-V, then you should be aware that there are a few tasks that must be performed to the machine prior to sequencing. These include: creating a dummy printer, creating dummy ODBC’s, and stopping all unnecessary services. In an effort to automate these tasks, I have written a script for each one.

(Note: If you are using App-V 4.6 SP1 you no longer need to create the dummy ODBC’s. They are now created for you during the sequencer install process.)

Stop Services Script

Before you can sequence an application it is recommended that you stop all unnecessary services. These services include: Windows Defender, Windows Search, SMS Agent Host, Windows Update, Disk Defragmenter, Windows Media Player, and Windows Firewall. The script below will stop all of these with one click. (well, maybe two if you have UAC enabled)

 


On Error Resume Next

StopSrv("WinDefend") ‘Windows Defender
StopSrv("WSearch") ‘Windows Search
StopSrv("ccmexec") ‘SMS Agent Host
StopSrv("wuauserv") ‘Windows Update
StopSrv("defragsvc") ‘Disk Defragmenter
StopSrv("WMPNetworkSvc") ‘Windows Media Player Network Sharing Service
StopSrv("MpsSvc") ‘Windows Firewall

WScript.Echo "Done"

Sub StopSrv(srvName)
Set objWMIService = GetObject("winmgmts:" &_
    "{impersonationLevel=Impersonate}!\\.\root\cimv2:Win32_Service.Name=’"_
    & srvName & "’")
objWMIService.StopService
objWMIService.ChangeStartMode("Manual")
End Sub


If you would like to add any services to this script just add another call to StopSrv and enter the service’s name.

Dummy Printer Script

The script below can be used to create a dummy printer. It uses the HP LaserJet 2300L PS driver which is built in to Windows 7. This can be changed to any driver you prefer by changing the DriverName value.


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

Set colPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = "HP LaserJet 2300L PS"
objPrinter.PortName   = "LPT1:"
objPrinter.DeviceID   = "Dummy"
objPrinter.Put_

WScript.Echo "Done"


Dummy ODBC Script

The script below will create both a system and user ODBC.


Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
 
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")
‘Create System ODBC
‘Create data source
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = "Dummy"
strValue = "SQL Server"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
‘Create ODBC
objReg.SetStringValue_ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strKeyPath =
"SOFTWARE\ODBC\ODBC.INI\Dummy"
objReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
‘Set description
strValueName = "Description"
strValue = "ODBC for App-v Sequencing"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
‘Set driver
strValueName = "Driver"
strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
‘Set server
strValueName = "Server"
strValue = "Dummy"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
‘Set security
strValueName = "Trusted_Connection"
strValue = "Yes"
objReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

‘Create User ODBC
‘Create data source
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources"
strValueName = "Dummy"
strValue = "SQL Server"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
‘Create ODBC
objReg.SetStringValue_ HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
strKeyPath =
"SOFTWARE\ODBC\ODBC.INI\Dummy"
objReg.CreateKey HKEY_CURRENT_USER,strKeyPath
‘Set description
strValueName = "Description"
strValue = "ODBC for App-v Sequencing"
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
‘Set driver
strValueName = "Driver"
strValue = "C:\WINDOWS\System32\SQLSRV32.dll"
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
‘Set server
strValueName = "Server"
strValue = "Dummy"
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
‘Set security
strValueName = "Trusted_Connection"
strValue = "Yes"
objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue