Showing posts with label vbscript. Show all posts
Showing posts with label vbscript. Show all posts

Tuesday, January 25, 2011

Microsoft Office - Disabling AutoFormat "Internet and network paths with hyperlinks" option through the registry.



Recently, at my place of business, I had to find an automatic way of disabling the "Internet and network paths with hyperlinks" option in Outlook 2007.  I wish it was as simple as setting a registry setting from "1" to "0" but it was a little beyond that.  The following vbscript is what was written and pushed out to our users through group policy:

' Constants used in this script
Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const ToggleAutoFormat = &H00000010 ' Auto Format flag
Const ToggleAutoFormatInv = &H11111101 ' Auto Format flag inverse
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Office\12.0\Word\Data"
strValueName = "SettingsWordMail"
' Get the binary value in question
oReg.GetBinaryValue HKCU, strKeyPath, strValueName, strValue
bitLocation = -1
' If this setting was not found, early out
if IsNull( strValue ) then
    WScript.Quit
end if
' go through the binary data and find our current setting
For i = lBound(strValue) to uBound(strValue) - 4
    'StdOut.Write "(" & i & ")" & strValue(i) & "|"
    'StdOut.Write strValue(i) & "|"
    if strValue(i) = 135 and strValue(i + 1) = 255 and strValue(i + 2) = 255 then
        'StdOut.Write "Found the troubled bit at " & (i + 3) & ": " & strValue(i + 3)
        bitLocation = i + 3
    end if
Next
' Did not find the bit we are looking for, early out
if bitLocation = -1 then
    WScript.Quit
end if
' Set the bit to off
newBit = strValue(bitLocation) And ToggleAutoFormatInv
' Write the new value into the registry only if this setting is toggled on
if newBit <> strValue(bitLocation) then
    strValue(bitLocation) = newBit
   
    ' Write the value back to the registry
    oReg.SetBinaryValue HKCU, strKeyPath, strValueName, strValue
end if