ON ERROR RESUME NEXT
'Set up some variables and constants
Dim Choice
Dim Drive, DriveCollection, DriveObj
Dim EnvLogonServer, EnvOpSystem, EnvWinDir, EnvTempDir, EstNumOfMaps, EventLog, EventLogObj
Dim FileServer,FileSysObj
Dim LocalPort, LogContents, LoginBox
Dim MapCount, MsgString
Dim Proc0, PrintObj, PrintServer
Dim RemotePrinter
Dim Share
Dim UseLogonScreen
Dim WSHShell, WshProcessEnvironment, WSHNetwork
Dim oShell
'Disconnect ALL mapped drives
Call DisconnetDriver()
'This sets constants for the textfile object.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
'This sets the use of the LoginBox Control to Yes.
'To Change it set the value to no
UseLogonScreen = "yes"
'This value is set for the progress bar of the
'LoginBox control. Estimate the average number
'of drives and printers mapped for a typical
'user session. It is important that you
'**ALWAYS OVERESTIMATE THIS VALUE**
'by a couple of drives. So that the user
'cannot close the loginbox dialog before the
'~~Script~~. has completed.
EstNumOfMaps = 9
'Set up some Objects for use later
set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHShell = CreateObject("WScript.Shell")
Set oShell = CreateObject("Shell.Application")
Set WshProcessEnvironment = WshShell.Environment("Process")
'Get some necessary environment variables
EnvWinDir = WshProcessEnvironment("windir")
EnvTempDir = WshProcessEnvironment("Temp")
EnvOpSystem = WshProcessEnvironment("OS")
Const FileServ01 = "fycnsrv03"
Const FileServ02 = "10.86.21.21"
Const PrintServ01 = "fycnsrv03"
Const printer1 = "it 2200" 'location: IT dept
Const printer2 = "fin hp1100" 'location: finance dept
Const printer3 = "Xerox_C3000_U" 'location: Fax room
Const printer4 = "HPLaserJ1320" 'location: planning section of material
Const printer5 = "Xerox_C3000_C" 'printing color, location:Fax room
Const printer6 = " "
User = ""
Do While User = ""
User = WSHNetwork.UserName
Loop
'Now its time to start the Logon Process
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
strGroup = LCase(Join(CurrentUser.MemberOf))
'Now map some group specific drives. You can
'build the Select case to
'better reflect your environment
MapDrive "Y:", FileServ01, "personal\" & User
MapDrive "Z:", FileServ01, "public"
set UserObj = GetObject("WinNT://" & WshNetwork.UserDomain & "/" & WshNetwork.UserName)
For Each Group In UserObj.groups
Select Case Group.Name
Case "DG_IT"
MapDrive "S:", FileServ01, "sap"
MapDrive "I:", FileServ01, "it2"
ConnectPrinter PrintServ01, printer3
'ConnectPrinter PrintServ01, printer2
'ConnectPrinter PrintServ01, printer4
WshNetwork.SetDefaultPrinter "\\" & PrintServ01 & "\" & Printer3
Case "DG_HR"
MapDrive "X:", FileServ01, "HR"
ConnectPrinter PrintServ01, printer5
' WshNetwork.SetDefaultPrinter "\\" & PrintServ01 & "\" & Printer2
Case "DG_Finance"
MapDrive "h:", FileServ01, "report"
MapDrive "J:", FileServ01, "project"
MapDrive "s:", FileServ01, "sap"
MapDrive "X:", FileServ01, "account"
ConnectPrinter PrintServ01, printer2
WshNetwork.SetDefaultPrinter "\\" & PrintServ01 & "\" & Printer2
Case "DG_Material"
MapDrive "h:", FileServ01, "bom"
MapDrive "i:", FileServ01, "report"
MapDrive "k:", FileServ01, "plan"
MapDrive "m:", FileServ01, "pc"
MapDrive "u:", FileServ01, "purchase"
MapDrive "s:", FileServ01, "sap"
MapDrive "t:", FileServ01, "buyer"
ConnectPrinter PrintServ01, printer4
WshNetwork.SetDefaultPrinter "\\" & PrintServ01 & "\" & Printer4
Case "DG_GM_Office"
MapDrive "h:", FileServ01, "bom"
MapDrive "i:", FileServ01, "report"
MapDrive "k:", FileServ01, "plan"
MapDrive "l:", FileServ01, "sales-price"
MapDrive "m:", FileServ01, "project"
MapDrive "o:", FileServ01, "meeting"
MapDrive "q:", FileServ01, "customfile"
MapDrive "s:", FileServ01, "sap"
MapDrive "w:", FileServ01, "sale"
' ConnectPrinter PrintServ01, printer5
' WshNetwork.SetDefaultPrinter "\\" & PrintServ01 & "\" & Printer5
Case "DG_Sales"
MapDrive "h:", FileServ01, "bom"
MapDrive "i:", FileServ01, "report"
MapDrive "k:", FileServ01, "plan"
MapDrive "l:", FileServ01, "sales-price"
MapDrive "m:", FileServ01, "project"
MapDrive "q:", FileServ01, "customfile"
MapDrive "s:", FileServ01, "sap"
MapDrive "x:", FileServ01, "sale"
ConnectPrinter PrintServ01, printer3
WshNetwork.SetDefaultPrinter "\\" & PrintServ01 & "\" & Printer3
End Select
Next
Wscript.quit
Sub MapDrive(Drive, FileServer, Share)
FileServer = "\\" & FileServer
Share = "\" & Share
WshNetwork.MapNetworkDrive Drive, FileServer & Share
End Sub
'This subroutine adds printers
Sub ConnectPrinter(PrintServer, Queue)
PrintServer = "\\" & PrintServer
Queue = "\" & Queue
On error resume next
'This next line is a workaround to provide
'some error checking when adding a printer
'since WshAdmin.dll does not report an error
'when the printer does not exists.
WsHNetwork.AddPrinterConnection Lpt8, PrintServer & Queue
If err.number <> 0 Then
LogContents = LogContents & "FAILURE!!! UNABLE to connect printer " & PrintServer & Queue & ". The remote file printer is unavailable!" & vbcrlf
msgbox "The Logon Script was unable to connect " & vbcrlf & vbcrlf & PrintServer & Queue & vbcrlf & vbcrlf & "The remote printer is either unavailable or " & Port & " is already in use!" & vbCRLF & "Please contact your network administrator.", vbOk + vbcritical,"Acme Information Services."
Else
'This next line deletes our dummy printer
'connection
'WsHNetwork.RemovePrinterConnection PrintServer & Queue
WshNetwork.AddWindowsPrinterConnection PrintServer & Queue
End If
err.clear
End Sub
'This subroutine enumerates the resultant
'drive mappings and printers for display in
'the logon screen control
Sub DisplayMappings()
Set DriveCollection = WSHNetwork.EnumNetworkDrives
MsgString = "You have access to following network " & vbcrlf & "drive and printer connections: " & vbCRLF & vbCRLF
For i = 0 To DriveCollection.Count - 1 Step 2
MsgString = MsgString & vbCRLF & vbtab & DriveCollection(i) & Chr(9) & DriveCollection(i + 1)
Next
Set PrinterCollection = WshNetwork.EnumPrinterConnections
For i = 0 To PrinterCollection.Count - 1 Step 2
MsgString = MsgString & vbCRLF & vbtab & PrinterCollection(i) & Chr(9) & PrinterCollection(i + 1)
Next
End Sub
Sub DisconnetDriver()
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 3000
End Sub
上文脚本是一个设备配置自动映射所属部门的文件夹及打印机,在AD中用户属性配置成登陆的脚本,可以在计算机启动过程中完成这些动作,大大提高了工作效率。
自由广告区 |
分类导航 |
邮件新闻资讯: IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮 电子邮箱 | 反垃圾邮件|邮件客户端|网络安全 行业数据 | 邮件人物 | 网站公告 | 行业法规 网络技术: 邮件原理 | 网络协议 | 网络管理 | 传输介质 线路接入 | 路由接口 | 邮件存储 | 华为3Com CISCO技术 | 网络与服务器硬件 操作系统: Windows 9X | Linux&Uinx | Windows NT Windows Vista | FreeBSD | 其它操作系统 邮件服务器: 程序与开发 | Exchange | Qmail | Postfix Sendmail | MDaemon | Domino | Foxmail KerioMail | JavaMail | Winwebmail |James Merak&VisNetic | CMailServer | WinMail 金笛邮件系统 | 其它 | 反垃圾邮件: 综述| 客户端反垃圾邮件|服务器端反垃圾邮件 邮件客户端软件: Outlook | Foxmail | DreamMail| KooMail The bat | 雷鸟 | Eudora |Becky! |Pegasus IncrediMail |其它 电子邮箱: 个人邮箱 | 企业邮箱 |Gmail 移动电子邮件:服务器 | 客户端 | 技术前沿 邮件网络安全: 软件漏洞 | 安全知识 | 病毒公告 |防火墙 攻防技术 | 病毒查杀| ISA | 数字签名 邮件营销: Email营销 | 网络营销 | 营销技巧 |营销案例 邮件人才:招聘 | 职场 | 培训 | 指南 | 职场 解决方案: 邮件系统|反垃圾邮件 |安全 |移动电邮 |招标 产品评测: 邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端 |