Map networked drive based on location

Set objNetwork = CreateObject("Wscript.Network")

strComputer = "."

Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")

Set colAdapters = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")

For Each objAdapter in colAdapters
    For Each strAddress in objAdapter.IPAddress
        arrOctets = Split(strAddress, ".")
        If arrOctets(0) <> "" Then
            strSubnet = arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
            x = 1
            Exit For
        End If
        If x = 1 Then
            Exit For
        End If
    Next
Next

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DeviceID = 'O:'")

If colItems.Count = 0 Then
    Select Case strSubnet
        Case "172.28.8" 
            objNetwork.MapNetworkDrive "O:", "\persei8Omicron"
        Case "172.16.3" 
            objNetwork.MapNetworkDrive "O:", "\persei3Omicron"
        Case "172.20.5" 
            objNetwork.MapNetworkDrive "O:", "\persei5Omicron"
    End Select
End If

Leave a comment

Your email address will not be published.

CAPTCHA ImageChange Image