Jump to content

Search the Community

Showing results for tags 'Power Status'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office


  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Member Title




Found 1 result

  1. For those of us with more than one hard drive, and with power management options enabled for disks, you might find yourself in the same situation as I've been in - asking the question 'Is that drive really powered down?'. I coded up the below example to get that information to you. Note that it reads power states for ALL drives, and the status information for removable & virtual drives will either show up as 'Unknown' or Powered-On. As a courtesy, please be sure to credit me or keep the UDF header intact if you use the code ; =============================================================================================================================== ; <DrivesPowerStatus.au3> ; ; Reports the Power status for all drives. ; ; Functions: ; _DriveGetPowerState() ; Returns a boolean indicating drive status (True=active, False=low power or powered-off) ; ; Author: Ascend4nt ; =============================================================================================================================== #include <Array.au3> Local $aDrives,$aDevInfo $aDrives=DriveGetDrive("ALL") ; returns array of 'drive:' with lower-case letters If @error Then Exit ; Create 2D array - 2nd column will carry the Power State info, 3rd Drive Type Dim $aDriveStates[$aDrives[0]+1][3] ; Copy over drives and get Power States For $i=1 To $aDrives[0] $aDriveStates[$i][0]=StringUpper($aDrives[$i]) $aDriveStates[$i][1]=_DriveGetPowerState($aDrives[$i]) If @error Then $aDriveStates[$i][1]="Unknown" $aDriveStates[$i][2]=DriveGetType($aDrives[$i]) Next $aDriveStates[0][0]="Drive" $aDriveStates[0][1]="Active Power State?" $aDriveStates[0][2]="Drive Type" _ArrayDisplay($aDriveStates,"Drives Power Status") ; =================================================================================================================== ; Func _DriveGetPowerState($sDrive) ; ; Returns a boolean representing the active power state of the given drive. ; True = Active (powered on, active), False = Inactive (either powered off, or in a low power state) ; ; $sDrive = Drive letter, or full path (only the Drive letter is extracted from the string) ; ; Returns: ; Success: True/False ; Failure: -1, with @error set: ; @error = 1 = invalid parameter ; @error = 2 = DLLCall error. @extended contains DLLCall error code (see AutoIt Help) ; @error = 3 = API call error. Call 'GetLastError' for more info ; ; Author: Ascend4nt ; =================================================================================================================== Func _DriveGetPowerState($sDrive) $sDrive=StringLeft($sDrive,1) If StringIsAlpha($sDrive)=0 Then Return SetError(1,0,-1) ; Device path for logical drives: '\\.\C:' Local $iErr,$aRet,$hDisk,$sDevicePath='\\.\'&$sDrive&':' #cs ; API call params: [0 Access (for metadata & device info),3 ShareMode for 'Read'+'Write', ; 0 (NULL) SecurityAttribs (i.e. none),3 CreationDisposition for 'OpenExisting',0 Flags,0 (NULL) TemplateFile] ; *We could also use _WinAPI_CreateFile($sDevicePath,2,8,6), but there's no guarantee that '8' as the 3rd param ; will continue to work (its currently a sort of 'hack' to work around the limitations of the UDF [to force AccessMode to 0]) #ce $aRet=DllCall('kernel32.dll','handle','CreateFileW','wstr',$sDevicePath,'dword',0,'dword',3,'ptr',0,'dword',3,'dword',0,'ptr',0) If @error Then Return SetError(2,@error,-1) If $aRet[0]=-1 Then Return SetError(3,0,-1) $hDisk=$aRet[0] ;~ ConsoleWrite("Handle for Drive '"&$sDrive&":' = "&$hDisk&@CRLF) $aRet=DllCall('kernel32.dll','bool','GetDevicePowerState','handle',$hDisk,'bool*',0) $iErr=@error ; We don't worry about whether this is successful, since there's nothing we can do about it: DllCall('kernel32.dll','bool','CloseHandle','handle',$hDisk) ; Error with GetDevicePowerState call? If $iErr Then Return SetError(2,$iErr,-1) If Not $aRet[0] Then Return SetError(3,0,-1) ;~ ConsoleWrite("$aRet[2]="&$aRet[2]&@CRLF) Return ($aRet[2]<>0) EndFunc
  • Create New...