Login Script extention in Using in Active Directory Environments
FileName: Logon.vbs
Option Explicit
Dim strComputer, strDrive, strPath, strUser, strPassword, strLabel
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive, boolPersistent
'Set objNetwork = WScript.CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
strComputer = objNetwork.ComputerName
strDrive = "X:"
strUser = objNetwork.UserName
strPath = "\\server\E$\Report\" & strUser
strPassword = ""
boolPersistent = false
strLabel = strUser & " On Server"
' This section deals with a For ... Next loop
' See how it compares the enumerated drive letters
' with strDriveLetter
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) = strDrive Then AlreadyConnected =True
Next
If AlreadyConnected = True Then
objNetwork.RemoveNetworkDrive strDrive
End If
objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent
objShell.NameSpace(strDrive).Self.Name = strLabel
Wscript.Echo "Hi! " & strUser & " Map Disk OK(^_^). You have a private Disk On Server."
WScript.Quit
Option Explicit
Dim strComputer, strDrive, strPath, strUser, strPassword, strLabel
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive, boolPersistent
'Set objNetwork = WScript.CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set CheckDrive = objNetwork.EnumNetworkDrives()
strComputer = objNetwork.ComputerName
strDrive = "X:"
strUser = objNetwork.UserName
strPath = "\\server\E$\Report\" & strUser
strPassword = ""
boolPersistent = false
strLabel = strUser & " On Server"
' This section deals with a For ... Next loop
' See how it compares the enumerated drive letters
' with strDriveLetter
On Error Resume Next
AlreadyConnected = False
For intDrive = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(intDrive) = strDrive Then AlreadyConnected =True
Next
If AlreadyConnected = True Then
objNetwork.RemoveNetworkDrive strDrive
End If
objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent
objShell.NameSpace(strDrive).Self.Name = strLabel
Wscript.Echo "Hi! " & strUser & " Map Disk OK(^_^). You have a private Disk On Server."
WScript.Quit
Nhận xét
Đăng nhận xét