Wingens

Error in Windows PE

22 posts in this topic

#1 ·  Posted

Hi,

I am creating a script that will allow me to boot from usb and install an image to workstations when we are on locations outside the office.

When i run the script in Windows it works like a charm, when i run the script using Windows PE 10 it gives an error.

Below is my code, the error happend when i added the disk combo box. This we need because sometimes the external hard drive is shown as disk 0 which we first used in diskpart.

What happend then is the external drive with the images is formated and all the images are gone :)

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <ComboConstants.au3>

#NoTrayIcon

WinSetState("[CLASS:ConsoleWindowClass]", "", @SW_HIDE)

GUICreate("Image from USB", 385, 108, 720, 459)

$CHOSENIMAGE = GUICtrlCreateInput("Kies image...", 20, 8, 305, 21)
$SELECTIMAGE = GUICtrlCreateButton("...", 328, 8, 35, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$DISK = GUICtrlCreateCombo("Kies schijf...", 20, 40, 305, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
    GUICtrlSetData($DISK, "==============================================================")

    $myinfos = _GetDriveInfos()
        Local $sResult = ""
            For $i = 0 to UBound($myinfos) - 1
                $sResult &= $myinfos[$i][2] & " : " & $myinfos[$i][1] & " : " & $myinfos[$i][4] & " GB|"
        Next
            GUICtrlSetData($DISK, $sResult)

$Bios = GUICtrlCreateCheckbox("Bios", 216, 80, 41, 17)
$EFI = GUICtrlCreateCheckbox("EFI", 264, 80, 41, 17)
$Start = GUICtrlCreateButton("Start", 129, 72, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

GUICtrlSetState($CHOSENIMAGE, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While 1
$Msg = GUIGetMsg()
    Select

        Case $msg = $SELECTIMAGE
            SelectSource()
        Case $msg = $GUI_EVENT_CLOSE
            $YesOrNo = msgBox(4,"","Weet je zeker dat je wilt stoppen?")
                If $YesOrNo = 6 then
                    WinSetState("[CLASS:ConsoleWindowClass]", "", @SW_SHOW)
                    Exit
                EndIf

        Case $msg = $Start
            Start()

        Case $msg = $BIOS
            If GUICtrlRead($BIOS) = $GUI_CHECKED Then
                GUICtrlSetState($EFI, $GUI_DISABLE)
            EndIf
            If GUICtrlRead($BIOS) = $GUI_UNCHECKED Then
                GUICtrlSetState($EFI, $GUI_ENABLE)
            EndIf

        Case $msg = $EFI
            If GUICtrlRead($EFI) = $GUI_CHECKED Then
                GUICtrlSetState($BIOS, $GUI_DISABLE)
            EndIf
            If GUICtrlRead($EFI) = $GUI_UNCHECKED Then
                GUICtrlSetState($BIOS, $GUI_ENABLE)
            EndIf

    EndSelect

    $VAR = GUICtrlRead($CHOSENIMAGE)
    Sleep(50)
        If $VAR = "" Then
            GUICtrlSetState($Start, $GUI_DISABLE)
        Else
            GUICtrlSetState($Start, $GUI_ENABLE)
        EndIf
WEnd

Func SelectSource()
    $SourceData = FileOpenDialog("Kies image bestand...", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Images (*.WIM)")
        GUICtrlSetData($CHOSENIMAGE, $SourceData)
EndFunc

Func Start()
    $GO = 1

    $oWMISvc = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    $colDiskDrives = $oWMISvc.ExecQuery("SELECT * FROM Win32_DiskDrive")
    $COUNT = 0
For $oDiskDrive In $colDiskDrives
    $COUNT = $COUNT + 1
    ConsoleWrite("DiskDrive = " & $oDiskDrive.DeviceId & "  Caption = " & $oDiskDrive.Caption & @LF)
Next
;   MsgBox(4096, "Telling",  "Geteld: " & $COUNT)
    If $COUNT >= 2 Then
        $GO = 1
    Else
        MsgBox(4096, "Let op!", "Er is maar " & $COUNT & " harde schijf gevonden!")
        $GO = 0
    EndIf

    If GUICtrlRead($Bios) = $GUI_UNCHECKED And GUICtrlRead($EFI) = $GUI_UNCHECKED Then
        MsgBox(4096, "Let op!", "Kies 1 van de opties indelingen: Bios of EFI.")
        $GO = 0
    EndIf

If $GO = 1 Then
    $VAR    = GUICtrlRead($DISK)
    $VAR2   = StringLeft($VAR, 6)
        MsgBox(4096, "Gekozen schijf", $VAR2)
    Exit
    $FILE = "X:\diskpart.txt"
    If GUICtrlRead($Bios) = $GUI_CHECKED Then
            FileOpen($FILE, 2)
                FileWriteLine($FILE, "SELECT " & $VAR2 & @CRLF)
                FileWriteLine($FILE, "CLEAN" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY SIZE=350" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="System"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER ="K"' & @CRLF)
                FileWriteLine($FILE, "ACTIVE" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="OS"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER="L"' & @CRLF)
                FileWriteLine($FILE, "EXIT" & @CRLF)
            FileClose($FILE)
    Else
            FileOpen($FILE, 2)
                FileWriteLine($FILE, "SELECT " & $VAR2 & @CRLF)
                FileWriteLine($FILE, "CLEAN" & @CRLF)
                FileWriteLine($FILE, "CONVERT GPT" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION efi SIZE=100" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=FAT32 LABEL="System"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER ="K"' & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION MSR size=16" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY" & @CRLF)
                FileWriteLine($FILE, "SHRINK MINIMUM=500" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="OS"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER="L"' & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="Recovery tools"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER="R"' & @CRLF)
                FileWriteLine($FILE, 'set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"' & @CRLF)
                FileWriteLine($FILE, "GTP attributes=0x8000000000000001"& @CRLF)
                FileWriteLine($FILE, "EXIT" & @CRLF)
            FileClose($FILE)
    EndIf

    RunWait("Diskpart.exe /s X:\diskpart.txt")

    $IMAGE = GUICtrlRead($CHOSENIMAGE)

    If GUICtrlRead($BIOS) = $GUI_CHECKED Then
        $IMAGELABEL = 1
        RunWait("X:\Windows\System32\BIOS-INSTALL.cmd " & $IMAGE & " " & $IMAGELABEL)
    Else
        $IMAGELABEL = "AMD64"
        RunWait("X:\Windows\System32\EFI-INSTALL.cmd " & $IMAGE & " " & $IMAGELABEL)
    EndIf
    Sleep(1500) ;-----------------------------------------------------------------------------------------------------Wachten voor 1,5 seconden
    Shutdown(2) ;-----------------------------------------------------------------------------------------------------Shutdown en de 2 staat voor herstarten
EndIf
EndFunc
;=====================================START GET DRIVE INFO FUNCTION===================================================
Func _GetDriveInfos()
Local $var = DriveGetDrive( "FIXED" ) , $specifs[$var[0]][5]
For $i = 1 to $var[0]
Dim $Services  = ObjGet('winmgmts:\\.\root\cimv2')
Dim $DiskDrives =  $Services.ExecQuery("Select Caption, DeviceID, Size From Win32_DiskDrive")
For $DiskDrive In $DiskDrives
    $query = "Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition"
    Dim $DiskPartitions = $Services.ExecQuery($query)
    For $DiskPartition In $DiskPartitions
        Dim $LogicalDisks = $Services.ExecQuery ("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
        For $LogicalDisk In $LogicalDisks
        If $LogicalDisk.DeviceID = $var[$i] Then
            $specifs[$i-1][0] = StringUpper($var[$i])
            $specifs[$i-1][1] = $DiskDrive.Caption
            Local $split = StringSplit($DiskPartition.DeviceID, ",")
            $specifs[$i-1][2] = StringReplace($split[1], "#", "")   ; disk
            $specifs[$i-1][3] = StringReplace($split[2], "#", "")   ; part
            $specifs[$i-1][4] = Int($DiskDrive.Size / 1024^3) ;& "GB"
        EndIf
       Next
    Next
Next
Next
Return $specifs
EndFunc
;=====================================END GET DRIVE INFO FUNCTION=====================================================

 

 

error windows pe.png

Share this post


Link to post
Share on other sites



#2 ·  Posted

Try using IsObj() after each ExecQuery.

Share this post


Link to post
Share on other sites

#3 ·  Posted

I don't really understand what you mean?

Share this post


Link to post
Share on other sites

#4 ·  Posted

This means you need to add some kind of error checking to your script.
The error you get means that the command before the line in error didn't work as expected and hence did not return the correct result. You thn process an invalid result and hence get the error message you see.
In your case I suggest to add a COM error handler (see ObjEvent in the help file for details). The example COM error handler in the help file returns a lot of helpful information about the errro you see.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

I tried the solution from above and still it gives the problem, am I doing something wrong?

 

;=====================================START GET DRIVE INFO FUNCTION===================================================
Func _GetDriveInfos()
Local $var = DriveGetDrive( "FIXED" ) , $specifs[$var[0]][5]
For $i = 1 to $var[0]
Dim $Services  = ObjGet('winmgmts:\\.\root\cimv2')
Dim $DiskDrives =  $Services.ExecQuery("Select Caption, DeviceID, Size From Win32_DiskDrive")
If IsObj($DiskDrives) Then
    For $DiskDrive In $DiskDrives
        $query = "Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition"
        dim $DiskPartitions = $Services.ExecQuery($query)
        For $DiskPartition In $DiskPartitions
            Dim $LogicalDisks = $Services.ExecQuery ("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
            For $LogicalDisk In $LogicalDisks
                If $LogicalDisk.DeviceID = $var[$i] Then
                    $specifs[$i-1][0] = StringUpper($var[$i])
                    $specifs[$i-1][1] = $DiskDrive.Caption
                    Local $split = StringSplit($DiskPartition.DeviceID, ",")
                    $specifs[$i-1][2] = StringReplace($split[1], "#", "")   ; disk
                    $specifs[$i-1][3] = StringReplace($split[2], "#", "")   ; part
                    $specifs[$i-1][4] = Int($DiskDrive.Size / 1024^3) ;& "GB"
                EndIf
            Next
        Next
    Next
EndIf
Next
Return $specifs
EndFunc
;=====================================END GET DRIVE INFO FUNCTION=====================================================

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Which line exactly does return the error? Means: Does it Crash on ObjGet or ExecQuery or when accessing the returned Devices?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

I dont know, i get the error as show attached to the original post.

 

Also added WMI support to the Windows PE enviroment still get the same error.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Have you tried adding some logging or more error checking?
Something like this:

;=====================================START GET DRIVE INFO FUNCTION===================================================
Func _GetDriveInfos()
    Local $var = DriveGetDrive("FIXED"), $specifs[$var[0]][5]
    For $i = 1 To $var[0]
        Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')
        If IsObj($Services) Then
            Dim $DiskDrives = $Services.ExecQuery("Select Caption, DeviceID, Size From Win32_DiskDrive")
            If IsObj($DiskDrives) Then
                For $DiskDrive In $DiskDrives
                    $query = "Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition"
                    Dim $DiskPartitions = $Services.ExecQuery($query)
                    For $DiskPartition In $DiskPartitions
                        Dim $LogicalDisks = $Services.ExecQuery("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
                        For $LogicalDisk In $LogicalDisks
                            If $LogicalDisk.DeviceID = $var[$i] Then
                                $specifs[$i - 1][0] = StringUpper($var[$i])
                                $specifs[$i - 1][1] = $DiskDrive.Caption
                                Local $split = StringSplit($DiskPartition.DeviceID, ",")
                                $specifs[$i - 1][2] = StringReplace($split[1], "#", "") ; disk
                                $specifs[$i - 1][3] = StringReplace($split[2], "#", "") ; part
                                $specifs[$i - 1][4] = Int($DiskDrive.Size / 1024 ^ 3) ;& "GB"
                            EndIf
                        Next
                    Next
                Next
            Else
                MsgBox(0,"Error Querying Object","Error running query on Object cimv2")
            EndIf
        Else
            MsgBox(0,"Error getting Object","Error initialize Object cimv2")
        EndIf
    Next
    Return $specifs
EndFunc   ;==>_GetDriveInfos
;=====================================END GET DRIVE INFO FUNCTION=====================================================

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted

I don't get an error now or a messagebox it opens my script but it shows no hard drives.

When i use diskpart in Windows PE it shows me the 2 hard drives and the bootable usb drive, any idea's?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Replace the MsgBox a with statement that writes to log file so you can see what's happening but I expect that the ObjGet('winmgmts:\\.\root\cimv2') is failing as that is the only test I've added. So that means that this (winmgmts:\\.\root\cimv2) WMI object is not available of the path to it is wrong for WinPE.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted

When I use filewrite of msgbox on the variable: Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')

I get a blanco msgbox or an empty txt file, also consolewrite shows nothing, what am i doing wrong?

Share this post


Link to post
Share on other sites

#13 ·  Posted

Helpfile page ObjGet()

Quote

Return Value

Success: an object.
Failure: sets the @error flag to non-zero.

Check what the @error macro returns as it seems it is failing, hence returning nothing  to the variable $Services.

 Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#14 ·  Posted

$Services is an object and hence can not be displayed using MsgBox or FileWriteLine.
Use something like

FileWriteLine("C:\temp\yourlogfile.txt", "IsObj = " & IsObj($Services) & ", @error = " & @error & ",@extended = " & @xtended & @CRLF)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

I added the code:

FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($Services) & ", @error = " & @error & ", @extended = " & @extended & @CRLF)

I attached a screenshot of the log it creates and the gui my scripts gets.

error & gui.png

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

So it looks like that one is OK. What about the next statement that uses this object ... etc.
Do the same for $diskdrives  and $DiskPartitions....  shouldn't be hard to do this debugging to get the the statement with the issue. ;)

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#17 ·  Posted

The code is a followed:

;=====================================START GET DRIVE INFO FUNCTION===================================================
Func _GetDriveInfos()
    Local $var = DriveGetDrive("FIXED"), $specifs[$var[0]][5]
    For $i = 1 To $var[0]
        Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')
            If FileExists(@ScriptDir & "\log.txt") Then
                FileDelete(@ScriptDir & "\log.txt")
            EndIf
            FileWrite(@ScriptDir & "\log.txt", "$Services:" & @CRLF)
            FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($Services) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
        If IsObj($Services) Then
            Dim $DiskDrives = $Services.ExecQuery("Select Caption, DeviceID, Size From Win32_DiskDrive")
            If IsObj($DiskDrives) Then
                FileWrite(@ScriptDir & "\log.txt", "$DiskDrives:" & @CRLF)
                FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($DiskDrives) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                For $DiskDrive In $DiskDrives
                    FileWrite(@ScriptDir & "\log.txt", "$DiskDrive:" & @CRLF)
                    FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($DiskDrive) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                    $query = "Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition"
                    Dim $DiskPartitions = $Services.ExecQuery($query)
                    For $DiskPartition In $DiskPartitions
                        FileWrite(@ScriptDir & "\log.txt", "$DiskPartition:" & @CRLF)
                        FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($DiskPartition) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                        Dim $LogicalDisks = $Services.ExecQuery("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
                        For $LogicalDisk In $LogicalDisks
                            FileWrite(@ScriptDir & "\log.txt", "$LogicalDisk:" & @CRLF)
                            FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($LogicalDisk) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                            If $LogicalDisk.DeviceID = $var[$i] Then
                                $specifs[$i - 1][0] = StringUpper($var[$i])
                                $specifs[$i - 1][1] = $DiskDrive.Caption
                                Local $split = StringSplit($DiskPartition.DeviceID, ",")
                                $specifs[$i - 1][2] = StringReplace($split[1], "#", "") ; disk
                                $specifs[$i - 1][3] = StringReplace($split[2], "#", "") ; part
                                $specifs[$i - 1][4] = Int($DiskDrive.Size / 1024 ^ 3) ;& "GB"
                            EndIf
                        Next
                    Next
                Next
            Else
                MsgBox(0,"Error Querying Object","Error running query on Object cimv2")
            EndIf
        Else
            MsgBox(0,"Error getting Object","Error initialize Object cimv2")
        EndIf
    Next
                If FileExists(@ScriptDir & "\log.txt") Then
                    RunWait("Notepad.exe " & @ScriptDir & "\log.txt")
                EndIf
    Return $specifs
EndFunc   ;==>_GetDriveInfos
;=====================================END GET DRIVE INFO FUNCTION=====================================================

 

The log i get:

$Services:
IsObj = 1, @error = 0, @extended = 0
$DiskDrives:
IsObj = 1, @error = 0, @extended = 0
$DiskDrive:
IsObj = 1, @error = 0, @extended = 0
$DiskDrive:
IsObj = 1, @error = 0, @extended = 0
$DiskDrive:
IsObj = 1, @error = 0, @extended = 0

 

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

Anyone got any ideas?

Share this post


Link to post
Share on other sites

#19 ·  Posted

So you aren't getting the error anymore but the dropdown box stays empty.  What does the total code look like now?
Did you do any more debugging to get to the root of this issue why it stays empty?

Jps


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#20 ·  Posted

I do not get the error any more, the pulldown menu gets some options in there but not the info I expect it shows something like:

   :   :   GB

The blank spaces between the : is suppose to be filled with the disk number, the model of de hard disk and size of the hard disk.

Example:   Disk 0 : WD5000-WLX : 469 GB

 

My code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <ComboConstants.au3>

#NoTrayIcon

WinSetState("[CLASS:ConsoleWindowClass]", "", @SW_HIDE)

GUICreate("Image from USB", 385, 108, 720, 459)

$CHOSENIMAGE = GUICtrlCreateInput("Kies image...", 20, 8, 305, 21)
$SELECTIMAGE = GUICtrlCreateButton("...", 328, 8, 35, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$DISK = GUICtrlCreateCombo("Kies schijf...", 20, 40, 305, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
    GUICtrlSetData($DISK, "==============================================================")

    $myinfos = _GetDriveInfos()
        Local $sResult = ""
            For $i = 0 to UBound($myinfos) - 1
                $sResult &= $myinfos[$i][2] & " : " & $myinfos[$i][1] & " : " & $myinfos[$i][4] & " GB|"
        Next
            GUICtrlSetData($DISK, $sResult)

$Bios = GUICtrlCreateCheckbox("Bios", 216, 80, 41, 17)
$EFI = GUICtrlCreateCheckbox("EFI", 264, 80, 41, 17)
$Start = GUICtrlCreateButton("Start", 129, 72, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

GUICtrlSetState($CHOSENIMAGE, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While 1
$Msg = GUIGetMsg()
    Select

        Case $msg = $SELECTIMAGE
            SelectSource()
        Case $msg = $GUI_EVENT_CLOSE
            $YesOrNo = msgBox(4,"  Sluiten","Weet je zeker dat je wilt stoppen?")
                If $YesOrNo = 6 then
                    WinSetState("[CLASS:ConsoleWindowClass]", "", @SW_SHOW)
                    Exit
                EndIf

        Case $msg = $Start
            Start()

        Case $msg = $BIOS
            If GUICtrlRead($BIOS) = $GUI_CHECKED Then
                GUICtrlSetState($EFI, $GUI_DISABLE)
            EndIf
            If GUICtrlRead($BIOS) = $GUI_UNCHECKED Then
                GUICtrlSetState($EFI, $GUI_ENABLE)
            EndIf

        Case $msg = $EFI
            If GUICtrlRead($EFI) = $GUI_CHECKED Then
                GUICtrlSetState($BIOS, $GUI_DISABLE)
            EndIf
            If GUICtrlRead($EFI) = $GUI_UNCHECKED Then
                GUICtrlSetState($BIOS, $GUI_ENABLE)
            EndIf

    EndSelect

    $VAR = GUICtrlRead($CHOSENIMAGE)
    Sleep(50)
        If $VAR = "" Then
            GUICtrlSetState($Start, $GUI_DISABLE)
        Else
            GUICtrlSetState($Start, $GUI_ENABLE)
        EndIf
WEnd

Func SelectSource()
    $SourceData = FileOpenDialog("Kies image bestand...", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Images (*.WIM)")
        GUICtrlSetData($CHOSENIMAGE, $SourceData)
EndFunc

Func Start()
    $GO = 1

    $oWMISvc = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    $colDiskDrives = $oWMISvc.ExecQuery("SELECT * FROM Win32_DiskDrive")
    $COUNT = 0
For $oDiskDrive In $colDiskDrives
    $COUNT = $COUNT + 1
    ConsoleWrite("DiskDrive = " & $oDiskDrive.DeviceId & "  Caption = " & $oDiskDrive.Caption & @LF)
Next
;   MsgBox(4096, "Telling",  "Geteld: " & $COUNT)
    If $COUNT >= 2 Then
        $GO = 1
    Else
        MsgBox(4096, "Let op!", "Er is maar " & $COUNT & " harde schijf gevonden!")
        $GO = 0
    EndIf

    If GUICtrlRead($Bios) = $GUI_UNCHECKED And GUICtrlRead($EFI) = $GUI_UNCHECKED Then
        MsgBox(4096, "Let op!", "Kies 1 van de opties indelingen: Bios of EFI.")
        $GO = 0
    EndIf

If $GO = 1 Then
    $VAR    = GUICtrlRead($DISK)
    $VAR2   = StringLeft($VAR, 6)
        MsgBox(4096, "Gekozen schijf", $VAR2)
    Exit
    $FILE = "X:\diskpart.txt"
    If GUICtrlRead($Bios) = $GUI_CHECKED Then
            FileOpen($FILE, 2)
                FileWriteLine($FILE, "SELECT " & $VAR2 & @CRLF)
                FileWriteLine($FILE, "CLEAN" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY SIZE=350" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="System"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER ="K"' & @CRLF)
                FileWriteLine($FILE, "ACTIVE" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="OS"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER="L"' & @CRLF)
                FileWriteLine($FILE, "EXIT" & @CRLF)
            FileClose($FILE)
    Else
            FileOpen($FILE, 2)
                FileWriteLine($FILE, "SELECT " & $VAR2 & @CRLF)
                FileWriteLine($FILE, "CLEAN" & @CRLF)
                FileWriteLine($FILE, "CONVERT GPT" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION efi SIZE=100" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=FAT32 LABEL="System"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER ="K"' & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION MSR size=16" & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY" & @CRLF)
                FileWriteLine($FILE, "SHRINK MINIMUM=500" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="OS"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER="L"' & @CRLF)
                FileWriteLine($FILE, "CREATE PARTITION PRIMARY" & @CRLF)
                FileWriteLine($FILE, 'FORMAT QUICK FS=NTFS LABEL="Recovery tools"' & @CRLF)
                FileWriteLine($FILE, 'ASSIGN LETTER="R"' & @CRLF)
                FileWriteLine($FILE, 'set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"' & @CRLF)
                FileWriteLine($FILE, "GTP attributes=0x8000000000000001"& @CRLF)
                FileWriteLine($FILE, "EXIT" & @CRLF)
            FileClose($FILE)
    EndIf

    RunWait("Diskpart.exe /s X:\diskpart.txt")

    $IMAGE = GUICtrlRead($CHOSENIMAGE)

    If GUICtrlRead($BIOS) = $GUI_CHECKED Then
        $IMAGELABEL = 1
        RunWait("X:\Windows\System32\BIOS-INSTALL.cmd " & $IMAGE & " " & $IMAGELABEL)
    Else
        $IMAGELABEL = "AMD64"
        RunWait("X:\Windows\System32\EFI-INSTALL.cmd " & $IMAGE & " " & $IMAGELABEL)
    EndIf
    Sleep(1500) ;-----------------------------------------------------------------------------------------------------Wachten voor 1,5 seconden
    Shutdown(2) ;-----------------------------------------------------------------------------------------------------Shutdown en de 2 staat voor herstarten
EndIf
EndFunc
;=====================================START GET DRIVE INFO FUNCTION===================================================
Func _GetDriveInfos()
    Local $var = DriveGetDrive("FIXED"), $specifs[$var[0]][5]
    For $i = 1 To $var[0]
        Dim $Services = ObjGet('winmgmts:\\.\root\cimv2')
            If FileExists(@ScriptDir & "\log.txt") Then
                FileDelete(@ScriptDir & "\log.txt")
            EndIf
            FileWrite(@ScriptDir & "\log.txt", "$Services:" & @CRLF)
            FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($Services) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
        If IsObj($Services) Then
            Dim $DiskDrives = $Services.ExecQuery("Select Caption, DeviceID, Size From Win32_DiskDrive")
            If IsObj($DiskDrives) Then
                FileWrite(@ScriptDir & "\log.txt", "$DiskDrives:" & @CRLF)
                FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($DiskDrives) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                For $DiskDrive In $DiskDrives
                    FileWrite(@ScriptDir & "\log.txt", "$DiskDrive:" & @CRLF)
                    FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($DiskDrive) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                    $query = "Associators of {Win32_DiskDrive.DeviceID='" & $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition"
                    Dim $DiskPartitions = $Services.ExecQuery($query)
                    For $DiskPartition In $DiskPartitions
                        FileWrite(@ScriptDir & "\log.txt", "$DiskPartition:" & @CRLF)
                        FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($DiskPartition) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                        Dim $LogicalDisks = $Services.ExecQuery("Associators of {Win32_DiskPartition.DeviceID='" & $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
                        For $LogicalDisk In $LogicalDisks
                            FileWrite(@ScriptDir & "\log.txt", "$LogicalDisk:" & @CRLF)
                            FileWrite(@ScriptDir & "\log.txt", "IsObj = " & IsObj($LogicalDisk) & ", @error = " & @error & ", @extended = " & @extended & @CRLF) ;-------------------------------------------> fout log
                            If $LogicalDisk.DeviceID = $var[$i] Then
                                $specifs[$i - 1][0] = StringUpper($var[$i])
                                $specifs[$i - 1][1] = $DiskDrive.Caption
                                Local $split = StringSplit($DiskPartition.DeviceID, ",")
                                $specifs[$i - 1][2] = StringReplace($split[1], "#", "") ; disk
                                $specifs[$i - 1][3] = StringReplace($split[2], "#", "") ; part
                                $specifs[$i - 1][4] = Int($DiskDrive.Size / 1024 ^ 3) ;& "GB"
                            EndIf
                        Next
                    Next
                Next
            Else
                MsgBox(0,"Error Querying Object","Error running query on Object cimv2")
            EndIf
        Else
            MsgBox(0,"Error getting Object","Error initialize Object cimv2")
        EndIf
    Next
                If FileExists(@ScriptDir & "\log.txt") Then
                    RunWait("Notepad.exe " & @ScriptDir & "\log.txt")
                EndIf
    Return $specifs
EndFunc   ;==>_GetDriveInfos
;=====================================END GET DRIVE INFO FUNCTION=====================================================

 

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