我想制作一个取证工具,并获得以下代码以弹出驱动器,但是在pycharm/console
中以管理员身份运行时,访问被拒绝
代码:
import win32api, win32gui, win32con, win32file, struct
def wapi():
FSCTL_LOCK_VOLUME = 0x0090018
FSCTL_DISMOUNT_VOLUME = 0x00090020
IOCTL_STORAGE_MEDIA_REMOVAL = 0x002D4804
IOCTL_STORAGE_EJECT_MEDIA = 0x002D4808
lpFileName = "H:/"
dwDesiredAccess = win32con.GENERIC_READ|win32con.GENERIC_WRITE
dwShareMode = win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE
dwCreationDisposition = win32con.OPEN_EXISTING
hVolume = win32file.CreateFile(lpFileName, dwDesiredAccess, dwShareMode, None, dwCreationDisposition, 0, None)
win32file.DeviceIoControl(hVolume, FSCTL_LOCK_VOLUME, "", 0, None)
win32file.DeviceIoControl(hVolume, FSCTL_DISMOUNT_VOLUME, "", 0, None)
try:
win32file.DeviceIoControl(hVolume, IOCTL_STORAGE_MEDIA_REMOVAL, struct.pack("B", 0), 0, None)
win32file.DeviceIoControl(hVolume, IOCTL_STORAGE_EJECT_MEDIA, "", 0, None)
except():
raise
finally:
win32file.CloseHandle(hVolume)
if __name__ == '__main__':
wapi()
错误:
hVolume = win32file.CreateFile(lpFileName, dwDesiredAccess, dwShareMode, None,dwCreationDisposition, 0, None) pywintypes.error: (5, 'CreateFile', 'Access is denied.')