(view source code of login_connect_network_drives_with_logging.vbs as plain text)
Set wshNetwork = CreateObject( "WScript.Network" )
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
' It doesn't hurt to make sure the C:\temp folder exists
If Not objFSO.FolderExists( "C:\temp" ) Then
Set objTempFolder = objFSO.CreateFolder( "C:\temp" )
Set objTempFolder = Nothing
End If
On Error Resume Next
' Open a log file, display a message dialog in case of error
Set objLogFile = objFSO.CreateTextFile( "C:\temp\login.log", True, False )
If Err Then
strMsg = "Error logging the results." & vbCrLf _
& "Please notify the helpdesk." & vbCrLf _
& "For now, results will be displayed on screen."
MsgBox strMsg, "Log File Error", 64
End If
intError = 0
With wshNetwork
' Map drive G: to the department share
.MapNetworkDrive "G:", "\\CompanyServer\Dept"
If Err Then
objLogFile.WriteLine "Error " & Err & " mapping drive G:"
objLogFile.WriteLine "(" & Err.Description & ")"
intError = intError + 1
End If
' Map drive H: to the user's home share
.MapNetworkDrive "H:", "\\CompanyServer\" & .UserName
If Err Then
objLogFile.WriteLine "Error " & Err & " mapping drive H:"
objLogFile.WriteLine "(" & Err.Description & ")"
intError = intError + 1
End If
End With
On Error Goto 0
' List all drive mappings
With wshNetwork.EnumNetworkDrives
For i = 0 To .Count - 2 Step 2
objLogFile.WriteLine .Item(i) & " " & .Item(i+1)
Next
End With
' Close the log file
objLogFile.Close
Set objLogFile = Nothing
' Warn the user if (an) error(s) occurred
If intError > 0 Then
strMsg = intError & " error(s) occurred during login." & vbCrLf _
& "The errors are logged to be reviewed " _
& "by the helpdesk staff." & vbCrLf _
& "Please notify the helpdesk."
MsgBox strMsg, "Login Error", 64
End If
Set objFSO = Nothing
Set wshNetwork = Nothing
page last modified: 2024-04-16; loaded in 0.0092 seconds