Wingens Posted June 8, 2017 Share Posted June 8, 2017 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 expandcollapse popup#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===================================================== Link to comment Share on other sites More sharing options...
Danp2 Posted June 8, 2017 Share Posted June 8, 2017 Try using IsObj() after each ExecQuery. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Wingens Posted June 9, 2017 Author Share Posted June 9, 2017 I don't really understand what you mean? Link to comment Share on other sites More sharing options...
water Posted June 9, 2017 Share Posted June 9, 2017 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jguinch Posted June 9, 2017 Share Posted June 9, 2017 Also, are you sure you have the WMI support in your WinPE environment ? https://technet.microsoft.com/en-us/library/hh824926.aspx Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Wingens Posted June 9, 2017 Author Share Posted June 9, 2017 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===================================================== Link to comment Share on other sites More sharing options...
water Posted June 9, 2017 Share Posted June 9, 2017 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Wingens Posted June 9, 2017 Author Share Posted June 9, 2017 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. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 9, 2017 Developers Share Posted June 9, 2017 (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 June 9, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wingens Posted June 9, 2017 Author Share Posted June 9, 2017 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? Link to comment Share on other sites More sharing options...
Developers Jos Posted June 9, 2017 Developers Share Posted June 9, 2017 (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 June 9, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wingens Posted June 9, 2017 Author Share Posted June 9, 2017 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? Link to comment Share on other sites More sharing options...
Developers Jos Posted June 9, 2017 Developers Share Posted June 9, 2017 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
water Posted June 9, 2017 Share Posted June 9, 2017 $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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Wingens Posted June 9, 2017 Author Share Posted June 9, 2017 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. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 9, 2017 Developers Share Posted June 9, 2017 (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 June 9, 2017 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wingens Posted June 12, 2017 Author Share Posted June 12, 2017 The code is a followed: expandcollapse popup;=====================================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 Link to comment Share on other sites More sharing options...
Wingens Posted June 14, 2017 Author Share Posted June 14, 2017 Anyone got any ideas? Link to comment Share on other sites More sharing options...
Developers Jos Posted June 14, 2017 Developers Share Posted June 14, 2017 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Wingens Posted June 14, 2017 Author Share Posted June 14, 2017 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: expandcollapse popup#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===================================================== 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