Sign in to follow this  
Followers 0
JellyFish666

Convert to Autoit

1 post in this topic

#1 ·  Posted (edited)

#DefineFunction LockMedia(DriveLetterAndColon, LockSetting) 
    IntControl(73, 1, 0, 0, 0)
    INVALID_HANDLE_VALUE = -1
    OPEN_EXISTING = 3
    FILE_ATTRIBUTE_NORMAL = 128
    FILE_SHARE_WRITE = 2
    GENERIC_READ = 2147483648
    IOCTL_STORAGE_MEDIA_REMOVAL = 2967556
    

    ;Fuction for (un)locking Media inside a removable storage drive
    ;DriveLetterAndColon should be two characters WITHOUT a trailing 
    ;backslash, ex: "D:"
    ;LockSetting specifies if we want to lock the media in the drive (True) 
    ;or unlock it (False)
    ;Returns True if it succeeds and False if it fails
    ;CreateFile will probably fail on Win9x systems so this function is only 
    ;intended for use on NT 4 and greater
    drivepath = StrCat("\\.\", DriveLetterAndColon)
    DaDll=strcat(DirWindows(1),"kernel32.dll")
    hDrive=DllCall(DaDll,long:"CreateFileA",lpstr:drivepath,long:GENERIC_READ,long:FILE_SHARE_WRITE,lpnull, long:OPEN_EXISTING, long:FILE_ATTRIBUTE_NORMAL, lpnull)
    If hDrive <> INVALID_HANDLE_VALUE 
        lpLock = BinaryAlloc(4)
        BinaryPoke(lpLock,0,locksetting)
        LockSz = BinaryEodGet(lpLock)
            lpReturnedBytes = BinaryAlloc(4)
        LockMediaRslt = DllCall(DaDll,long:"DeviceIoControl",long:hDrive, long:IOCTL_STORAGE_MEDIA_REMOVAL, lpbinary:lpLock, long:LockSz, long:0, long:0, lpbinary:lpReturnedBytes, lpnull)
        LastErr = DllLastError()
        BinaryFree(lpLock)
        BinaryFree(lpReturnedBytes)
        DllCall(DaDll,long:"CloseHandle",long:hDrive)  ;Clean up after outselves
        if LockMediaRslt == 0
           Message("DeviceIoControl Failed with Error",LastErr)
            Return 0
        Endif 
        Return 1
    Endif
    Return 0

    :WBERRORHANDLER
    if hDrive !=0 then DllCall(DaDll,long:"CloseHandle",long:hDrive)  
    if IsDefined(lpLock) then BinaryFree(lpLock)
    if IsDefined(lpReturnedBytes) then BinaryFree(lpReturnedBytes)
    Message("Error Occured on line",wberrorhandlerline)
    Return 0

#EndFunction

;Grab CDROM Drive letter
CDROMLIST = DiskScan (8)
CDROM = ItemExtract(1,CDROMLIST,@TAB)


;Lock CDROM Drive
ret = LockMedia(CDROM, @True)

Pause("Check CDROM Drive","The CDROM drive %CDROM% should now be locked")

;UnLock CDROM Drive 
ret = LockMedia(CDROM, @False) 

Pause("Check CDROM Drive","The CDROM drive %CDROM% should now be unlocked")
exit

This website has code but not sure how to convert most of it...

anyway to convert it to Autoit :)

Edited by JellyFish666

Share this post


Link to post
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
Sign in to follow this  
Followers 0