Jump to content

Recommended Posts

Posted

is it possible to see if the script is being mapped from a mapped drive?

i get errors if someone runs it from a unc path (\\server\blah\blah.exe)

thanks

Posted (edited)

actually that just differentiates between types (local/network)..

it doesnt say differentiate between mapped or unmapped.

Edited by gcue
Posted

how about something like this?

If @ScriptDir = "\\" Then

MsgBox(4096, "UNC")

EndIf

is there a way to say "Contains" instead of "="

i tried using "*" - no luck either

actually that just differentiates between types (local/network)..

it doesnt say differentiate between mapped or unmapped.

Posted (edited)

You could take the script location and compare it against a list of the mapped drives. Search the necessary functions in the help file for that.

Searching for "\\" in the script dir wont tell you if it's mapped either and you might as well use the first suggestion.

Also look up StringInStr and StringSplit for help parsing the locations.

Edited by Distrophy
Posted

Here you go:

Dim $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")

Dim $colDrives = $objWMIService.ExecQuery ("Select * From Win32_LogicalDisk Where DriveType = 4")

Dim $mapped = false

For $objDrive in $colDrives
    ;ConsoleWrite("Drive letter: " & $objDrive.DeviceID & @CRLF)
    ;ConsoleWrite("Network path: " & $objDrive.ProviderName & @CRLF)
    
    If StringLeft(@ScriptDir, 2) = $objDrive.DeviceID OR StringInStr(@ScriptDir, $objDrive.ProviderName) Then
        $mapped = True
        ExitLoop
    EndIf
Next

If $mapped Then
    MsgBox(0,"","Drive is mapped")
Else
    MsgBox(0,"","Drive is NOT mapped")
EndIf

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...