VBScript to display current power plan

Microsoft Windows
Post Reply
Posts: 1
Joined: 2022-Mar-29, 5:00 pm

VBScript to display current power plan

Post 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.

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

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();

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

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
User avatar
Simon Sheppard
Posts: 102
Joined: 2021-Jul-10, 7:46 pm

Re: VBScript to display current power plan

Post 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.
Post Reply