I have the following HTA file:
<html>
<head>
<title>test</title>
<SCRIPT Language="VBScript">
createobject("Shell.Application").ShellExecute "C:\windows\system32\cmd.exe", "/k powercfg /batteryreport", "", "runas", 1
</SCRIPT>
<body>
</body>
</html>
When I run it, it shows a UAC prompt with "yes"/"no" buttons from "Windows Command Processor." After "yes" is clicked, it opens a command prompt window with the title "Administrator: C:\WINDOWS\SysWOW64\cmd.exe". However the command fails, stating that "The Power Efficiency Diagnostic library (energy.dll) could not be loaded."
I am pretty sure the command window that opens has admin permissions because of the following reasons:
- It shows a UAC box to open the CMD window
- The VBScript command was supposed to run the external command with elevated permissions
- When I run the following command in that same command window, it says "Success":
net session >nul 2>&1 && echo Success || echo Failure
. (This command checks for admin permissions; I found in a comment on this post: https://superuser.com/a/667745 - The title says "Administrator:" in it.
So, I am wondering why this command doesn't work and how I can get it to work, if possible.
Another interesting thing I noticed was that taking line 5 (createobject("Shell.Application").ShellExecute "C:\windows\system32\cmd.exe", "/k powercfg /batteryreport", "", "runas", 1
) from that HTA file and putting it in a blank .VBS file actually leads to a different result. The title of the resulting Command Window with this method is different ("Administrator: C:\Windows\System32\cmd.exe"), and the resulting error is different, too. It says:
Enabling tracing for 60 seconds... Observing system behavior... Could not open the Power Efficiency Diagnostic ETW session. The ETW session is already in use. Ensure that no other instances of PowerCfg are currently running.
Does anyone have a potential explanation or solution to this problem? Thank you.