gruntydatsun Posted December 6, 2013 Share Posted December 6, 2013 (edited) I check for an existing drive mapping on X using FileExists("X:") save it to a variable then map the path I need to X if DriveMapAdd("X:",$sDataPath,8,$sAuth,$sAuth) = 0 then _errDriveMapAdd(@error,@extended) once I'm finished with the mapped drive I return it to it's original mapping with _errDriveMapDel(DriveMapDel("X:")) if DriveMapAdd("X:",$sDataPath,8,$sAuth,$sAuth) = 0 then _errDriveMapAdd(@error,@extended) and below are the error checking functions func _errDriveMapDel($iRetVal) if $iRetVal = 0 Then msgbox(16,"ERROR - Drive Map Del","Unable to delete existing drive mapping - closing app") Exit EndIf EndFunc func _errDriveMapAdd($iError,$iExtended) $sTitle = "ERROR - Drive Map Add" Switch $iError Case 1 msgbox(16,$sTitle,"Undetermined Cause - Windows API returns error: " & $iExtended) Case 2 msgbox(16,$sTitle,"Access to the remote share was denied") Case 3 msgbox(16,$sTitle,"The drive letter or device is already assigned") Case 4 msgbox(16,$sTitle,"Invalid device name (must be a letter a-Z)") Case 5 msgbox(16,$sTitle,"Invalid remote share (bad path)") Case 6 msgbox(16,$sTitle,"Invalid password") EndSwitch Exit EndFunc The problem is that the drive labels in Windows Explorer are not changing when this drive mapping changes. The mapped drive points correctly to the new location but in Explorer it still shows the old drive label. Is there some way to force this to refresh? (note that starting a new instance of explorer still shows the old drive label also). Below is the full program: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.9.21 (Beta) Author: GruntyDatsun Script Function: Check if there is an existing X drive mapping, if so record it Remap X drive to \\server\path Launch APP On close of APP, remove the x drive mapping to \\server\path Restore pre-existing x drive mapping, if there was one 0.3 changed cmd map add/drops to DriveMapAdd and DriveMapDel added error detection and feedback ;~ problem: if there is an existing process using data in a mapped drive the windows command cannot unmap it. #ce ----------------------------------------------------------------------------ss local $sOldMap = "" local const $sAppPath = "G:\path\to\application" local const $sDataPath = "\\server\path\to\data" local const $sAuth = "user_same_as_pw_Shame" Switch FileExists("X:") Case 0 ;no existing x drive mapping - just map it if DriveMapAdd("X:",$sDataPath,8,$sAuth,$sAuth) = 0 then _errDriveMapAdd(@error,@extended) ;add drive mapping Case 1 $sOldMap = DriveMapGet("X:") ;get path of existing drive mapping if $sOldMap <> $sDataPath then ;if existing drive path matches proposed drive path _errDriveMapDel(DriveMapDel("X:")) ;delete existing drive mapping if DriveMapAdd("X:",$sDataPath,8,$sAuth,$sAuth) = 0 then _errDriveMapAdd(@error,@extended) ;add drive mapping EndIf EndSwitch if FileExists($sAppPath & "\APP.exe") Then ;if iSYS app exists on this path RunWait($sAppPath & "\APP.exe",$sAppPath) ;run iSYS app Else msgbox(16,"ERROR - Running iSYS","iSYS is not available on network path: " & $sAppPath & "\APP.exe") ;warn iSYS app not available on proposed path Exit EndIf func _errDriveMapDel($iRetVal) if $iRetVal = 0 Then msgbox(16,"ERROR - Drive Map Del","Unable to delete existing drive mapping - closing app") Exit EndIf EndFunc func _errDriveMapAdd($iError,$iExtended) $sTitle = "ERROR - Drive Map Add" Switch $iError Case 1 msgbox(16,$sTitle,"Undetermined Cause - Windows API returns error: " & $iExtended) Case 2 msgbox(16,$sTitle,"Access to the remote share was denied") Case 3 msgbox(16,$sTitle,"The drive letter or device is already assigned") Case 4 msgbox(16,$sTitle,"Invalid device name (must be a letter a-Z)") Case 5 msgbox(16,$sTitle,"Invalid remote share (bad path)") Case 6 msgbox(16,$sTitle,"Invalid password") EndSwitch Exit EndFunc Edited December 6, 2013 by gruntydatsun Link to comment Share on other sites More sharing options...
jdelaney Posted December 6, 2013 Share Posted December 6, 2013 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
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