Another Registry Script…

I have the unfortunate need to occasionally fix things in the registry, mostly related to applications running in a Citrix environment.  I believe there are nice tools out there that are supposed to do this for you, if given the right information, but I haven’t bothered to figure out what those tools are or how to use them.  Instead, I torture myself with trying to muddle through VBScript and make it do what I want. 

In that spirit, I am going to show you one of my pitiful scripts (and this one is horrible, because I didn’t bother to clean it up after I worked out how to make it accomplish the desired goal.  So… here you go:

‘==========================================================================

‘ VBScript Source File — Created with SAPIEN Technologies PrimalScript 2007

‘ NAME: BorlandDBPathFix.vbs

‘ AUTHOR: Michael Phillips , Brasfield & Gorrie, LLC
‘ DATE : March 11, 2009

‘ COMMENT: This script is to change the value of 2 registry keys on a per
‘ user basis. It should set the value to be the correct system
‘ drive (c: or u:).
‘ It should also be noted that this script isn’t very pretty.
‘==========================================================================
‘Registry stuff
Const HKCU = &H80000001 ‘This defines the Current User Hive
Const HKLM = &H80000002 ‘This defines the Local Machine Hive
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
vDebug = 1
Dim strComputer

strComputer = “.” ‘This computer is the “.”. If you want another computer, replace the .

Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\default:StdRegProv”)

sGetPath
Sub sGetPath
Set oShell = CreateObject( “WScript.Shell” )
strSystemDrive = oShell.ExpandEnvironmentStrings(“%systemdrive%”)
‘* wscript.echo strSystemDrive
fGetRegistryValues strSystemDrive
End Sub

‘*
‘* This is what we are looking for:
‘* [HKCU\Software\Borland\BDS\4.0\DBExpress]
‘* @=””
‘* “Connection Registry File”=”C:\\Program Files\\Common Files\\Borland Shared\\DBExpress\\dbxconnections.ini”
‘* “Driver Registry File”=”C:\\Program Files\\Common Files\\Borland Shared\\DBExpress\\dbxdrivers.ini”
Function fGetRegistryValues (vSystemDrive)
‘* wscript.echo vSystemDrive & ” is being passed as vSystemDrive”
oReg.GetExpandedStringValue HKCU,”Software\Borland\BDS\4.0\DBExpress”,”Connection Registry File”,strValue1
oReg.GetExpandedStringValue HKCU,”Software\Borland\BDS\4.0\DBExpress”,”Driver Registry File”,strValue2
strDriveLetter1 = Left (strValue1,2)
‘* wscript.echo strDriveLetter1 & strValue1 & strSystemDrive
strDriveLetter2 = Left (strValue2,2)
If strDriveLetter1 = vSystemDrive Then
If strDriveLetter2 = vSystemDrive Then
Else
fSetRegistryValues strValue1,strValue2,vSystemDrive

End If
Else
fSetRegistryValues strValue1,strValue2,vSystemDrive
End If
End Function
Function fSetRegistryValues (fValue1,fValue2,fDriveLetter)
‘* wscript.echo “Bad Letter is being passed ” & fValue1 & fValue2 & fDriveLetter
vLength1 = (Len (fValue1))-2
vLength2 = (Len (fValue2))-2
‘* wscript.echo “–strValue1 & vLength1– >” & fValue1 & ” ” & vLength1
strPathNoLetter1 = Right (fValue1,vLength1)
strNewKeyValue1 = fDriveLetter & strPathNoLetter1
fWriteStringRegistryValues “Software\Borland\BDS\4.0\DBExpress”,”Connection Registry File”,strNewKeyValue1
‘* wscript.echo strNewKeyValue1

strPathNoLetter2 = Right (fValue2,vLength2)
strNewKeyValue2 = fDriveLetter & strPathNoLetter2
fWriteStringRegistryValues “Software\Borland\BDS\4.0\DBExpress”,”Driver Registry File”,strNewKeyValue2
‘* wscript.echo (fDriveLetter & (Right (fValue2,vLength2)))
End Function

Function fWriteStringRegistryValues (fvRegistryKeyPath,fvRegistryKeyName,fvRegistryKeyValue)
If vDebug = 1 Then
‘* wscript.echo “Begining Function -fWriteStringRegistryValues-.”
End If
‘ This function takes input to write string values to the registry. Key must already exist.
oReg.SetStringValue HKCU,fvRegistryKeyPath,fvRegistryKeyName,fvRegistryKeyValue
End Function

Leave a Reply