Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Аватара для dimich22

В работе


Сообщения: 851
Благодарности: 215

Профиль | Сайт | Отправить PM | Цитировать


Вот целиком рабочий листинг. Подключаются диски в зависимости от членства в группе.
Комментарии оставил. Изначально скрипт написан Dan Thomson (logon.vbs), я его только немного подправил. Т.о. можно подключать и принтеры

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

On Error Resume Next

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Define Variables and Constants
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim objFileSys
Dim objIntExplorer
Dim objWshNetwork
Dim objWshShell
Dim strDomain 'Domain of the user
Dim strHomePage 'Homepage to be set for user
Dim strLogonPath 'Path to location from where the script is running
Dim strOSProdType 'OS Product type (WinNT, LanmanNT, ServerNT)
Dim strWorkstation 'Local Computer Name
Dim strUserGroups 'List of groups the user is a meber of
Dim intCounter 'General counter

Const UseNTServer = 0 'Sets whether this script runs when logging on locally
'to Windows Servers.
'Values are: 1 (Yes) OR 0 (No)

Const FileSrv1 = "\\w2kserver"
Const FileSrv2 = "\\calculator2"

'Initialize common scripting objects
Set objFileSys = CreateObject( "Scripting.FileSystemObject" )
Set objWshNetwork = CreateObject( "WScript.Network" )
Set objWshShell = CreateObject( "WScript.Shell" )


'Pause script until user is fully logged on (applicable only to Win 9x or ME)
'This will timeout after 10 seconds
strUser = ""
intCounter = 0
Do
strUserID = objWshNetwork.Username
intCounter = intCounter + 1
Wscript.Sleep 500
Loop Until strUserID <> "" OR intCounter > 20

'Check for error getting username
If strUserID = "" Then
objWshShell.Popup "Logon script failed - Contact the Helpdesk @ x 345", , _
"Logon script", 48
Call Cleanup
End If

'Gather some basic system info
Call GetSystemInfo

If IsTerminalServerSession <> True Then
'Exit if we are logging on locally to a server and the script is set to NOT run on servers
IF UseNTServer = 0 AND (strOSProdType = "LanmanNT" OR strOSProdType = "ServerNT") Then
objWshShell.Popup "Windows Server - Exiting Logon Script!", 10, _
"Logon to " & strDomain, 16
Call CleanUp
End if
End If

'Get group memberships
strUserGroups = ""
Call GetLocalGroupMembership
Call GetGlobalGroupMembership

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'
' This section performs actions based on group membership
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

if InGroup("ТАИ") then
MapDrv "P:", FileSrv1 & "\tai$","Папка для ТАИ"
MapDrv "P:\", FileSrv1 & "\tai$","Папка для ТАИ"
End If

If InGroup( "ПЭО" ) Then
MapDrv "P:", FileSrv1 & "\peo$","Папка для ПЭО"
MapDrv "P:\", FileSrv1 & "\peo$","Папка для ПЭО"
End If

If InGroup( "Бухгалтерия" ) Then
MapDrv "P:", FileSrv1 & "\buh$","Папка для бухгалтерии"
MapDrv "P:\", FileSrv1 & "\buh$","Папка для бухгалтерии"
End If

If InGroup( "Администрация" ) Then
MapDrv "P:", FileSrv1 & "\ruk$","Папка для администрации"
MapDrv "P:\", FileSrv1 & "\ruk$","Папка для администрации"
End If

If InGroup( "АРС" ) Then
MapDrv "P:", FileSrv1 & "\ars$","Папка для АРС"
MapDrv "P:\", FileSrv1 & "\ars$","Папка для АРС"
End If

If InGroup( "Канцелярия" ) Then
MapDrv "P:", FileSrv1 & "\zu$","Папка для канцелярии"
MapDrv "P:\", FileSrv1 & "\zu$","Папка для канцелярии"
End If

If InGroup( "КТЦ" ) Then
MapDrv "P:", FileSrv1 & "\ktc$","Папка для КТЦ"
MapDrv "P:\", FileSrv1 & "\ktc$","Папка для КТЦ"
End If

If InGroup( "Администрация" ) Then
MapDrv "P:", FileSrv1 & "\ruk$","Папка для администрации"
MapDrv "P:\", FileSrv1 & "\ruk$","Папка для администрации"
End If

