GEOSoft Posted May 15, 2008 Share Posted May 15, 2008 This is just the functions where I have finished the header info. There are more to come after I finished writing the headers for them and that will not be today. NOTE: I will be removing this code at a later date and replacing it with the link to the page on my web site. (cuts down on post size).Download Drive.zipPlease report any errors that you find.expandcollapse popup; #include-once ;============================================================================== ; Function list: ; _Drive_CD_MediaLoaded() ; _Drive_DefragVol() ; _Drive_IsFloppy() ; _Drive_Optical_Type() ; ; ;============================================================================== ;=============================================================================== ; Function Name: _Drive_CD_MediaLoaded() ; Description: Determine if there is media in a cd or dvd drive ; Syntax: _Drive_CD_MediaLoaded() ; Parameter(s): $Drive - Drive to Check ; $Computer - Computer on which the drive is installed (default = localhost) ; Requirement(s): ; Return Value(s): Success - Media Loaded Status ; Failure - Sets @Error to 1 ; Author(s): George (GEOSoft) Gedye ; Modification(s): ; Note(s): In the example below, change G: to the actual drive to check ; Example(s): $L_Status = "Loaded" ; If NOT _Drive_CD_MediaLoaded("G:") Then $L_Status = "Not Loaded" ; If @Error Then ; MsgBox(0, "Error", "Drive is not a CD drive") ; Else ; MsgBox(0, "Media Status", "Status = " & $L_Status) ; EndIf ;=============================================================================== Func _Drive_CD_MediaLoaded($Drive, $Computer = ".") $Drive = StringReplace(StringUpper($Drive), "\", "") If StringRight($Drive, 1) <> ":" Then $Drive &= ":" If DriveGetType($Drive &"\") <> "CDROM" Then Return SetError(1) $Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2") $Items = $Obj_CD.ExecQuery("SELECT * FROM Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39), "WQL", 0x10 + 0x20) If IsObj($Items) then For $Item in $Items If $Item.MediaLoaded Then Return 1 Return 0 Next Endif EndFunc ;<==> _Drive_CD_MediaLoaded() ;============================================================================== ; Function Name: _Drive_DefragVol() ; Description: Defrag a drive volume on Windows Server 2003 or 2008 (NOT for use on XP or Vista) ; Syntax: _Drive_DefragVol($sVol, $Computer = ".") ; Parameter(s): $Drive - The drive to check. This MUST include the colon (eg. a: ; $Computer - The network computer to check (Default is localhost) ; Requirement(s): ; Return Value(s): Success - Defragments the volume ; Failure - Sets @Error to 1, volume could not be defragmented ; Author(s): George Gedye (GEOSoft) geog AT mvps DOT org ; Note(s): (NOT for use on XP or Vista) ;============================================================================== Func _Drive_DefragVol($sVol, $Computer = ".") If (@OSVersion = "WIN_2003" AND @OSBuild = "3790") OR (@OSVersion = "WIN_2008") Then $sVol = Chr(39) & StringLeft($sVol, 2) & "\\" $objWMIService = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2") $colVolumes = $objWMIService.ExecQuery ("Select * from Win32_Volume Where Name = " & $sVol &"'") For $objVolume in $colVolumes $errResult = $objVolume.Defrag() Next Return $errResult EndIf Return SetError(1) EndFunc ;<==> _Drive_DefragVol() ;============================================================================== ; Function Name: _Drive_IsFloppy() ; Description: Determines if a drive is a floppy drive ; Syntax: _Drive_IsFloppy($Drive, $Computer = ".") ; Parameter(s): $Drive - The drive to check. This MUST include the colon (eg. a: ; $Computer - The network computer to check (Default is localhost) ; Requirement(s): ; Return Value(s): 1 - $Drive is a Floppy drive, 0- $Drive is not a Floppy drive ; Author(s): George Gedye (GEOSoft) goeg AT mvps DOT org ;============================================================================== Func _Drive_IsFloppy($Drive, $Computer = ".") $Drive = StringReplace($Drive, "\", "") Local $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & $Computer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE MediaType = '5'", "WQL", 0x30) If IsObj($colItems) then For $objItem In $colItems If $objItem.DeviceID = $Drive Then Return 1 Else Return 0 EndIf Next Endif EndFunc ;<==> _Drive_IsFloppy() ;============================================================================== ; Function Name: _Drive_Optical_Type() ; Description: Retrieve the type of drive (CD, DVD, Virtual &etc.) ; Syntax: _Drive_Optical_Type( $Drive, [$Computer] ) ; Parameter(s): $Drive - The drive to check. This MUST include the colon (eg. a: ; $Computer - The network computer to check (Default is localhost) ; Requirement(s): WMI capable system ; Return Value(s): Success - Returns the drive type ; Author(s): George Gedye (GEOSoft) geog AT mvps DOT org ; Example(s): ; $Drives = DriveGetDrive("CDROM") ; ; For $I = 1 To Ubound($Drives) -1 ; MsgBox(0, "Test", "Drive " & StringUpper($Drives[$I]) & " is a " & _Drive_Optical_Type($Drives[$I])) ; Next ;============================================================================== Func _Drive_Optical_Type( $Drive, $Computer = ".") If DriveGetType($Drive) <> "CDROM" Then Return SetError(1) Local $oRtn = "" $Drive = StringUpper($Drive) $Obj_CD = ObjGet("winmgmts:\\" & $Computer & "\root\cimv2") $Items = $Obj_CD.ExecQuery("Select * from Win32_CDROMDrive WHERE Id = '" & $Drive & Chr(39)) For $Item in $Items $oRtn = StringMid($Item.DeviceID, StringInStr($Item.DeviceID, "_")+1) If StringInStr($oRtn, "Virtual") Then $oRtn = StringMid($oRtn, StringInStr($oRtn, "Virtual")) $oRtn = StringReplace($oRtn, "_", " ", 1) $oRtn = StringLeft($oRtn, 15) Else $oRtn = StringLeft($oRtn, StringInStr($oRtn, "_") -1) EndIf Next If $oRtn = "" Then Return SetError(1) Return $oRtn EndFunc ;<==> _Drive_Optical_Type() ; George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now