Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/25/2012 in all areas

  1. Melba23

    Keyloggers

    The Forum Rules specifically mention that "keyloggers" are a prohibited subject on this forum. Of late we have had several threads locked because they have strayed (usually unwittingly) into keylogger territory. Here is a reminder of what Jon (the site owner) has set out as the basis for acceptability: "how to check for a few keys being pressed is one thing" We are not going to define "a few" in absolute terms, but if you post any code which checks for the best part of the keyboard you can be absolutely sure that you are in breach of the rules, that your thread will be locked, and that sanctions may follow. So please do not post such scripts - we do not want to be heavy-handed, but after this announcement your excuses had better be very good ones! M23
    1 point
  2. Skitty

    Ghost mouse?

    It all started back in 2007 (or somewhere around that time). There was a forum here dedicated to game botting and game automation. Long story short, it was overrun by angry at life, threatening and flaming teenagers and someone made the call to get rid of them. The end.
    1 point
  3. Valik

    Latest Beta

    This is why Jon didn't want to add ternary operators. If you do not know how to use them they make the code worse. I softened him somewhat on them by using them (correctly) to write AutoIt. Seeing code like that causes me to regret giving the green light to the feature, though.
    1 point
  4. ProgAndy

    Latest Beta

    And with the new ternary operator we do not have to rely on this sluggish conversion. (1=1)?1:0 ist much cleaner
    1 point
  5. Hey there Solarlight. I think I've got this fixed for you, and simplified this program WAY down. Everything has been rolled into one program with a single includes file #NoTrayIcon Opt("TrayMenuMode",1) $menu = TrayCreateItem("DriveLocker") $menu2 = TrayCreateItem("") $menuLock = TrayCreateItem("Lock Drive") $menuExit = TrayCreateItem("Exit") TraySetState() #include <eject.au3> While 1 $letter = DriveGetDrive("REMOVABLE") If IsArray($letter) Then For $i = 1 to $letter[0] _Check($letter[$i]) Next EndIf $time = TimerInit() While TimerDiff($time) < 60000 $msg = TrayGetMsg() TrayItemSetState($msg,4) Select Case $msg = $menuLock _LockDrive() Case $msg = $menuExit Exit EndSelect Sleep(100) WEnd WEnd Func _Check($strDriveLetter) If FileExists($strDriveLetter & "IAmLocked") Then _Unlock($strDriveLetter) EndFunc Func _Unlock($strDriveLetter) $strPassword = InputBox("Security Check", "Enter your password.", "", "*") If ($strPassword = "password") Then FileDelete($strDriveLetter & "IAmLocked") _ReAnimate($strDriveLetter) Else EjectVolume($strDriveLetter) EndIf EndFunc Func _ReAnimate($strDriveLetter) ; Put your reanimation batch calls here EndFunc Func _LockDrive() $letter = DriveGetDrive("REMOVABLE") If IsArray($letter) Then For $i = 1 To $letter[0] If MsgBox(36,"Lock This Drive?","Do you wish to lock the " & $letter[$i] & " drive?") = 6 Then FileWrite($letter[$i] & "IAmLocked","Locked") EjectVolume($letter[$i]) EndIf Next EndIf EndFunc Then, in your C:\Program Files\AutoIt3\Include\ directory, save this file as eject.au3 (I made some slight adjustments to the eject script you posted above from the previous example forum) #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinApi.au3> ;Prototypes ;BOOL EjectVolume(TCHAR cDriveLetter); ;HANDLE OpenVolume(TCHAR cDriveLetter); ;BOOL LockVolume(HANDLE hVolume); ;BOOL DismountVolume(HANDLE hVolume); ;BOOL PreventRemovalOfVolume(HANDLE hVolume, BOOL fPrevent); ;BOOL AutoEjectVolume(HANDLE hVolume); ;BOOL CloseVolume(HANDLE hVolume); ;StringFormat Output $szVolumeFormat = ".%s" $szRootFormat = "%s" $szErrorFormat = "Error %d: %sn" ;------------------------------------------ ;Arbitrary variables ;;Global Const $INVALID_HANDLE_VALUE = 0 ;------------------------------------------ ;DeviceIoControl Contants Global Const $FSCTL_LOCK_VOLUME = int(0x090018) Global Const $FSCTL_DISMOUNT_VOLUME = int(0x00090020) Global Const $IOCTL_STORAGE_EJECT_MEDIA = int(0x002D4808) Global Const $IOCTL_STORAGE_MEDIA_REMOVAL = int(0x002D4804) ;------------------------------------------ ;Retry Constants Global Const $LOCK_TIMEOUT = 10000 ; 10 Seconds Global Const $LOCK_RETRIES = 20 ;$OpenVolume = InputBox("Ejecting...", "Enter the drive to eject", "G:") ;ConsoleWrite("Trying to Eject the drive " & EjectVolume($OpenVolume) & @crlf) Func ReportError($szMsg) ConsoleWrite(StringFormat($szErrorFormat, _WinAPI_GetLastErrorMessage (), $szMsg) & @CRLF) Exit EndFunc ;==>ReportError Func OpenVolume($cDriveLetter) ;HANDLE hVolume ;UINT uDriveType ;TCHAR szVolumeName[8] ;TCHAR szRootName[5] ;DWORD dwAccessFlags $szRootName = StringFormat($szRootFormat, $cDriveLetter) $uDriveType = DriveGetType($szRootName); ConsoleWrite($szRootName & @tab & $uDriveType & @crlf) Switch $uDriveType Case "Removable" $dwAccessFlags = 6 Case "CDROM" $dwAccessFlags = 2 Case Else ConsoleWrite("Cannot eject. Drive type is incorrect." & @CRLF) Return $INVALID_HANDLE_VALUE EndSwitch $szVolumeName = StringFormat($szVolumeFormat, $cDriveLetter) ;$szVolumeName = $szVolumeFormat & $cDriveLetter ConsoleWrite($szVolumeName & @crlf ) $hVolume = _WinAPI_CreateFile ($szVolumeName, 2,$dwAccessFlags, 6) #cs hVolume = CreateFile( szVolumeName, dwAccessFlags, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); #ce If ($hVolume == $INVALID_HANDLE_VALUE) Then ReportError("CreateFile"); Return $hVolume; EndFunc ;==>OpenVolume Func CloseVolume($hVolume) Return _WinAPI_CloseHandle ($hVolume); EndFunc ;==>CloseVolume Func LockVolume($hVolume) Local $dwBytesReturned Local $dwSleepAmount Local $nTryCount local $iRead $dwSleepAmount = $LOCK_TIMEOUT / $LOCK_RETRIES; ; Do this in a loop until a timeout period has expired For $nTryCount = 0 To $nTryCount < $LOCK_RETRIES If _Device_Control($hVolume, $FSCTL_LOCK_VOLUME, $iRead) Then Return True Else Sleep($dwSleepAmount); EndIf Next Return False; EndFunc ;==>LockVolume Func DismountVolume($hVolume) ConsoleWrite("Dismount " & $hVolume & @crlf) Local $dwBytesReturned, $iRead local $aResult = _Device_Control($hVolume, $FSCTL_DISMOUNT_VOLUME, $iRead) ;msgbox(0,"",$aResult) Return $aResult ;Return $dwBytesReturned EndFunc ;==>DismountVolume Func PreventRemovalOfVolume($hVolume, $fPreventRemoval) Local $dwBytesReturned Local $aResult Local $lpInbuffer,$nInBufferSize,$lpOutBuffer,$nOutBufferSize,$lpOverlapped $PMRBUFFER = DllStructCreate("bool PreventMediaRemoval") DllStructSetData($PMRBUFFER,"PreventMediaRemoval",$fPreventRemoval) $lpBytesReturned = DllStructCreate("int Read") $pRead = DllStructGetPtr($lpBytesReturned, "Read") $aResult = Dllcall("kernel32.dll","int","DeviceIoControl","hwnd",$hVolume,"uint",$IOCTL_STORAGE_MEDIA_REMOVAL,"ptr",DllStructGetPtr($PMRBUFFER),"uint",DllStructGetSize($PMRBUFFER), _ "ptr",$lpOutBuffer,"uint",$nOutBufferSize,"ptr",$pRead,"ptr",$lpOverlapped) if $aResult = 0 then msgbox(0,"",_WinAPI_GetLastErrorMessage()) Return $aResult <> 0 ;& PMRBuffer, sizeof (PREVENT_MEDIA_REMOVAL), ;NULL, 0, ; & dwBytesReturned, ;NULL); EndFunc ;==>PreventRemovalOfVolume Func AutoEjectVolume($hVolume) Local $aResult, $iRead; $aResult = _Device_Control($hVolume, $IOCTL_STORAGE_EJECT_MEDIA, $iRead) Return $aResult EndFunc ;==>AutoEjectVolume Func EjectVolume($cDriveLetter) Local $hVolume; Local $fRemoveSafely = False; Local $fAutoEject = False; ; Open the volume. $hVolume = OpenVolume($cDriveLetter); If $hVolume == $INVALID_HANDLE_VALUE Then Return False ; Lock and dismount the volume. If LockVolume($hVolume) And DismountVolume($hVolume) Then $fRemoveSafely = True; ConsoleWrite("Volume Locked and Dismounted, trying to Eject " & @crlf) ; Set prevent removal to false and Eject the volume. If PreventRemovalOfVolume($hVolume, False) And AutoEjectVolume($hVolume) Then $fAutoEject = True; EndIf Else ConsoleWrite("Volume can't be locked or dismounted, please close possible opened files" & @crlf) EndIf ; Close the volume so other processes can use the drive. If CloseVolume($hVolume) = False Then Return False; EndIf If $fAutoEject Then ConsoleWrite(StringFormat("Media in drive %s has been ejected safely.n", $cDriveLetter)) Else If $fRemoveSafely Then ConsoleWrite(StringFormat("Media in drive %s can be safely removed.n", $cDriveLetter)) EndIf EndIf Return True; EndFunc ;==>EjectVolume Func _Device_Control($hDevice, $dwIoControlAutoit, ByRef $iRead) Local $aResult Local $lpInbuffer,$nInBufferSize,$lpOutBuffer,$nOutBufferSize,$lpOverlapped $tRead = DllStructCreate("int Data") $aResult = Dllcall("kernel32.dll","int","DeviceIoControl","hwnd",$hDevice,"uint",$dwIoControlAutoit,"ptr",$lpInBuffer,"uint",0, _ "ptr",$lpOutBuffer,"uint",0,"ptr",DllStructGetPtr($tRead),"ptr",$lpOverlapped) $iRead = DllStructGetData($tRead, "Data") ConsoleWrite("Device Control " & $iRead & @CRLF) Return $aResult<>0 EndFunc ;==>_Device_Control I'll give you a quick rundown of how this all works. 1) In lines 1 through 7 I'm creating a custom menu for your checker program that can be utilized by the system clock. You can use this to lock a drive or to exit the checker. On line 9, I'm including the eject.au3 file that I put in the second code block above. The main loop for your program is lines 11 through 30. In this look we start by pulling all of the removable drives attached to your system on line 12 and storing that to the $letter variable. On line 13, we check to ensure that we received an array back. If we didn't receive one, then we know there are no removable drives and there isn't anything more to do, so we can jump down to line 18. If we did find an array on line 13, we need to check every drive that was returned to see if it contains the locked file. That is where the For loop on lines 14-16 come into play. For each item in the $letter array, we run the _Check function. The check function simply does two things. It checks to see if your drive contains a file called "IAmLocked". If it does, calls the _Unlocked function, passing the drive letter that we already know is locked as its one parameter. If the drive doesn't have the "IAmLocked" file, then the unlock function is skipped and we continue on in the main function. Lets assume the drive is indeed locked and has that file present. The _Unlock function is then called. On line 37, we ask the user for a password to unlock the drive. We test that password on line 39. You can set your own password here to be whatever you like. If the password is correct, we delete the IAmLocked file on line 40 and we run the ReAnimate function on line 41. If we enter the password wrong, we call the EjectVolume function and pass it the drive letter. (This function is part of the include <eject.au3> file) Down in the _ReAnimate function, you can enter whatever logic you like here for your batch files to run. Just enter those commands on line 48. This takes you through the process of how to unlock your drive, and if that password attempt fails, the drive is ejected. This completes the main _Check function's needs and gets your program what you were looking for. I then took your program one step further by implementing a way to lock the removable drives again. Back up in the main function on line 18, we pull a timestamp. I prefer to use timestamps and timediffs in a loop rather than sleeping for a long period of time. This way we can still send menu commands and have the program respond to them without sleeping for minutes at a time. So, while the difference between the first timestamp and now is less than one minute (which is what that 60000 is set to), we'll poll the menu for either a Lock Drive command (on lines 23/24) or an Exit command (on lines 25/26). Exit is obviously easy to read. Lets take a look at the _LockDrive function down on lines 51 to 61. On line 52 we again pull for all the removable drives. We test to make sure that the $letter variable is an array on line 53, and if it is, we keep going. Otherwise the function ends. On 54-59, we loop through every letter in that array of drive letters. On 55, we are asking the user to "Lock this drive". If the user presses Yes, we write to the drive a file named "IAmLocked" (on line 56) and then eject the volume (on line 57). If the user presses No, then we simply move on to the next removable drive. And that completes your locking application. I hope you find the changes useful and the explanation informative. LvlUp
    1 point
  6. Valik

    Latest Beta

    Why would you even...? Never mind. I don't want to know.
    1 point
  7. Valik

    Latest Beta

    We will see how severe an impact this has. Right now my argument is you should have used better variable names including but not limited to some sort of type prefix. The implementation for functions as first-class objects does not involve pointers. It only provides pointer-to-function like semantics from the language side. Internally it's implemented completely differently. Do not concern yourself with implementation details. What matters is that the feature works sensibly and how people expect. Which it does, barring a bug or two.
    1 point
  8. Valik

    Latest Beta

    Yes, I intend to release a fully broken beta. /facepalm
    1 point
  9. Valik

    Latest Beta

    What the hell is all this non-sense about? ConsoleWrite("AutoIt version: " & @AutoItVersion & @CRLF) Local Writer = ConsoleWrite Writer("What the hell, this works?" & @CRLF) Writer = MyConsoleWrite Writer("This works, too!?" & @CRLF) Func MyConsoleWrite(sText) ConsoleWrite("MyConsoleWrite(): " & sText) EndFunc Output: AutoIt version: 3.3.9.5 What the hell, this works? MyConsoleWrite(): This works, too!? Tomorrow... maybe...
    1 point
×
×
  • Create New...