Jump to content

detect if script is being run from a mapped drive?


gcue
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

You could combine the above ideas:

$result = DriveGetType (@ScriptDir)

If $result = "Network" Then
    If StringLeft(@ScriptDir, 2) = "\\" Then
        ;Drive NOT mapped
    Else
        ;Drive mapped
    EndIf
EndIf

Unfortunately, if you happen to have launched the script from the UNC path but the drive is mapped it will still show not mapped.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...