Jump to content

Recommended Posts

Posted

The following script is just me testing the new DriveMap* functions, and is really all about the UDF _MapDrive.

When I run the calls to _MapDrive which are commented out, everything works as expected. But when I run the code asis, which just assigns the same drive sequentially to different shares, I get unexpected results after the 1st call to _MapDrive: the 2nd DriveMapDel doesn't report an error, yet the assignment fails. And notice that when the 3rd call runs, it confirms that the 2nd DriveMapDel was indeed successful.

I'm expecting all 3 calls to work successfully. I've also tried putting Sleep()s in all over the place .. up to Sleep(1000) even. But all to no avail. Is there something obvious I'm missing? Or is it maybe just one of thoes quirky NT things?

:)

Here's the code:

;----------------------------------------------------------------------
;DriveMaps
;----------------------------------------------------------------------
    _Debug("#ds");open log window

;This works okay..
;    _MapDrive("L:","\\NTFS001\livereports")
;    _MapDrive("S:","\\NTFS002\d")
;    _MapDrive("U:","\\NTFS003\inetpub")

;This doesn't ..
    _MapDrive("U:","\\NTFS001\livereports")
    _MapDrive("U:","\\NTFS002\d")
    _MapDrive("U:","\\NTFS003\inetpub")

    _Debug("#de");keep log window open until you close it

Func _MapDrive($psDrive, $psPath)

    _Debug("Map Requested:: " & $psDrive & " --> " & $psPath)
    
    $sX = DriveMapGet($psDrive)
    _Debug(@TAB & "Initially = """ & $sX & """")
    
    If Not DriveMapDel($psDrive) Then
        _Debug(@TAB & "### DriveMapDel Failed for '" & $psDrive & "' ###")
    Endif
    
    _Debug(@TAB & "Attempting map...")
    $nRC = DriveMapAdd($psDrive, $psPath , 1)
    $nErr = @ERROR
    
    Select  
        Case $nErr =  0 
            _Debug(@TAB & "*** SUCCESS ***") 
        Case $nErr =  1 
            _Debug(@TAB & "*** Undefined / Other error ***") 
        Case $nErr =  2 
            _Debug(@TAB & "*** Access to the remote share was denied ***")
        Case $nErr =  3 
            _Debug(@TAB & "*** The device is already assigned ***")
        Case $nErr =  4 
            _Debug(@TAB & "*** Invalid device name ***")
        Case $nErr =  5 
            _Debug(@TAB & "*** Invalid remote share ***")
        Case $nErr =  6 
            _Debug(@TAB & "*** Invalid password ***")
    EndSelect
    
EndFunc

Func _Debug($message)
;From Cyberslug, circa 2004-05-10
;Until AutoIt gets full debugging features, the following might help some people:
;
;    Example usage:
;    _Debug('#ds');open log window
;   ; start of script goes here...
;    _Debug("The value of some variable foo is:" & $foo)
;    _Debug("Another debug message")
;   ; end of script...
;    _Debug('#de');keep log window open until you close it
    
    If $message = "#ds" Then
        $sAutoItWinGetTitle = AutoItWinGetTitle()
        WinActivate ( $sAutoItWinGetTitle )
        WinSetState ( $sAutoItWinGetTitle, "", @SW_SHOW )
        WinMove     ( $sAutoItWinGetTitle, "", @DESKTOPWIDTH / 3, @DESKTOPHEIGHT / 3, @DESKTOPWIDTH / 3, @DESKTOPHEIGHT / 3 )
    ElseIf $message = "#de" Then
        WinWaitClose(AutoItWinGetTitle())
    Else
        Local $previous = ControlGetText( AutoItWinGetTitle(),"", "Edit1")
        ControlSetText( AutoItWinGetTitle(),"", "Edit1", $previous & $message & @CRLF)
        ControlSend( AutoItWinGetTitle(),"", "Edit1", "^{END}")
    EndIf
   
EndFunc

And here are the results:

Map Requested:: U: --> \\NTFS001\livereports
    Initially = ""
    ### DriveMapDel Failed for 'U:' ###
    Attempting map...
    *** SUCCESS ***
Map Requested:: U: --> \\NTFS002\d
    Initially = "\\NTFS001\livereports"
    Attempting map...
    *** The device is already assigned ***
Map Requested:: U: --> \\NTFS003\inetpub
    Initially = ""
    ### DriveMapDel Failed for 'U:' ###
    Attempting map...
    *** The device is already assigned ***
Posted

I may be completly off on this but I was thinking since AutoIt is the worlds fastest USER that maybe you are going to fast for the operating system. It is successfully disconnecting from the drive but you might be requesting the same drive letter too quickly. Try to put the following in after you DriveMapDel:

While Not( DriveMapGet([i]letter[/i]) = "" )
   Sleep(1)
Wend

It is just a thought. Like I said it may be way off.

*** Matt @ MPCS

  • Developers
Posted (edited)

seems to be a bug... here are the findings:

DriveMapAdd errors out on ERROR_DEVICE_ALREADY_REMEMBERED after the first DriveMapDel.

Changed the following code:

AUT_RESULT AutoIt_Script::F_DriveMapDel(VectorVariant &vParams, Variant &vResult)
{
    DWORD res = WNetCancelConnection2(vParams[0].szValue(), 0, TRUE);

to

AUT_RESULT AutoIt_Script::F_DriveMapDel(VectorVariant &vParams, Variant &vResult)
{
    DWORD res = WNetCancelConnection2(vParams[0].szValue(), CONNECT_UPDATE_PROFILE, TRUE);

Which solved it ....

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Did you submit your changes to Jon so this gets added to the unstable?

I'm just glad that I wasn't too far off on this one. Good luck with the changes when they are released Trids!

*** Matt @ MPCS

Posted

Thanks folks - thought I was going mad or blind!

@Matt .. yep - I was even putting Sleep(1000)s after just about every statement! I was getting desperate :)

@JdeB .. thanks for restoring order to my world :)

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
  • Recently Browsing   0 members

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