Jump to content

_WinAPI_IsWritable not correct?


Recommended Posts

Hi all,

Two questions!

First, the example in help docs for _WinAPI_IsWritable doesn't appear to give the desired results for me.

In Windows 7, with me as an administrator and UAC disabled, it tells me that all my local hard drives are not writable. Is this a bug, or am I using the example incorrectly somehow?

Second, if it was working... it doesn't appear to be valid for network drives. Is there an equivalent function for network drives?

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

Link to comment
Share on other sites

  • Moderators

MrBeatnik,

When I look inside the function it seems to me that the flag to detect if the disk is write-protected is working in the reverse sense - I will consult with the Devs and get back to you. :wacko:

Could you please test this modified function and see if it works for you - it does for me: :)

#include <WinAPIFiles.au3>

Local $aDrive = DriveGetDrive('ALL')

If IsArray($aDrive) Then
    Local $sText
    For $i = 1 To $aDrive[0]
        If _WinAPI_IsWritable_Mod($aDrive[$i]) Then
            $sText = 'Writable'
        Else
            $sText = 'Not writable'
        EndIf
        If Not @error Then
            ConsoleWrite(StringUpper($aDrive[$i]) & ' => ' & $sText & @CRLF)
        EndIf
    Next
EndIf

Func _WinAPI_IsWritable_Mod($sDrive)
    Local $hFile = _WinAPI_CreateFileEx('\\.\' & $sDrive, $OPEN_EXISTING, 0, $FILE_SHARE_READWRITE)
    If @error Then Return SetError(@error + 20, @extended, False)

    Local Const $ERROR_WRITE_PROTECT = 19 ; The media is write protected
    Local $aRet = DllCall('kernel32.dll', 'bool', 'DeviceIoControl', 'handle', $hFile, 'dword', 0x00070024, 'ptr', 0, 'dword', 0, _
            'ptr', 0, 'dword', 0, 'dword*', 0, 'ptr', 0)
    If __CheckErrorCloseHandle($aRet, $hFile, 1) <> 10 And @extended = $ERROR_WRITE_PROTECT Then Return SetError(@error, @extended, False)
    Return $aRet[0]
EndFunc   ;==>_WinAPI_IsWritable_Mod
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

MrBeatnik,

It seems I was correct - the function will be changed for future releases. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...