If InGroup( "НСС" ) Then
MapDrv "P:", FileSrv1 & "\nss$","Папка для НСС"
MapDrv "P:\", FileSrv1 & "\nss$","Папка для НСС"
End If

If InGroup( "ОКС" ) Then
MapDrv "P:", FileSrv1 & "\oks$","Папка для ОКС"
MapDrv "P:\", FileSrv1 & "\oks$","Папка для ОКС"
End If

If InGroup( "ОМТСиК" ) Then
MapDrv "P:", FileSrv1 & "\omts$","Папка для ОМТСиК"
MapDrv "P:\", FileSrv1 & "\omts$","Папка для ОМТСиК"
End If

If InGroup( "ОППР" ) Then
MapDrv "P:", FileSrv1 & "\oppr$","Папка для ОППР"
MapDrv "P:\", FileSrv1 & "\oppr$","Папка для ОППР"
End If

If InGroup( "Отдел Кадров" ) Then
MapDrv "P:", FileSrv1 & "\ok$","Папка для Отдела кадров"
MapDrv "P:\", FileSrv1 & "\ok$","Папка для Отдела кадров"
End If

If InGroup( "ПТО" ) Then
MapDrv "P:", FileSrv1 & "\pto$","Папка для ПТО"
MapDrv "P:\", FileSrv1 & "\pto$","Папка для ПТО"
End If

If InGroup( "Химцех" ) Then
MapDrv "P:", FileSrv1 & "\hc$","Папка для Химцеха"
MapDrv "P:\", FileSrv1 & "\hc$","Папка для Химцеха"
End If

If InGroup( "Электроцех" ) Then
MapDrv "P:", FileSrv1 & "\ec$","Папка для Электроцеха"
MapDrv "P:\", FileSrv1 & "\ec$","Папка для Электроцеха"
End If

If InGroup( "Мнемосхема" ) Then
MapDrv "R:", FileSrv2 & "\mnemo","Мнемосхема"
MapDrv "R:\", FileSrv2 & "\mnemo","Мнемосхема"
End If

If InGroup( "Директор" ) Then
MapDrv "Y:", FileSrv1 & "\chief$","Конфиденциально"
MapDrv "Y:\", FileSrv1 & "\chief$","Конфиденциально"
End If

MapDrv "V:", FileSrv1 & "\users\" & objWshNetwork.UserName, "Домашняя папка"
MapDrv "V:\", FileSrv1 & "\users\" & objWshNetwork.UserName, "Домашняя папка"

MapDrv "K:", FileSrv1 & "\distr", "Дистрибутивы"
MapDrv "K:\", FileSrv1 & "\distr", "Дистрибутивы"

MapDrv "T:", FileSrv1 & "\ctec","Папка ЦТЭЦ"
MapDrv "T:\", FileSrv1 & "\ctec","Папка ЦТЭЦ"


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' End section
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub: MapDrive
'
' Purpose: Map a drive to a shared folder
'
' Input:
' strDrive Drive letter to which share is mapped
' strServer Name of server that hosts the share
' strShare Share name
'
' Output:
'
' Usage:
' Call MapDrive ("P:", "w2kserver", "tai$")
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function MapDrv(DrvLet, UNCPath, DrvName)

Dim objFSO, oShell ' Object variable

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objoShell = CreateObject("Shell.Application")

On Error Resume Next

If objFSO.DriveExists(DrvLet) Then
objWshNetwork.RemoveNetworkDrive DrvLet, true, true
End If

objWshNetwork.MapNetworkDrive DrvLet, UNCPath
objoShell.NameSpace(DrvLet).Self.Name = DrvName

End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub: GetLocalGroupMembership
'
' Purpose: Gather all local groups the current user belongs to
'
' Input:
'
' Output: Local group names are added to strUserGroups
'
' Usage: Call GetLocalGroupMembership
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub GetLocalGroupMembership

On Error Resume Next

Dim colGroups 'Collection of groups on the local system
Dim objGroup 'Object reference to individual groups
Dim objUser 'Object reference to individual group member

