1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
'===============================================================================================
'Network Login Script
'===============================================================================================
Dim oShell
Dim iResult
Dim iDebug
Const ForReading = 1, ForWriting = 2
Dim fso, f
'=================================================
' Set Environment Variables
'=================================================
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\Windows\Temp\log.txt", ForWriting,true)
On Error Resume Next
Domain = WSHNetwork.UserDomain
UserName = ""
iDebug = True
While UserName = ""
UserName = WSHNetwork.UserName
MyGroups = GetGroups(Domain, UserName)
Wend
' Create Shell object
Set oShell = CreateObject("Wscript.Shell")
If iDebug then f.writeline(UserName)
If iDebug then f.writeline(MyGroups)
'Open message box Yes/No and test response
'iResult = oShell.Popup("Montage des lecteurs", 5, "Lecteurs réseaux", 0)
'=================================================
'GIVES PC TIME TO DISCONNECT MAPPED DRIVES
'=================================================
WScript.Sleep(10000)
'=================================================
'Map Drives by Group
'=================================================
'USAGE: MapDrive "X:", "\\SERVER\SHARE", "Drive Name"
'NOTE: <HOMEDRIVE:> IS NOT TO BE MAPPED AS IT IS THE HOME DRIVE!!!
'=================
'domain.lan\Domain Users Drives:
'=================
If INGROUP ("Domain Users") Then
If iDebug then f.writeline("Domain Users")
If iDebug then f.writeline("Etape1 : OK")
MapDrive "Z:", "\\SRVPROD42\Commun", "Commun"
MapDrive "H:", "\\SRVPROD42\Utilisateurs$\"& UCase(UserName), "Home"
If iDebug then f.writeline("Etape2 : OK")
End If
'=================
'domain.lan\GS-INFRA Drives:
'=================
If INGROUP ("GS-INFRA") Then
If iDebug then f.writeline("GS-INFRA")
MapDrive "P:", "\\domain-nas\DATA", "NAS-HISI"
End If
If iDebug then f.writeline("Terminé")
'=================================================
'Exit Script
'=================================================
WScript.Quit
'===============================================================================================
'Subfunctions and Routines
'===============================================================================================
'=================================================
'Function: GetGroups
'=================================================
Function GetGroups(Domain, UserName)
Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
GetGroups=""
For Each objGroup In objUser.Groups
GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
Next
End Function
'=================================================
'Function: InGroup
'=================================================
Function InGroup(strGroup)
InGroup=False
If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
InGroup=True
End If
End Function
'=================================================
' MapDrives Subroutine
'=================================================
Sub MapDrive(sDrive,sShare,sName)
If iDebug then f.writeline("MapDrive1 : " & sName & " OK")
On Error Resume Next
WSHNetwork.RemoveNetworkDrive sDrive, 1, 1
WScript.Sleep(200)
Err.Clear
WSHNetwork.MapNetworkDrive sDrive, sShare
WScript.Sleep(300)
objShell.NameSpace(sDrive).Self.Name = sName
If iDebug then f.writeline("MapDrive2 : " & sShare & " OK")
End Sub |
Partager