Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_connect_network_drives_with_logging.vbs

(view source code of login_connect_network_drives_with_logging.vbs as plain text)

  1. Set wshNetwork = CreateObject( "WScript.Network" )
  2. Set objFSO     = CreateObject( "Scripting.FileSystemObject" )
  3.  
  4. ' It doesn't hurt to make sure the C:\temp folder exists
  5. If Not objFSO.FolderExists( "C:\temp" ) Then
  6. 	Set objTempFolder = objFSO.CreateFolder( "C:\temp" )
  7. 	Set objTempFolder = Nothing
  8. End If
  9.  
  10. On Error Resume Next
  11.  
  12. ' Open a log file, display a message dialog in case of error
  13. Set objLogFile = objFSO.CreateTextFile( "C:\temp\login.log", True, False )
  14. If Err Then
  15. 	strMsg = "Error logging the results."  & vbCrLf _
  16. 	       & "Please notify the helpdesk." & vbCrLf _
  17. 	       & "For now, results will be displayed on screen."
  18. 	MsgBox strMsg, "Log File Error", 64
  19. End If
  20.  
  21. intError = 0
  22.  
  23. With wshNetwork
  24. 	' Map drive G: to the department share
  25. 	.MapNetworkDrive "G:", "\\CompanyServer\Dept"
  26. 	If Err Then
  27. 		objLogFile.WriteLine "Error " & Err & " mapping drive G:"
  28. 		objLogFile.WriteLine "(" & Err.Description & ")"
  29. 		intError = intError + 1
  30. 	End If
  31.  
  32. 	' Map drive H: to the user's home share
  33. 	.MapNetworkDrive "H:", "\\CompanyServer\" & .UserName
  34. 	If Err Then
  35. 		objLogFile.WriteLine "Error " & Err & " mapping drive H:"
  36. 		objLogFile.WriteLine "(" & Err.Description & ")"
  37. 		intError = intError + 1
  38. 	End If
  39. End With
  40.  
  41. On Error Goto 0
  42.  
  43. ' List all drive mappings
  44. With wshNetwork.EnumNetworkDrives
  45. 	For i = 0 To .Count - 2 Step 2
  46. 		objLogFile.WriteLine .Item(i) & " " & .Item(i+1)
  47. 	Next
  48. End With
  49.  
  50. ' Close the log file
  51. objLogFile.Close
  52. Set objLogFile = Nothing
  53.  
  54. ' Warn the user if (an) error(s) occurred
  55. If intError > 0 Then
  56. 	strMsg = intError & " error(s) occurred during login." & vbCrLf _
  57. 	       & "The errors are logged to be reviewed " _
  58. 	       & "by the helpdesk staff." & vbCrLf _
  59. 	       & "Please notify the helpdesk."
  60. 	MsgBox strMsg, "Login Error", 64
  61. End If
  62.  
  63. Set objFSO     = Nothing
  64. Set wshNetwork = Nothing

page last modified: 2024-04-16; loaded in 0.0392 seconds