'Verify system is not Windows 9x or ME
If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
'Connect to local system
Set colGroups = GetObject( "WinNT://" & strWorkstation )
colGroups.Filter = Array( "group" )
'Process each group
For Each objGroup In colGroups
'Process each user in group
For Each objUser in objGroup.Members
'Check if current user belongs to group being processed
If LCase( objUser.Name ) = LCase( strUserID ) Then
'Add group name to list
strUserGroups = strUserGroups & objGroup.Name & ","
End If
Next
Next
Set colGroups = Nothing
End If

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub: GetGlobalGroupMembership
'
' Purpose: Gather all global groups the current user belongs to
'
' Input:
'
' Output: Global group names are added to strUserGroups
'
' Usage: Call GetGlobalGroupMembership
'
' Notes: Use WinNT connection method to be backwards
' compatible with NT 4 domains
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub GetGlobalGroupMembership

On Error Resume Next

Dim objNameSpace
Dim objUser

Const ADS_READONLY_SERVER = 4

Set objNameSpace = GetObject( "WinNT:" )
'Use the OpenDSObject method with the ADS_READONLY_SERVER
'value to grab the "closest" domain controller

'Connect to user object in the domain
Set objUser = objNameSpace.OpenDSObject( _
"WinNT://" & strDomain & "/" & strUserID, "", "", ADS_READONLY_SERVER)
'Process each group
For Each objGroup In objUser.Groups
'Add group name to list
strUserGroups = strUserGroups & objGroup.Name & ","
Next
Set objNameSpace = Nothing

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function: InGroup
'
' Purpose: Determine if user belongs to specified group
'
' Input: Name of group to test for membership
'
' Output: True or False
'
' Usage: If InGroup("Domain Admins") Then <do something>
'
' Requirements:
' strUserGroups must have been previously populated via
' GetLocalGroupMembership and/or GetGlobalGroupMembership
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function InGroup(strGroup)

On Error Resume Next

InGroup = False
'Search strUserGroups for strGroup
If Instr( 1, LCase( strUserGroups ), LCase( strGroup ), 1) Then InGroup = True

End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub: GetSystemInfo
'
' Purpose: Gather basic info about local system
'
' Input:
'
' Output: strDomain, strOSProdType, strWorkstation, strLogonPath
'
' Usage: Call GetSystemInfo
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub GetSystemInfo

On Error Resume Next

'Get domain name
If objWshShell.ExpandEnvironmentStrings( "%OS%" ) = "Windows_NT" Then
strDomain = objWshNetwork.UserDomain
Else
strDomain = objWshShell.RegRead( "HKLM\System\CurrentControlSet\" & _
"Services\MSNP32\NetWorkProvider\AuthenticatingAgent" )
End If

'Get Product Type from registry (WinNT, LanmanNT, ServerNT)
strOSProdType = objWshShell.RegRead( _
"HKLM\System\CurrentControlSet\Control\ProductOptions\ProductType")

'Get computer name
If IsTerminalServerSession = True Then
'Set strWorkstation to the real name and not the name of the server
strWorkstation = objWshShell.ExpandEnvironmentStrings( "%CLIENTNAME%" )
Else
strWorkstation = objWshNetwork.ComputerName
End If

'Get the path to the location from where the script is running
strLogonPath = Left( Wscript.ScriptFullName, _
( InstrRev( Wscript.ScriptFullName, "\") -1))

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function: IsTerminalServer
'
' Purpose: Determine if the script is running in a terminal server session
'
' Input:
'
' Output:
' True if running in a terminal server session
' False if not running in a terminal server session
' Usage:
' If IsTerminalServerSession = True Then <Do Something>
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IsTerminalServerSession

On Error Resume Next

Dim strName

'Detect if this is a terminal server session
'If it is, set some names to the terminal server client name
strName = objWshShell.ExpandEnvironmentStrings( "%CLIENTNAME%" )
If strName <> "%CLIENTNAME%" AND strName <> "" Then _
IsTerminalServerSession = True

End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub: Cleanup
'
' Purpose: Release common objects and exit script
'
' Input:
'
' Output:
'
' Usage: Call Cleanup
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Cleanup

On Error Resume Next

Set objFileSys = Nothing
Set objWshNetwork = Nothing
Set objWshShell = Nothing
Set objIntExplorer = Nothing

'Exit script
Wscript.Quit()

End Sub

-------
Программа выполняет то, что вы ей приказали делать, а не то, что бы вы хотели, чтобы она делала.
Компьютерная литература Мой сайт Active Directory Сборник рецептов


Отправлено: 17:32, 21-03-2007 | #6