Page 1 of 1

VBScript to display current power plan

Posted: 2022-Mar-29, 5:05 pm
by jwaldchen
I am trying to display CURRENT POWER PLAN in an HTA using VBscript. Here is the Powershell equivalent of what I am looking to output and the VB that I am trying so far. No errors in VBS but no output. Having trouble adding namespace to the wmi var. I have a similar script that is working (below) that pulls Serial Number from default namespace .Any help would be great.

POWERSHELL
Get-CimInstance -classname Win32_PowerPlan -Namespace "root\cimv2\power" | select-object -expandproperty Elementname

VB
function powerprofile() {
var powerprofile = "";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}r");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_PowerPlan WHERE IsActive = TRUE"));
for(; !e.atEnd(); e.moveNext()) {
var s = e.item();
powerprofile = s.ElementName;
}
return powerprofile
}

/* Global variables */
var power = powerprofile();

HTA:
<script type="text/javascript"> document.write(power);</script>

WORKING SIMILAR VBS:
function serialNumber() {
var serialNumber = "";
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_BIOS"));
for(; !e.atEnd(); e.moveNext()) {
var s = e.item();
serialNumber = s.SerialNumber;
}
return serialNumber
}

Re: VBScript to display current power plan

Posted: 2022-Apr-02, 7:42 pm
by Simon Sheppard
In this line

Code: Select all

var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}r");
it looks like you have an extra 'r' at the end of the line.

Also try running it with cscript.exe to see if that works before wrapping it into an HTA.