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
}
VBScript to display current power plan
- Simon Sheppard
- Posts: 170
- Joined: 2021-Jul-10, 7:46 pm
- Contact:
Re: VBScript to display current power plan
In this line
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.
Code: Select all
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}r");
Also try running it with cscript.exe to see if that works before wrapping it into an HTA.