jayinoz Posted November 8, 2023 Posted November 8, 2023 (edited) Hi folks, I've converted quite a few PowerShell scripts to AutoIT, but I'm struggling with this one, and I've got a VBScript alternative that seems equally a challenge. Here is the PowerShell command and output (gwmi –class Lenovo_GetBiosSelections –namespace root\wmi).GetBiosSelections("WakeOnLAN") | Format-List Selections Output: Selections : Disable,ACOnly,ACandBattery,Enable Here is a very similar VBScript On Error Resume Next Dim colItems strComputer = "LOCALHOST" ' Change as needed. strOptions Set objWMIService = GetObject("WinMgmts:" _ &"{ImpersonationLevel=Impersonate}!\\" & strComputer & "\root\wmi") Set colItems = objWMIService.ExecQuery("Select * from Lenovo_BiosSetting") For Each objItem in colItems If Len(objItem.CurrentSetting) > 0 Then Setting = ObjItem.CurrentSetting StrItem = Left(ObjItem.CurrentSetting, InStr(ObjItem.CurrentSetting, ",") - 1) StrValue = Mid(ObjItem.CurrentSetting, InStr(ObjItem.CurrentSetting, ",") + 1, 256) If StrItem = "WakeOnLAN" Then Set selItems = objWMIService.ExecQuery("Select * from Lenovo_GetBiosSelections") For Each objItem2 in selItems objItem2.GetBiosSelections StrItem + ";", strOptions Next WScript.Echo StrItem WScript.Echo " current setting = " + StrValue WScript.Echo " possible settings = " + strOptions WScript.Echo End If End If Next Output: WakeOnLAN current setting = ACOnly possible settings = Disable,ACOnly,ACandBattery,Enable Could somebody help me with the AutoIT equivalent please? Thanks Edited November 8, 2023 by jayinoz
Andreik Posted November 8, 2023 Posted November 8, 2023 $strComputer = "LOCALHOST" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("Select * from Lenovo_BiosSetting") If IsObj($colItems) then For $objItem In $colItems $StrOptions = '' If StringLen($objItem.CurrentSetting) > 0 Then $Setting = $objItem.CurrentSetting $StrItem = StringLeft($objItem.CurrentSetting, StringInStr($objItem.CurrentSetting, ",") - 1) $StrValue = StringMid($objItem.CurrentSetting, StringInStr($objItem.CurrentSetting, ",") + 1, 256) If $StrItem = "WakeOnLAN" Then $selItems =$objWMIService.ExecQuery("Select * from Lenovo_GetBiosSelections") For $objItem2 in $selItems ;Not sure about this line, I suppose it's a string concatenation ;~ $objItem2.GetBiosSelections StrItem + ";", strOptions $StrOptions &= $objItem2.GetBiosSelections & ',' Next ConsoleWrite($StrItem & @CRLF) ConsoleWrite('Current setting: ' & $StrValue & @CRLF) ConsoleWrite('Possible settings: ' & $StrOptions & @CRLF) EndIf EndIf Next Endif
jayinoz Posted November 8, 2023 Author Posted November 8, 2023 Thanks Andreik, but unfortunately this produces no output.
Andreik Posted November 8, 2023 Posted November 8, 2023 (edited) I suppose Lenovo_BiosSetting class is available just on Lenovo devices. Is the VBScript working on the same device? Edited November 8, 2023 by Andreik
jayinoz Posted November 9, 2023 Author Posted November 9, 2023 Yes on both counts. I can run both PowerShell and VBscript on the device and get output, but running AutoIT produces no errors, but I get no output either.
spudw2k Posted November 9, 2023 Posted November 9, 2023 Are you running the AutoIt script as an EXE? When using ConsoleWrite and running as an EXE you need to add the directive #AutoIt3Wrapper_Change2CUI=Y...if you are expecting the output to be shown in the command prompt console. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
jayinoz Posted November 9, 2023 Author Posted November 9, 2023 I'm using ConsoleWrite at the moment, the code has not been compiled. I'm using other similar queries with no issue, e.g. Func GetAllBIOSSettingsAndValues() Local $objWMI = ObjGet('winmgmts:root\wmi') Local $objClass = $objWMI.ExecQuery('SELECT * FROM Lenovo_BiosSetting') Local $ResultString = 'All BIOS settings...' & @CRLF Dim $ResultsArray[0][3] For $objItem In $objClass If StringInStr($objItem.CurrentSetting, ",") Then ReDim $ResultsArray[UBound($ResultsArray)+1][3] Local $anObject = StringSplit($objItem.CurrentSetting, ",") If $Debug Then ConsoleWrite ($objItem.CurrentSetting & " split value in to " & $anObject[0] & "." & $anObject[1] & ":" & $anObject[2] & @CRLF) If $anObject[0] >= 1 Then $ResultsArray[UBound($ResultsArray) - 1][0] = $anObject[1] If $anObject[0] >= 2 Then $ResultsArray[UBound($ResultsArray) - 1][1] = $anObject[2] $ResultsArray[UBound($ResultsArray) - 1][2] = StringReplace($objItem.InstanceName,"\","\\") EndIf Next Return $ResultsArray EndFunc The problem is in here somewhere... For $objItem2 in $selItems ;VBScript $objItem2.GetBiosSelections StrItem + ";", strOptions $StrOptions &= $objItem2.GetBiosSelections & ',' Next
Andreik Posted November 9, 2023 Posted November 9, 2023 2 hours ago, jayinoz said: The problem is in here somewhere... For $objItem2 in $selItems ;VBScript $objItem2.GetBiosSelections StrItem + ";", strOptions $StrOptions &= $objItem2.GetBiosSelections & ',' Next I think GetBiosSelection method has a parameter that it's the setting name so it should be something like this. Let me know if it works. $strComputer = "LOCALHOST" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("Select * from Lenovo_BiosSetting") If IsObj($colItems) then For $objItem In $colItems $StrOptions = '' If StringLen($objItem.CurrentSetting) > 0 Then $Setting = $objItem.CurrentSetting $StrItem = StringLeft($objItem.CurrentSetting, StringInStr($objItem.CurrentSetting, ",") - 1) $StrValue = StringMid($objItem.CurrentSetting, StringInStr($objItem.CurrentSetting, ",") + 1, 256) If $StrItem = "WakeOnLAN" Then $selItems =$objWMIService.ExecQuery("Select * from Lenovo_GetBiosSelections") For $objItem2 in $selItems $StrOptions &= $objItem2.GetBiosSelections($StrItem) & ',' Next ConsoleWrite($StrItem & @CRLF) ConsoleWrite('Current setting: ' & $StrValue & @CRLF) ConsoleWrite('Possible settings: ' & StringTrimRight($StrOptions, 1) & @CRLF) EndIf EndIf Next Endif
jayinoz Posted November 9, 2023 Author Posted November 9, 2023 (edited) Thanks for the suggestion & I think you're right, but it's not getting that far... $strComputer = "LOCALHOST" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("Select * from Lenovo_BiosSetting") If IsObj($colItems) then ConsoleWrite("Step 1" & @CRLF) For $objItem In $colItems ConsoleWrite("Step 2" & @CRLF) $StrOptions = '' ;If StringLen($objItem.CurrentSetting) > 0 Then ConsoleWrite("Step 3" & @CRLF) $Setting = $objItem.CurrentSetting $StrItem = StringLeft($objItem.CurrentSetting, StringInStr($objItem.CurrentSetting, ",") - 1) $StrValue = StringMid($objItem.CurrentSetting, StringInStr($objItem.CurrentSetting, ",") + 1, 256) If $StrItem = "WakeOnLAN" Then $selItems =$objWMIService.ExecQuery("Select * from Lenovo_GetBiosSelections") For $objItem2 in $selItems $StrOptions &= $objItem2.GetBiosSelections($StrItem) & ',' Next ConsoleWrite($StrItem & @CRLF) ConsoleWrite('Current setting: ' & $StrValue & @CRLF) ConsoleWrite('Possible settings: ' & StringTrimRight($StrOptions, 1) & @CRLF) EndIf ;EndIf Next Endif This results in Step 1 being output, so it's not getting in to the For $objItem In $colItems loop Edited November 9, 2023 by jayinoz
Andreik Posted November 9, 2023 Posted November 9, 2023 Run this and show us what do you get in console: expandcollapse popupLenovo_BiosSetting() Func Lenovo_BiosSetting($strComputer = 'localhost') Local $objWMIService, $colItems, $selItems Local $Options, $Setting, $SettingName, $SettingValue $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") If IsObj($colItems) then For $objItem In $colItems ConsoleWrite($objItem.Manufacturer & ' / ' & $objItem.Model & @CRLF) Next EndIf $colItems = $objWMIService.ExecQuery("Select * from Lenovo_BiosSetting") If IsObj($colItems) then ConsoleWrite("Lenovo_BiosSetting: " & (IsObj($colItems) ? True : False) & @CRLF) For $objItem In $colItems $SettingName = '' $SettingValue = '' $Setting = $objItem.CurrentSetting ConsoleWrite("Current setting: " & $objItem.CurrentSetting& @CRLF) $aSetting = StringSplit($Setting, ',') If IsArray($aSetting) Then If $aSetting[0] >= 2 Then $SettingName = $aSetting[1] $SettingValue = $aSetting[2] EndIf EndIf If $SettingName = "WakeOnLAN" Then $Options = '' $selItems =$objWMIService.ExecQuery("Select * from Lenovo_GetBiosSelections") ConsoleWrite("Lenovo_GetBiosSelections: " & (IsObj($selItems) ? True : False) & @CRLF) For $selItem in $selItems $Options &= $selItem.GetBiosSelections($SettingName) & ',' Next ConsoleWrite($SettingName & @CRLF) ConsoleWrite('Current setting value: ' & $SettingValue & @CRLF) ConsoleWrite('Possible settings: ' & StringTrimRight($Options, 1) & @CRLF) EndIf Next Endif EndFunc
jayinoz Posted November 9, 2023 Author Posted November 9, 2023 This might help. This code works perfectly expandcollapse popup#include <AutoItConstants.au3> #include <Array.au3> #include <Math.au3> $Debug = False $AllBIOSSettings = GetAllBIOSSettingsAndValues() ShowBIOSSettingAndValues($AllBIOSSettings, 300) Func GetAllBIOSSettingsAndValues() Local $objWMI = ObjGet('winmgmts:root\wmi') Local $objClass = $objWMI.ExecQuery('SELECT * FROM Lenovo_BiosSetting') Local $ResultString = 'All BIOS settings...' & @CRLF Dim $ResultsArray[0][3] For $objItem In $objClass If StringInStr($objItem.CurrentSetting, ",") Then ReDim $ResultsArray[UBound($ResultsArray)+1][3] Local $anObject = StringSplit($objItem.CurrentSetting, ",") If $Debug Then ConsoleWrite ($objItem.CurrentSetting & " split value in to " & $anObject[0] & "." & $anObject[1] & ":" & $anObject[2] & @CRLF) If $anObject[0] >= 1 Then $ResultsArray[UBound($ResultsArray) - 1][0] = $anObject[1] If $anObject[0] >= 2 Then $ResultsArray[UBound($ResultsArray) - 1][1] = $anObject[2] $ResultsArray[UBound($ResultsArray) - 1][2] = StringReplace($objItem.InstanceName,"\","\\") EndIf Next Return $ResultsArray EndFunc Func ShowBIOSSettingAndValues ($AllData, $topcount) ConsoleWrite(StringFormat("%-25.20s", "Reference") ) ConsoleWrite(StringFormat("%-45.40s", "Setting")); // left-justification with spaces ;ConsoleWrite(StringFormat("%-15.10s", $TheString[$EachLine][1]) & @CRLF); // left-justification with spaces ConsoleWrite("Value" & @CRLF ); // left-justification with spaces For $EachLine = 0 to _min((UBound($AllData) - 1), ($topcount - 1)) ConsoleWrite(StringFormat("%-25.20s", $AllData[$EachLine][2])); // left-justification with spaces ConsoleWrite(StringFormat("%-45.40s", $AllData[$EachLine][0])); // left-justification with spaces ;ConsoleWrite(StringFormat("%-15.10s", $TheString[$EachLine][1]) & @CRLF); // left-justification with spaces ConsoleWrite( $AllData[$EachLine][1] & @CRLF ); // left-justification with spaces Next EndFunc This outputs this... Reference Setting Value ACPI\\PNP0C14\\1_0 WakeOnLAN ACOnly ACPI\\PNP0C14\\1_1 WakeOnLANDock Disable ACPI\\PNP0C14\\1_2 EthernetLANOptionROM Enable ACPI\\PNP0C14\\1_3 IPv4NetworkStack Disable ACPI\\PNP0C14\\1_4 IPv6NetworkStack Disable Etc
jayinoz Posted November 10, 2023 Author Posted November 10, 2023 19 hours ago, Andreik said: Run this and show us what do you get in console: expandcollapse popupLenovo_BiosSetting() Func Lenovo_BiosSetting($strComputer = 'localhost') Local $objWMIService, $colItems, $selItems Local $Options, $Setting, $SettingName, $SettingValue $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") If IsObj($colItems) then For $objItem In $colItems ConsoleWrite($objItem.Manufacturer & ' / ' & $objItem.Model & @CRLF) Next EndIf $colItems = $objWMIService.ExecQuery("Select * from Lenovo_BiosSetting") If IsObj($colItems) then ConsoleWrite("Lenovo_BiosSetting: " & (IsObj($colItems) ? True : False) & @CRLF) For $objItem In $colItems $SettingName = '' $SettingValue = '' $Setting = $objItem.CurrentSetting ConsoleWrite("Current setting: " & $objItem.CurrentSetting& @CRLF) $aSetting = StringSplit($Setting, ',') If IsArray($aSetting) Then If $aSetting[0] >= 2 Then $SettingName = $aSetting[1] $SettingValue = $aSetting[2] EndIf EndIf If $SettingName = "WakeOnLAN" Then $Options = '' $selItems =$objWMIService.ExecQuery("Select * from Lenovo_GetBiosSelections") ConsoleWrite("Lenovo_GetBiosSelections: " & (IsObj($selItems) ? True : False) & @CRLF) For $selItem in $selItems $Options &= $selItem.GetBiosSelections($SettingName) & ',' Next ConsoleWrite($SettingName & @CRLF) ConsoleWrite('Current setting value: ' & $SettingValue & @CRLF) ConsoleWrite('Possible settings: ' & StringTrimRight($Options, 1) & @CRLF) EndIf Next Endif EndFunc I get this... +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. LENOVO / 20UCS0P40E Lenovo_BiosSetting: True +>07:40:11 AutoIt3.exe ended.rc:0 Thanks
jayinoz Posted November 21, 2023 Author Posted November 21, 2023 Any other thoughts on this one folks?
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