Re: gpo scripts
- From: jonesj <jonesj@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 1 Dec 2008 13:10:00 -0800
Well, the way I know they're running, is the fact that i can see the drives
mapped and i can watch outlook configure itself when the new user logs in the
first time. And yes, if the machine is started, newuserA logs in, the scripts
run. is userA logs out and userB logs in, scripts do not run. if workstation
is restarted, userB logs in and the scripts run. It won't matter now however
userA logs in, his profile is already created on the local workstation....the
scripts look for %username% profile. if it finds it, the script stops. if
the profile is not found, the script is supposed to run. here are the 2
scripts in question:
the login script:
'***************************************************
' File: auto_outlook.vbs
' Author: Mark M Manning
' Date: 10/10/2007
' Version: 1
' Based on the work of Peder Pedersen - pep@xxxxxxxx
'***************************************************
'Option Explicit
Dim Company, Exserver, Exserver3, ProfileName, ProfileName3, DomainString,
UserString, objDomain, UserObj, intTest
' =========================================
' ====== EDIT THIS INFORMATION=============
Company = "NorthCharleston" ' SET THE NAME OF YOUR COMPANY
'PRFLocation = "c:\test.prf" ' SET THE LOCATION ON THE NETWORK OR
LOCAL DRIVE
Exserver =
"\\northcharleston\share\install\office03_ent\outlook_exserver.prf" ' OF THE
PRF THAT HAS BEEN CREATE
Exserver3 =
"\\northcharleston\share\install\office03_ent\outlook_exserver3.prf" ' OF THE
PRF THAT HAS BEEN CREATE
ProfileName = "outlook_exserver" ' This is the name that you have already
created when you made the PRF.
ProfileName3 = "outlook_exserver3" ' This is the name that you have
already created when you made the PRF.
' =========================================
' =================DO NOT EDIT ANYTHING BELOW THIS SECTION================
' ========================================================================
intTest = 0
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ObjEnv = WshShell.Environment("Process")
Set objShell = CreateObject("Shell.Application")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
UserString = WSHNetwork.UserName
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
Const HKEY_CURRENT_USER = &H80000001
Dim HKCUfirstRunflag
HKCUfirstRunflag = "HKCU\Software\" & Company & "\FirstRunFlag"
Dim HKCUprofile
For Each GroupObj In UserObj.Groups
Select Case UCase (GroupObj.Name)
Case "Fire","Police","Police_Admin","FireAdmin","FireInsp"
HKCUprofile = "HKCU\Software\Microsoft\Windows
NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & ProfileName
Case Else
HKCUprofile = "HKCU\Software\Microsoft\Windows
NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & ProfileName3
End Select
Next
Dim WshShell, WshNetwork, objEnv, fso, objShell, username, key,
FirstRunCurrentUser, MSOKey, NoProfile, OfficeInstalled, strUserName,
strInitials
Dim strOfficePath, strMachineName, objSysInfo, objUser
Dim objWord, LogonSrv, PRFPath, result, OSnummer, objWMIService,
colOperatingSystems, objOperatingSystem
strOfficePath = "Software\Microsoft\Office\11.0\Common\UserInfo" 'Path for
office user info
strMachineName = "."
' ============== START OF MAIN SCRIPT ==============
'Check OS
' =========================================
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strMachineName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
result = objOperatingSystem.Version
OSnummer = Left(result,3)
if OSnummer <> "5.1" then
'Wscript.Echo "This is not XP" 'Debug
Wscript.Quit
else
'Wscript.Echo OSnummer 'Debug
end if
Next
' =========================================
'Test to see if the script has run before
' =========================================
TestfirstRunUser ' Has script been run before?
If FirstRunCurrentUser then 'If not then continue
TestProfile
If NoProfile then 'Set up profile if none exists
OutlookSetup 'Setup Outlook profile
End if
end if
' =========================================
' Add a registry key if the script runs successfully
WshShell.RegWrite HKCUfirstrunflag, "1", "REG_DWORD"
cleanup
' ================================================
' ============== END OF MAIN SCRIPT ==============
' ================================================
' -------- Test if first run for this user?
Sub TestFirstRunUser
on error resume next 'cannot be read first time
key = WshShell.RegRead(HKCUfirstRunflag)
If Err <> 0 Then
FirstRunCurrentUser = True
Else
FirstRunCurrentUser = False
End If
On Error Goto 0
End Sub
'------------ Test if profile exists?
Sub TestProfile
on error resume next 'cannot be read first time
MSOKey = WshShell.RegRead(HKCUprofile)
' determine if a profile has already been setup
If MSOKey = "" Then
'wscript.echo "No Profile" 'Testing
NoProfile = True
else
'wscript.echo "Profile exists" 'Testing
NoProfile = False
end if
On Error Goto 0
End sub
'------------ Setup username and initials to Office
Sub SetUser
' Currently logged in User
strUserName = objUser.displayName 'Get name of current user
StrInitials = objUser.samaccountname 'Get initials
Set objWord = CreateObject("Word.Application")
objWord.UserName = strUserName
objWord.UserInitials = Ucase(StrInitials)
objWord.Quit
End sub
'------------ Setup prf
Sub OutlookSetup
For Each GroupObj In UserObj.Groups
Select Case UCase (GroupObj.Name)
Case "Fire","Police","Police_Admin","FireAdmin","FireInsp"
intTest = intTest + 1
' WshShell.Run "outlook.exe /importprf " & Exserver, 1, False
' Case Else
' WshShell.Run "outlook.exe /importprf " & Exserver3, 1, False
End Select
Next
wscript.sleep 500
WshShell.RegWrite
"HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserInitials",
objUser.samaccountname, "REG_SZ"
WshShell.RegWrite
"HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserName",
objUser.displayName, "REG_SZ"
If intTest > 0 Then
WshShell.Run "outlook.exe /importprf " & Exserver, 1, False
Else
WshShell.Run "outlook.exe /importprf " & Exserver3, 1, False
End If
End Sub
Sub Cleanup
Set WshNetwork = Nothing
Set objSysInfo = Nothing
Set WshShell = Nothing
Set fso = Nothing
Set ObjEnv = Nothing
Set objShell = Nothing
Set objUser = Nothing
Set objWord = Nothing
Set objWMIService = Nothing
Set colOperatingSystems = Nothing
Set objWord = Nothing
Set UserObj = Nothing
End Sub
=======================================
just some info on my expertise here...I've been thrust into this admin role
and am learning pretty quickly, but scripting is not one of my forte's and
these scripts are common place on the web.
BTW, We run windows server 2003, exchange 2003 in an ad environment. any
other info, just ask. I also have a .prf file on a network share for the
outlook configuration....
Thanks
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
Path, objNetwork, objNetwork1
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships
later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
'Disconnect ALL mapped drives
'Set clDrives = WshNetwork.EnumNetworkDrives
'For i = 0 to clDrives.Count -1 Step 2
'WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
'Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300
'Map drives
'Note the first command uses the user name as a variable to map to a user
share.
WSHNetwork.MapNetworkDrive "g:", "\\northcharleston\" & UserString,True
WSHNetwork.MapNetworkDrive "h:", "\\northcharleston\share",True
'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups
Select Case GroupObj.Name
'Check for group memberships and take needed action
Case "MIS"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\mis",True
Case "Operations"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\oper",True
Case "ARTS"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\arts",True
Case "Building"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\buil",True
Case "Code"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\code",True
Case "Council"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\coun",True
Case "Court"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\court",True
Case "Executive"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\exec",True
Case "Finance"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\fina",True
Case "Legal"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\legal",True
Case "Personnel"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\pers",True
Case "Planning"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\plan",True
Case "Public Works"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\pw",True
Case "Purchasing"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\purcasing",True
Case "Recreation"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\park",True
Case "POLICE"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\police",True
Case "Police_admin"
WSHNetwork.MapNetworkDrive "j:", "\\northcharleston\admin",True
Case "Crime"
WSHNetwork.MapNetworkDrive "m:", "\\northcharleston\crime",True
Case "Internal Affairs"
WSHNetwork.MapNetworkDrive "j:", "\\northcharleston\specialopps",True
Case "Training"
WSHNetwork.MapNetworkDrive "t:", "\\northcharleston\training",True
Case "Victim's Advocate"
WSHNetwork.MapNetworkDrive "j:", "\\northcharleston\vaccsi",True
Case "Fire"
WSHNetwork.MapNetworkDrive "i:", "\\northcharleston\fire",True
Case "FireAdmin"
WSHNetwork.MapNetworkDrive "j:", "\\northcharleston\fireadmin",True
Case "FireInsp"
WSHNetwork.MapNetworkDrive "j:", "\\northcharleston\fireinsp",True
Case "Fire and Police Pics"
WSHNetwork.MapNetworkDrive "p:", "\\northcharleston\pictures",True
'Case "grp-FTP-root-rw"
'Set objNetwork = WScript.CreateObject("WScript.Network")
'strLocalDrive = "M:"
'strRemoteShare = "\\server\share"
'strPer = "FALSE"
'strUsr = "username"
'strPas = "password"
'objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, strPer, strUsr,
strPas
'Case "grp-ftp-root-r"
'Set objNetwork1 = WScript.CreateObject("WScript.Network")
'strLocalDrive1 = "L:"
'strRemoteShare1 = "\\server\share"
'strPer1 = "FALSE"
'strUsr1 = "username"
'strPas1 = "password"
'objNetwork1.MapNetworkDrive strLocalDrive1, strRemoteShare1, strPer1,
strUsr1, strPas1
End Select
Next
'=====================================
'Add On Code goes above this line
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
Set objNetwork = Nothing
Set objNetwork1 = Nothing
'Quit the Script
wscript.quit
===========================
the auto config outlook script:
"Greg Stigers" wrote:
If you're still just testing, there is little to be lost by recreating your
GPOs. Does gpmc.msc or rsop show these GPOs being applied to those users?
Searching the web for "windows logon script does not run" returns quite a
few possibilities, some pretty strange, such as being a member of more than
390 groups, under Windows 2000 http://support.microsoft.com/kb/310930.
It would help to know more, including how you know they are not running. If
you haven't, include some debugging logic such as a net send command in your
logon script to map drives. You might also consider posting the scripts.
So, you have TestUserA and TestUserB. If you restart and logon as TestUserA,.
the scripts run. If you log off and log on as TestUserB, the scripts do not
run. If you restart and log on as TestUserB, the scripts run. If you log off
and log on as TestUserA, the scripts do not run. Is that about right?
BTW, there may be a better solution than using a logon script to map drives,
unless you have an application that requires drive letters or drive letter
mapping.
______
Greg Stigers, MCSE
remember to vote for the answers you like
- References:
- gpo scripts
- From: jonesj
- Re: gpo scripts
- From: Greg Stigers
- Re: gpo scripts
- From: jonesj
- Re: gpo scripts
- From: Greg Stigers
- gpo scripts
- Prev by Date: changing folder redirection with GP
- Next by Date: RE: Web Login
- Previous by thread: Re: gpo scripts
- Next by thread: Re: gpo scripts
- Index(es):
Relevant Pages
|
Loading