Eksempel på et VBS logon script


Nedenstående script kan benyttes på workstation og i et Teminal/Citrix miljø.
Gruppe funktionen medtager også nested groups.

‘Globale Variabler
Dim objNetwork,strUser ,wShell,wshnetwork

‘Ingen fejlmeddelser
on error resume next

‘***************** Get Username + Nested Groups *********************

Set objNetwork=CreateObject(“Wscript.Network”)
strUser
=objNetwork.UserName

Function IsMember(sGroup)
If IsEmpty(oGroupList) Then
Set
oGroupList = CreateObject(“Scripting.Dictionary”)
Call LoadGroups(oADObject)
End If
IsMember = oGroupList.Exists(sGroup)
End Function

Sub LoadGroups(oADObject)
On Error Resume Next
Dim
colsGroups, oGroup, j
oGroupList.CompareMode
= vbTextCompare
colsGroups
= oADObject.memberOf
If IsEmpty(colsGroups) Then
Exit Sub
End If

If TypeName(colsGroups) = “String” Then
Set
oGroup = GetObject(“LDAP://” & colsGroups)
If Not oGroupList.Exists(oGroup.sAMAccountName) Then
oGroupList(oGroup.sAMAccountName) = True
Call
LoadGroups(oGroup)
End If
Set
oGroup = Nothing
Exit Sub
End If

For j = 0 To UBound(colsGroups)
Set oGroup = GetObject(“LDAP://” & colsGroups(j))
If Not oGroupList.Exists(oGroup.sAMAccountName) Then
oGroupList(oGroup.sAMAccountName) = True
Call
LoadGroups(oGroup)
End If
Next
Set
oGroup = Nothing
End Sub

‘********Tjek om brugeren skal afvikle Login script****************

If IsMember(“CtxAdmin”) Then
Wscript
.Quit
End If

‘*********** Map Network Drives ***********************************

set wshnetwork = wscript.createobject(“wscript.network”)
wshnetwork.mapnetworkdrive
“H:”,“\WIN-FIL-001Home$” & strUser & “”
wshnetwork.mapnetworkdrive “M:”,“\WIN-FIL-001Teknik”
wshnetwork.mapnetworkdrive “N:”,“\WIN-FIL-001IT”
wshnetwork.mapnetworkdrive “O:”,“\WIN-FIL-001Public”

‘*********** Map Clint Printers ***********************************

wshnetwork.addwindowsprinterconnection “\WIN-FIL-001HP4100”
wshnetwork.addwindowsprinterconnection “\WIN-FIL-001HP4700”

‘Sætter default printer
wshnetwork.setdefaultprinter “\WIN-FIL-001HP4100”

‘********************Redirect af diverse foldere***************************

Dim WSHShell
Set WSHShell = Wscript.CreateObject(“WScript.Shell”)

RegRedirect = “HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders”
WSHShell.RegWrite RegRedirect & “Personal”, “H:My Documents”,“REG_EXPAND_SZ”
WSHShell.RegWrite RegRedirect & “Desktop”, “H:CitrixDesktop”,“REG_EXPAND_SZ”
WSHShell.RegWrite RegRedirect & “Favorites”, “H:CitrixFavorites”,“REG_EXPAND_SZ”
WSHShell.RegWrite RegRedirect & “Cookies”, “H:CitrixCookies”,“REG_EXPAND_SZ”

‘********************Opretter Genveje på deskop*****************************

Dim oShell
Set oShell = Wscript.CreateObject(“WScript.Shell”)

Const OverwriteExisting = True
Set
objFSO = CreateObject(“Scripting.FileSystemObject”)

If IsMember(“MSvisio”) Then
objFSO.CopyFile “\WIN-FIL-001GenvejMS Visio.lnk” , “H:CitrixDesktop” , OverwriteExisting
End If

If IsMember(“SAP”) Then
objFSO.CopyFile “\WIN-FIL-001GenvejSAPlogon.lnk” , “H:CitrixDesktop” , OverwriteExisting
Set oShell = Wscript.CreateObject(“WScript.Shell”)
CmdResult
= oShell.run (“\WII-FIL-001GenvejSAP.cmd”)
CmdResult
= oShell.run (“regedit /S \WIN-FIL-001GenvejSAP.reg,0,True”)
End If

Comments are closed.