找回密码
 加入
搜索
查看: 2301|回复: 4

[系统综合] [已解决] 如何判断分区是 写保护状态 或 不可写状态?

[复制链接]
发表于 2012-5-7 22:46:07 | 显示全部楼层 |阅读模式
本帖最后由 yhxhappy 于 2012-5-8 08:40 编辑

我试了 FileOpen 或 FileCopy,Iniwrite等方法,在不可写的分区内操作,都提示下图警告框:


我想能判断不可写又不弹出对话框。P版曾回答过类似问题:
判断是否有写入保护,发送IOCTL_DISK_IS_WRITABLE控制请求。

因水平有限,不知道上面说的方法什么用?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-5-7 23:52:03 | 显示全部楼层

Const $DISK_PATH = "\\.\H:"

Const $IOCTL_DISK_IS_WRITABLE = 0x70024
Const $GENERIC_READ = 0x80000000
Const $ERROR_WRITE_PROTECT = 19


Local $hDiskDrive, $iStatus

$hDiskDrive = DllCall("Kernel32.dll", "handle", "CreateFileW", "wstr", $DISK_PATH, "dword", $GENERIC_READ, "long", 3, "ptr", 0, "dword", 3, "long", 0, "handle", 0)
$hDiskDrive = $hDiskDrive[0]

$iStatus = DllCall("Kernel32.dll", "bool", "DeviceIoControl", "handle", $hDiskDrive, "dword", $IOCTL_DISK_IS_WRITABLE, "ptr", 0, "long", 0, "ptr", 0, "long", 0, "long*", 0, "ptr", 0)

If $iStatus[0] Then
        MsgBox(48, "OK", StringFormat("'%s' is writable.", $DISK_PATH))
Else
        $iStatus = DllCall("Kernel32.dll", "long", "GetLastError")

        If $iStatus[0] = $ERROR_WRITE_PROTECT Then
                MsgBox(48, "OK", StringFormat("'%s' is read-only.", $DISK_PATH))
        Else
                MsgBox(48, "Error", StringFormat("Cannot determine, error code: %d", $iStatus[0]))
        EndIf
EndIf

DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hDiskDrive)
发表于 2012-5-8 08:02:35 | 显示全部楼层
谢 谢 代 码.
发表于 2012-5-8 08:22:10 | 显示全部楼层
回复 1# yhxhappy
2楼超版已经给出解答,建议楼主将贴修改为“已解决”
 楼主| 发表于 2012-5-8 08:41:32 | 显示全部楼层
感谢P版的代码
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-4 10:18 , Processed in 0.077087 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表