Code:
Option Explicit
Dim StrUserName, objNetwork, user, pass, strprofile
const marketing = "\\server\Marketing"
const FDrive = "\\server\company"
const creative = "\\server\creativeserver"
const mitn = "\\server\MITN_shared"
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.ComputerName
Select Case strUserName
Case "Comp1":
Call check("M:",marketing)
Call check("F:",FDrive)
Call cs("S:",creative,false,"user","pass")
Call check("Z:",mitn)
Case "Comp2":
Call check("M:",marketing)
Call check("F:",FDrive)
Call cs("S:",creative,false,"user","pass")
Call check("Z:",mitn)
Case "MyComp":
Call check("K:",FDrive)
Call cs("S:",creative,false,"user","pass")
Call check("Z:",mitn)
Case Else:
Call check("F:",FDrive)
Call cs("S:",creative,false,"user","pass")
Call check("Z:",mitn)
End Select
Public Function check(ByRef strDriveLetter, ByRef strRemotePath)
Set objNetwork = CreateObject("Wscript.Network")
Dim CheckDrive, AlreadyConnected, intDrive
Set CheckDrive = objNetwork.EnumNetworkDrives()
' 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) = strDriveLetter Then
AlreadyConnected = True
End If
Next
' This section uses the If = then, else logic
' This tests to see if the Drive is already mapped.
' If yes then disconnects
Select Case AlreadyConnected
Case "True":
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
Case "False":
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
End Select
End Function
Public Function cs(ByRef strDriveLetter, ByRef strRemotePath, ByRef prof, ByRef User, ByRef Pass)
Set objNetwork = CreateObject("Wscript.Network")
Dim CheckDrive, AlreadyConnected, intDrive
Set CheckDrive = objNetwork.EnumNetworkDrives()
' 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) = strDriveLetter Then
AlreadyConnected = True
End If
Next
' This section uses the If = then, else logic
' This tests to see if the Drive is already mapped.
' If yes then disconnects
Select Case AlreadyConnected
Case "True":
objNetwork.RemoveNetworkDrive strDriveLetter
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass
Case "False":
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass
End Select
End Function Can someone shed some light on what I am doing wrong or what needs to be fixed so that I can get this to work correctly, do I need to do a wscript.sleep for 15 seconds before it runs so it gives the machine a chance to load or what exactly ?