Print this post Print this post

Active Directory user logon script

You can assign logon script to a certain user or configure it by Group Policy. Use “Profile” tab from user’s properties in Active Directory console (ADUC). It applies to workstations from operating systems like: Windows 95, Windows 98, Windows ME, Windows NT. Group Policy script allows for a user logon script configuration for operating systems staring from Windows 2000 upwards.

Following VBS user logon script allows to:

1. Map network disks
2. Conditional mapping – it regards belonging to a certain Active Directory security group
3. Making shortcuts on the Desktop
4. Adding Network printers

 

‘=====================================
Easy Active Directory user logon script (.vbs)
‘=====================================
Option Explicit
On error resume next
Dim wshNetwork
Dim wshShell
Dim objShell
Dim userLink
Dim userDesktop
Dim userGroup
Set wshNetwork = CreateObject(“Wscript.Network”)
Set wshShell = CreateObject(“Wscript.Shell”)
Set objShell = CreateObject(“Shell.Application”)

‘————————
‘Disk mapping
‘————————
wshNetwork.MapNetworkDrive “R:”,”\\Server1\CompanyDocuments”, true
objShell.NameSpace(“R:”).Self.Name = ” CompanyDocuments “

‘————————
‘Mapping only if User is a member of a certain security group
‘————————
userGroup = “ProjectTeam”
If (IsMember(userGroup) = True) Then
wshNetwork.MapNetworkDrive “P:”,”\\Server1\Projects”, true
objShell.NameSpace(“P:”).Self.Name = “Projects”
End If

‘————————
‘Making shortcuts on the desktop
‘————————
userDesktop = wshShell.SpecialFolders(“Desktop”)
set userLink = wshShell.CreateShortcut(userDesktop & “\CompanyDocuments.lnk”)
userLink.TargetPath = “R:”
userLink.Save
set userLink = wshShell.CreateShortcut(userDesktop & “\Outlook.lnk”)
userLink.TargetPath = “C:\Program Files\Microsoft Office\Office12\outlook.exe”
userLink.Save

‘————————
‘Conditional add of network printers
‘————————
userGroup = ” HP-Printer ”
If (IsMember(userGroup) = True) Then
wshNetwork.AddWindowsPrinterConnection “\\Server2\HP-Printer”
End If
userGroup = “EPSON-Printer”
If (IsMember(userGroup) = True) Then
wshNetwork.AddWindowsPrinterConnection “\\Server2\EPSON-Printer”
End If

Musisz być logged in żeby skomentować ten wpis.