活动目录管理中常用的脚本(二)
二、映射网络路径(UPN)
每个用户登陆时,自动映射网络驱动,这个目录只有该用户才能访问,其他用户包括Administrators Groups member也无法访问,主要让用户存放个人数据。
如果这个用户是第一次登陆时,脚本将会为这个用户在
每个用户登陆时,自动映射网络驱动,这个目录只有该用户才能访问,其他用户包括Administrators Groups member也无法访问,主要让用户存放个人数据。
如果这个用户是第一次登陆时,脚本将会为这个用户在
“\\domainName\root\user datas\”路径中创建以用户名命名的目录。
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME: auto map network directory to local z: driver
'
' AUTHOR: Bona Shen
' DATE : 2006-10-31
'
' COMMENT: auto map network directory to local z: driver
'
'==========================================================================
On Error Resume Next
dim objNetwork
Set objNetwork = CreateObject("Wscript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
userName = getUserName
sharedir="\\domainName\root\user datas\" & username
found=0
For i = 0 To colDrives.Count-1 Step 2
If colDrives.Item(i + 1) = sharedir Then
found = 1
Exit For
End If
Next
If found=0 Then
createUserFolder sharedir,username
MapNext(sharedir)
End If
'wshShell = Null
objNetwork = Null
Function MapNext(strShare)
For intDrive = 26 To 5 Step -1
If TryMapDrive(intDrive, strShare) Then
MapNext = Chr(intDrive + 64) & ":"
Exit For
End If
Next
End Function
Function TryMapDrive(intDrive, strShare)
' Convert number to drive letter and try mapping share to it
' will get an error if drive letter is in use
Dim strDrive
strDrive = Chr(intDrive + 64) & ":"
On Error Resume Next
objNetwork.MapNetworkDrive strDrive, strShare
TryMapDrive = (Err.Number = 0)
End Function
Sub createUserFolder(folderpath,username)
'create user floder
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(folderpath) Then
'WSH.Echo "create folder"
objFSO.CreateFolder(folderpath)
configPermission username,folderpath
End If
End Sub
Sub configPermission(username,folderpath)
Set wshShell = WScript.CreateObject("WScript.Shell")
userdir=""""&folderpath&""""
argu = userdir & " /G "& username &":f"
wshShell.Run("cscript \\
domainName
\root\scripts\xcacls.vbs "& argu)
wshShell = Null
End Sub
Function getUserName
getUserName = objNetwork.UserName
End Function
注:加载这个脚本时要创建GPO,设为用户级运行脚本。posted on 2006-12-23 16:59 Bona shen 阅读(1211) 评论(1) 编辑 收藏 举报