Jump to content
stefanwue

my Diskpart Script have no Drives in Listbox

Recommended Posts

stefanwue

Hello all

i have a problem with this script i have no drives in the listbox why ???? can you help me please ?

sorry fo my bad english.

#include <GUIConstantsEx.au3>
#include <String.au3>

$File = FileOpen(@TempDir & '\lstdsk.ini', 2)
FileWrite($File, 'list disk')
FileClose($File)
RunWait('cmd /c diskpart /s lstdsk.ini > lstdsk.txt', @TempDir, @SW_HIDE)
Example()

Func Example()
    Local $Menu1, $n1, $n2, $Msg, $Menustate, $Menutext, $File
    Local $Line, $Array = _StringExplode(FileRead(@TempDir & '\lstdsk.txt'), @LF)
    For $i = 0 To UBound($Array) - 1
        If StringRegExp($Array[$i], '(?i)Disk [\d]+') Then $Line &= $Array[$i] & '|'
    Next
    $Line = StringRegExpReplace($Line, '[\s|]*$', '') ;trim spaces, returns, line breaks, and pipes from end of the string
    GUICreate('Select Disk To Format', 260, 250) ; will create a dialog box that when displayed is centered
    GUICtrlCreateLabel('Avaliable Disks', 22, 10, 100)
    $n1 = GUICtrlCreateList('', 20, 30, 215, 150)
    GUICtrlSetData(-1, $Line)
    $n2 = GUICtrlCreateButton('Select This Disk to Format', 28, 200, 200)
    GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
    GUISetState() ; will display an empty dialog box
    ; Run the GUI until the dialog is closed
    Do
        $Msg = GUIGetMsg()
        If $Msg = $n2 Then
            Local $Disk = StringRegExpReplace(GUICtrlRead($n1), '(?i)^.*(Disk [\d]+).*$', '$1')
            Local $iMsgBoxAnswer
            $iMsgBoxAnswer = MsgBox(262452, 'Selected Drive To Format is: ' & $Disk, 'Proceed with Format of ' & $Disk & '?')
            Select
                Case $iMsgBoxAnswer = 6 ;Yes
                    _Format($Disk)
                Case $iMsgBoxAnswer = 7 ;No

            EndSelect
        EndIf
    Until $Msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func _Format($Drive)
    GUISetState(@SW_HIDE)
    Local $String, $Text = 'This is the script that you can send to diskpart' & @LF & 'The file is located at: ' & @TempDir & '\format.txt'
    $String &= 'Select ' & $Drive & @CRLF
    $String &= 'Clean' & @CRLF
    $String &= 'Create Partition Primary' & @CRLF
    $String &= 'Select Partition 1' & @CRLF
    $String &= 'Format fs=NTFS Quick' & @CRLF
    $String &= 'Active' & @CRLF
    $String &= 'Exit'
    $File = FileOpen(@TempDir & '\format.txt', 2)
    FileWrite($File, $String)
    FileClose($File)
    ShellExecute(@TempDir & '\format.txt', '', '', 'open')
    MsgBox(262144, 'Diskpart Script Created for ' & $Drive, $Text)
    GUISetState()
EndFunc   ;==>_Format

 

Edited by stefanwue

Share this post


Link to post
Share on other sites
HankHell

well, diskpart is ran from a separate shell... the way I got around it was to offload it to a new .txt document in %temp%, then run the script using diskpart /s location ...mind you it's .bat code taken from

:List_HDD
        echo.>"%temp%\FixerUpperListDisk.txt"
        echo list volume > "%temp%\FixerUpperListDisk.txt"
            diskpart /s "%temp%\FixerUpperListDisk.txt" > "%temp%\FixerUpperDiskpartListDisk.txt"
            type "%temp%\FixerUpperDiskpartListDisk.txt"
            echo.
            del /f "%temp%\FixerUpperListDisk.txt"
            del /f "%temp%\FixerUpperDiskpartListDisk.txt"
            goto Skip_CLS_Partition_Manager

 

Edited by HankHell

Share this post


Link to post
Share on other sites
careca
1 hour ago, stefanwue said:

i have no drives in the listbox why?

I do, your script works fine here. try #requireadmin


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

×