Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd Logon Script Side Effect

Status
Not open for further replies.

jmbrixey

Technical User
May 27, 2008
4
US
I am working on a logon script (GPO) that checks for an Outlook Profile, if one exists/does not exist, it either creates a registry key or exits the instruction loop. Both cases create a log event with a descriptive text entry. If the script is executed standalone (just run from command line or from windows explorer) it works normally. If executed via a logon script (standard GPO) it works, but it creates like 10 duplicate entries in the event log. I have never seen this before and thought I would put out some feelers to see if anyone has and found the solution for it.

Code:
Const HKLM = &H80000002
            Const HKCU = &H80000001
            Const Event_Information = 4
            
            strComputer = "."
            Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
            Set objShell = wscript.CreateObject("wscript.Shell")
            Set wshNetwork = CreateObject("wscript.Network")
            
            strOfficeKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
            strEntry1a = "DisplayName"
            objReg.EnumKey HKLM, strOfficeKey, arrSubkeys
            
            strProfilePath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"

            'set variables to search the current user profile to see if a mail profile has been created
            strProfileValueName = "DefaultProfile"
            objReg.GetStringValue HKCU, strProfilePath, strProfileValueName, strValue

            'set variables to remove the first-run value if there is no mail profile
            strDeleteValuePath = "Software\Microsoft\Office\12.0\Outlook\Setup"
            strDeleteValue = "First-Run"
            strNewValueName = "ImportPRF"
            strNewValue = "\\<sourcefilelocation>\Office2007Pro\outlook.prf"

            'check uninstaller repository for the correct version of Office
            For Each strSubkey In arrSubkeys
                intRet1 = objReg.GetStringValue(HKLM, strOfficeKey & strSubkey, strEntry1a, strValue1)
                If intRet1 <> 0 Then
                    objReg.GetStringValue HKLM, strOfficeKey & strSubkey, strEntry1b, strValue1
                End If
                
                'If Office 2007 is found, install the registry keys needed for Outlook profiles
                If strValue1 <> "" and strValue1 = "Microsoft Office Professional Plus 2007" Then 
                    'get the current logged on user
                    strUser = wshNetwork.Username
                                
                    If isNull(strValue) Then
                        'import office prf routine here
                        objReg.DeleteValue HKCU, strDeleteValuePath, strDeleteValue
                        objReg.SetStringValue HKCU, strDeleteValuePath, strNewValueName, strNewValue
                        objShell.LogEvent Event_Information, "Outlook configuration file imported for user: " & strUser
                    Else
                        objShell.LogEvent Event_Information, "Outlook profile already exists for user: " & strUser & ". Office will install normally."
                    End If
                Else
                    'make the registry key manually before Office 2007 is installed
                    objReg.CreateKey HKCU, strDeleteValuePath
                    objReg.SetStringValue HKCU, strDeleteValuePath, strNewValueName, strNewValue
                    objShell.LogEvent Event_Information, "Office 2007 not installed, outlook configuration file path entered into registry" 
                End If
            Next
 
Sounds like a GPO problem. If the same GPO applies to the user multiple times, then the script may run multiple times during the logon process.

Run a GPResult on a workstation that is having a problem to find the culprit.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
If intRet1 <> 0 Then
objReg.GetStringValue HKLM, strOfficeKey & strSubkey, [red]strEntry1b[/red], strValue1
End If

I don't see where you are setting strEntry1b. Shouldn't this be strEntry1a?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark,

Thanks for pointing that out. It should have been as you suggested. Although that was not the cause. It was my actions within the loop of the key array. I neglected to exit the For...Next loop once the correct key was found. Because the values I was testing for (strValue1) would always be the same, every installed product would test as true a log entry would be created. Placing an exit for statement after creating the log entry appears to resolve the problem. Will continue to test further. (Although why when testing standalone it did not seem to add the multiple entries I have not determined.)

Below is the revised, will post back with results from testing.

Code:
	<job id="OutlookProfileCheck">
		<comment>
            Purpose: To allow the installation of Office 2007 via GPO and automating the Outlook profile creation.
            reference [URL unfurl="true"]http://www.microsoft.com/technet/scriptcenter/scripts/os/registry/osrgvb04.mspx[/URL]
            reference [URL unfurl="true"]http://support.microsoft.com/kb/252304[/URL]
            reference [URL unfurl="true"]http://www.microsoft.com/technet/scriptcenter/scripts/logs/eventlog/lgevvb19.mspx[/URL]
		</comment>
		<script language="VBScript">        
            Const HKLM = &H80000002
            Const HKCU = &H80000001
            Const Event_Information = 4            
            strComputer = "."
            Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
            Set objShell = wscript.CreateObject("wscript.Shell")
            Set wshNetwork = CreateObject("wscript.Network")
            
            'set variables to search the current user profile to see if a mail profile has been created
            strProfilePath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
            strProfileValueName = "DefaultProfile"
            objReg.GetStringValue HKCU, strProfilePath, strProfileValueName, strValue

            'set variables to remove the first-run value if there is no mail profile
            strDeleteValuePath = "Software\Microsoft\Office\12.0\Outlook\Setup"
            strDeleteValue = "First-Run"
            strNewValueName = "ImportPRF"
            strNewValue = "[i]<application source>[/i]\Office2007Pro\outlook.prf"

            'check uninstaller repository for the correct version of Office
            strInstalledProduct = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
            strEntry1a = "DisplayName"
            objReg.EnumKey HKLM, strOfficeKey, arrSubkeys  
            
            For Each strSubkey In arrSubkeys
                'get the display name for the subkey
                intRegKey = objReg.GetStringValue(HKLM, strInstalledProduct & strSubkey, strEntry1a, strValue1)
                
                'check to make sure there is a display name for the installed software
                If intRegKey <> 0 Then
                    objReg.GetStringValue HKLM, strInstalledProduct & strSubkey, strEntry1a, strValue1
                End If
                
                'get the current logged on user
                strUser = wshNetwork.Username
                
                'Make a check to ensure not an empty string and if Office 2007 is found, install the registry keys needed for Outlook profiles
                If strValue1 <> "" and strValue1 = "Microsoft Office Professional Plus 2007" Then                             
                    If isNull(strValue) Then
                        'import office prf routine here
                        objReg.DeleteValue HKCU, strDeleteValuePath, strDeleteValue
                        objReg.SetStringValue HKCU, strDeleteValuePath, strNewValueName, strNewValue
                        objShell.LogEvent Event_Information, "Outlook 2007 configuration file path imported for user: " & strUser
                        Exit For
                    Else
                        objShell.LogEvent Event_Information, "Outlook profile exists for user: " & strUser & ". Office 2007 will migrate normally."
                        Exit For
                    End If
                ElseIf strValue1 <> "" and strValue1 <> "Microsoft Office Professional Plus 2007" Then
                    'If an Outlook profile exists, but Office 2007 is not installed make event viewer entry
                    If strValue <> "" Then
                        objShell.LogEvent Event_Information, "Office 2007 not installed, but Outlook profile exists for user: " & strUser & ". Office 2007 installation will migrate normally."
                        Exit For
                    Else
                        'make the registry key manually before Office 2007 is installed
                        objReg.CreateKey HKCU, strDeleteValuePath
                        objReg.SetStringValue HKCU, strDeleteValuePath, strNewValueName, strNewValue
                        objShell.LogEvent Event_Information, "Office 2007 not installed and no Outlook profile exists for user: " & strUser & ". Outlook configuration file path entered into registry"
                        Exit For
                    End If
                End If
            Next
		</script>
	</job>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top