二、映射网络路径(UPN)
每个用户登陆时,自动映射网络驱动,这个目录只有该用户才能访问,其他用户包括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 objNetworkSet objNetwork = CreateObject("Wscript.Network")Set colDrives = objNetwork.EnumNetworkDrivesuserName = getUserNamesharedir="\\domainName\root\user datas\" & usernamefound=0For i = 0 To colDrives.Count-1 Step 2 If colDrives.Item(i + 1) = sharedir Then found = 1 Exit For End If NextIf found=0 Then createUserFolder sharedir,username MapNext(sharedir) End If 'wshShell = NullobjNetwork = Null Function MapNext(strShare) For intDrive = 26 To 5 Step -1 If TryMapDrive(intDrive, strShare) Then MapNext = Chr(intDrive + 64) & ":" Exit For End If NextEnd FunctionFunction 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.UserNameEnd Function
注:加载这个脚本时要创建GPO,设为
用户级运行脚本。