gcue Posted March 27, 2008 Posted March 27, 2008 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
DarkMatter Posted March 27, 2008 Posted March 27, 2008 DriveGetType(@ScriptDir) If it is being run from a Network Drive it will return NETWORK [sub]Quantum mechanics: The dreams stuff is made of[/sub]
gcue Posted March 27, 2008 Author Posted March 27, 2008 (edited) actually that just differentiates between types (local/network).. it doesnt say differentiate between mapped or unmapped. Edited March 27, 2008 by gcue
gcue Posted March 27, 2008 Author Posted March 27, 2008 how about something like this?If @ScriptDir = "\\" Then MsgBox(4096, "UNC")EndIfis there a way to say "Contains" instead of "="i tried using "*" - no luck eitheractually that just differentiates between types (local/network).. it doesnt say differentiate between mapped or unmapped.
Distrophy Posted March 27, 2008 Posted March 27, 2008 (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 March 27, 2008 by Distrophy
weaponx Posted March 27, 2008 Posted March 27, 2008 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.
weaponx Posted March 27, 2008 Posted March 27, 2008 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now