script อันนี้มีฟังชั่นการทำงานหลักๆ คือ
๑. map drive สามารถเลือก map ตาม group ของ user ได้
๒. map printer สามารถเลือก map ตาม group ของ user ได้
๓. ตั้งชื่อไดรฟ์ที่ map ได้
๔. สามารถสร้าง short cut ของไดรฟ์ที่ map มาไว้บน desktop ได้
๕. สามารถตรวจสอบ password ว่าใกล้หมดอายุหรือเปล่า
'Author: Touchie
'Created by SAPIEN Technologies, Inc. Logon Script Generator
'Modified by: Touchie
'Logon script version 3.0
'**********************
On Error Resume Next
Dim objFSO,objFILE,objShell,objNetwork,objShellApp,MyShortcut
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")
Set objShellApp = CreateObject("Shell.Application")
'edit here
'Map network drives
'usage:
'MapIt "Drive letter","\\server_name\shared_name","Name of drive to show on My computer and Desktop"
MapIt "I:","\\server\info","Public Documents"
MapIt "J:","\\server\FTPScan","For FTP Scanner"
MapIt "K:","\\server\OfficeDoc","The Office Documents"
'For map drive to specific group only. eg. 'Management' group
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Management") Then MapIt "M:","\\server\Management","Management"
'edit here
'Map printers
'usage:
'AddPrinterConnection "\\server_name\printer_shared_name"
AddPrinterConnection "\\server\x560n"
'Set as default printer
objNetwork.SetDefaultPrinter "\\server\x560n"
AddPrinterConnection "\\server\x342n"
'For map printer to specific group only. eg. 'Management' group
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Management") Then AddPrinterConnection "\\server\e250dn"
'End of main script
'//////////////////////////////////////////////////
Function PasswordExpires(strDomain,strUser)
On Error Resume Next
Dim objUser
Set objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
PassExp=INT(objUser.MaxPasswordAge/86400)-INT(objUser.PasswordAge/86400)
If PassExp<0 Then
strPassMsg="Your password never expires."
Else
strPassMsg="Your password expires in " & PassExp & " day(s)"
end If
PasswordExpires=strPassMsg
End Function
Function IsAMemberOf(strDomain,strUser,strGroup)
On Error Resume Next
Set objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
Set objGrp=GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
If objGrp.IsMember(objUser.ADsPath) Then
IsAMemberOf=True
Else
IsAMemberOf=False
End If
End Function
Sub MapIt(strDrive,strMap,strNewName)
On Error Resume Next
If objFSO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive)
objNetwork.MapNetworkDrive strDrive,strMap
objShellApp.NameSpace(strDrive).Self.Name = strNewName
'Create Shortcut on Desktop
'If no need shortcut, just comment here
DesktopPath = objShell.SpecialFolders("Desktop")
'Create a shortcut object on the desktop
Set MyShortcut = objShell.CreateShortcut(DesktopPath & "\" & strNewName & ".lnk")
'Set shortcut object properties and save it
strTargetDrive = strDrive & "\"
MyShortcut.TargetPath = objShell.ExpandEnvironmentStrings(strTargetDrive)
MyShortcut.WorkingDirectory = objShell.ExpandEnvironmentStrings("")
MyShortcut.WindowStyle = 4
MyShortcut.IconLocation = objShell.ExpandEnvironmentStrings("%windir%\system32\shell32.dll, 126")
MyShortcut.Save
'End of create shortcut
If Err.Number<>0 And blnShowError Then
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
VbCrLf & Err.Description
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
Err.Clear
End If
End Sub
Sub AddPrinterConnection(strPrinterUNC)
On Error Resume Next
objNetwork.AddWindowsPrinterConnection strPrinterUNC
If Err.Number<>0 And blnShowError Then
strMsg="There was a problem mapping " & UCase(strPrinterUNC) & ". " &_
vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
VbCrLf & Err.Description
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
Err.Clear
End If
end sub
Sub AddPrinterPortConnection(strPort,strPrinterUNC)
On Error Resume Next
objNetwork.AddPrinterConnection strPort,strPrinterUNC
If Err.Number<>0 And blnShowError Then
strMsg="There was a problem mapping " & UCase(strPrinterUNC) & " to " &_
strPort & vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
VbCrLf & Err.Description
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
Err.Clear
End If
end sub
ที่มา http://www.thaiadmin.org/board/index.php?topic=121159.0