Jump to content

Recommended Posts

I had problem differentiating drives of system and External drives as they're both of same type - "FIXED" when using DriveGetDrive and DriveGetType, so managed to make a small script to detect External ones.

Im a newb, so you may will find silly, unnecessary code which could have been done better with smart work instead of hard work, if you know what i mean :sweating:

#include <Array.au3>

Local $drivelist = DriveGetDrive("FIXED"), $addspace = 0, $getspace, $systemdrives, $externaldrives
;~ _ArrayDisplay($drivelist)
findexthdd()

Func findexthdd()
RunWait(@ComSpec & " /c " & 'wmic diskdrive get PNPDeviceID, size /format:csv | find /v "USBSTOR" > wmic.txt', @ScriptDir, @SW_HIDE)
$file = FileOpen("wmic.txt")
$readfile = FileRead($file)

$readfile = StringSplit($readfile, ",")
;~ _ArrayDisplay($readfile)
$last = $readfile[0]
$totalsize = $readfile[$last]
$totalsize = $totalsize / 1024 / 1024 / 1024 ;MB
Do
Local $c = 1
$totalsize = StringTrimRight($totalsize, $c)
$c = $c + 1
$return = StringInStr($totalsize, ".")
Until $return = 0
$return = 1

For $w = 1 To UBound($drivelist) - 1
$getspace = DriveSpaceTotal($drivelist[$w]) / 1024
Do
Local $z = 1
$getspace = StringTrimRight($getspace, $z)
$z = $z + 1
$return = StringInStr($getspace, ".")
Until $return = 0
$addspace += $getspace
If $addspace <= $totalsize Then ;463 vs 465
$systemdrives &= $drivelist[$w] & ","
Else
;~ MsgBox(0, "", $drivelist[$w] & " is the f****** external hard drive!")
$externaldrives &= $drivelist[$w] & ","
EndIf
Next

$systemdrives = StringTrimRight($systemdrives, 1)
$systemdrives = StringSplit($systemdrives, ",")
_ArrayDisplay($systemdrives, "SYSTEM DRIVES LIST")

$externaldrives = StringTrimRight($externaldrives, 1)
$externaldrives = StringSplit($externaldrives, ",")
_ArrayDisplay($externaldrives, "EXTERNAL DRIVES LIST")
EndFunc ;==>findexthdd
Link to comment
Share on other sites

There's nothing wrong with your method at all. Some might say it's not foolproof because it relies on WMI being enabled on the target system (which is the default, but can be disabled).

I wrote a UDF for a different purpose some time ago, but it can gather the information you need, it even has an _IsUSBHDD test to do exactly what you want. Maybe you'll find it useful as well.

Link to comment
Share on other sites

Interesting ! :)

Works well

I have tried to simplify you code a bit.

#include <Array.au3>

$aExternalDrives = _FindExtHdd()
_ArrayDisplay ( $aExternalDrives, "EXTERNAL DRIVES LIST" )

Func _FindExtHdd()
    Local $iPid, $sStdout, $iTotalSize, $sGetSpace, $addspace, $externaldrives
    $iPid = Run ( @ComSpec & ' /c wmic diskdrive get PNPDeviceID, size /format:csv | find /v "USBSTOR"', '', @SW_HIDE, 2 )
    While ProcessExists ( $iPid )
        $sStdout &= StdoutRead ( $iPid )
    Wend
    $sStdout = StringSplit($sStdout, ",")
    $iTotalSize = $sStdout[$sStdout[0]] / 1024 / 1024 / 1024 ; GB
    Do
        $iTotalSize = StringTrimRight($iTotalSize, 1 )
    Until Not StringInStr($iTotalSize, ".")
    Local $aDriveList = DriveGetDrive("FIXED")
    For $w = 1 To UBound($aDriveList) - 1
        $sGetSpace = DriveSpaceTotal($aDriveList[$w]) / 1024
        Do
            $sGetSpace = StringTrimRight($sGetSpace, 1 )
        Until Not StringInStr($sGetSpace, ".")
        $addspace += $sGetSpace
        If $addspace > $iTotalSize Then $externaldrives &= $aDriveList[$w] & ","
    Next
    $externaldrives = StringTrimRight($externaldrives, 1)
    If $externaldrives Then Return StringSplit($externaldrives, ",", 1)
EndFunc ;==>_FindExtHdd

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Hello abaddon7734,

why don't you make it wider, and have listed internal and external in one gui? ListView or something.

All i get when i run this, is a list of the drives i got, all represented as external.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Search "is service running".

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@careca :oops: Its not working? What is your OS and is wmic enabled and working in your system? And tried the code posted by wakillon ?

No, Win7 x64, Yes and Yes, Tested it again right now, and it shows all disks as external and a usb pen doesn't appear.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

This shows my second internal hard drive and a USB hard drive as external.

@careca

This function isn't designed to detect thumb drives, only external hard drives.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This shows my second internal hard drive and a USB hard drive as external.

This is exactly what i was afraid of! This script is working for system with single Hard drive.

An output of

RunWait(@ComSpec & " /c " & 'wmic diskdrive get PNPDeviceID, size /format:csv | find /v "USBSTOR" > wmic.txt', @ScriptDir, @SW_HIDE)

will yield output like:

Node,PNPDeviceID,Size
X-7068F8D674B94,IDE\DISKST500DM002-1BD142_______________________KC44____\5&amp;2BEE401B&amp;0&amp;0.0.0,500105249280

from which we have to get the size part: 500105249280

But assuming there is a second internal hard drive, output will be like:

Node,PNPDeviceID,Size
X-7068F8D674B94,IDE\DISKST500DM002-1BD142_______________________KC44____\5&amp;2BEE401B&amp;0&amp;0.0.0,500105249280
X-7068F8D674B94,IDE\DISKST500DM002-1BD142_______________________KC44____\5&amp;2BEE401B&amp;0&amp;0.0.0,1000194048000

from which we will have to get 500105249280 + 1000194048000

Hmmmm :think:

Link to comment
Share on other sites

Yeah, i have 5 internal hdds and all show as external.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
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
 Share

×
×
  • Create New...