Windows 8 and 8.1 Forums


Cannot run elevated shortcut from html

  1. #1


    Posts : 301
    Windows 8 Pro

    Cannot run elevated shortcut from html


    I have a gadget that has buttons for hibernate and standby to run a shortcut. If I run the short cut directly by clicking it, it works, but if I try to run it from the html button, it will not acknowledge the run as administrator setting. I have tried it with VBScript and cannot change the powercfg - h state.

    Here is the html:
    HTML Code:
    <a id="hibernate"  onMouseOver='ShowTip(1,"Hibernate");' onMouseOut='HideTip(1);' href="../core/Hibernate.lnk" >
         <img src="../images/Hibernate.png" border="0" width="20" height="20" >
         <span id='tooltip1' class='tooltip'></span>
    </a>
    Here is the shortcut:
    Code:
    C:\Windows\System32\cmd.exe /c powercfg -h on & rundll32.exe powrprof.dll,SetSuspendState 0,1,0
    Here is the VBScript:
    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "%COMSPEC% /c POWERCFG /Hibernate ON"
    WshShell.Run "rundll32.exe PowrProf.dll SetSuspendState Hibernate"

      My System SpecsSystem Spec

  2. #2


    Central IL
    Posts : 3,468
    Linux Mint 17.2


    You are really going about it the hard way. Why reinvent the wheel. If you are just going to use Metro/Start, use Ctrl-Alt-Del, to pull up the Start Button. If using 8.1.1, it is already on the Metro/start screen. If always using the desktop, use Classic Shell or Start8 from Stardock.com
      My System SpecsSystem Spec

  3. #3


    Posts : 301
    Windows 8 Pro


    I have ClassicShell installed and I bypass all Windows 8 functionality - this is a laptop, not an android phone.
      My System SpecsSystem Spec

  4. #4


    Central IL
    Posts : 3,468
    Linux Mint 17.2


    We know that. Like I stated, if you are in Desktop mode, the classic Shut Down button is in the menu. If in Metro/Start on 8.1.1, the Shutdown icon is next to the picture. Why you are comparing Windows 8 to Android OS, makes no sense. One has nothing to do with the other.
      My System SpecsSystem Spec

  5. #5


    Posts : 301
    Windows 8 Pro


    Metro/Start was designed for touch screens and to compete with google's android. Here is the final batch file I came up with that works and satisfies the issue; make sure that the last 9 lines are paid close attention to since this will work for hibernate and standby:
    Code:
    REM -- Minimize window --
    if not "%minimized%"=="" goto :minimized
    set minimized=true
    start /min cmd /C "%~dpnx0"
    goto :EOF
    :minimized
    
    REM -- Runs batch files as administrator --
    REM --add the following to the top of your bat file --
    @echo off
    
    :: BatchGotAdmin
    :-------------------------------------
    REM  --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
    
    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
        echo Requesting administrative privileges...
        goto UACPrompt
    ) else ( goto gotAdmin )
    
    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        set params = %*:"=""
        echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    
        "%temp%\getadmin.vbs"
        del "%temp%\getadmin.vbs"
        exit /B
    
    :gotAdmin
        pushd "%CD%"
        CD /D "%~dp0"
        
    REM -- Code you want to run --
    :--------------------------------------
    C:\Windows\System32\cmd.exe /c 
    C:\Windows\system32\powercfg.exe -h on
    rundll32.exe powrprof.dll,SetSuspendState 0,1,1
    
    Rem The above 3 lines are for hibernate.
    Rem The following 3 lines are for standby
    Rem Use which ever is desired or create 2 batch files.
    
    C:\Windows\System32\cmd.exe /c 
    C:\Windows\system32\powercfg.exe -h off
    rundll32.exe powrprof.dll,SetSuspendState 0,1,1
      My System SpecsSystem Spec

  6. #6


    Central IL
    Posts : 3,468
    Linux Mint 17.2


    There is no need to write a program to take the place of something else. The Windows Club forum has a Taskbar Shutdown/Logoff/Restart utility called "HotShut". Just download it, or like I stated before. The Metro/Start screen already has the icon next to the user login picture, if the computer is running 8.1.1. If in Desktop mode, again the Shutdown/Logoff/Restart is going to show up with either Classic Shell or Start8.

    Also Windows 8 was never intended to compete against Android OS or iOS. Really wish you would get that out of your mind. Also yes it may be used for Touch screen interfaces to use the Metro Apps. They still work if you use a mouse.

    You are overthinking something that all of the work has already been done.
      My System SpecsSystem Spec

  7. #7


    Central IL
    Posts : 3,468
    Linux Mint 17.2


    Using the Powercfg /h off, disables Hibernate, it does not place the unit into hibernate mode.
      My System SpecsSystem Spec

  8. #8


    Posts : 301
    Windows 8 Pro


    Powercfg /h off will put into Standby with: rundll32.exe powrprof.dll,SetSuspendState (not necessary to add Standby)
    Powercfg /h on will put into Hibernate with: rundll32.exe powrprof.dll,SetSuspendState (not necessary to add Hibernate)

    Give this a try:
    Code:
    ' HIBERNATE.vbs
    If WScript.Arguments.length =0 Then
        Set objShell = CreateObject("Shell.Application")
        objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    Else
        Set objShell = CreateObject("WScript.Shell")
        objShell.run "powercfg /hibernate on"
        objShell.run "rundll32.exe powrprof.dll,SetSuspendState"
    End If
    
    'STANDBY.vbs
    If WScript.Arguments.length =0 Then
        Set objShell = CreateObject("Shell.Application")
        objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    Else
        Set objShell = CreateObject("WScript.Shell")
        objShell.run "powercfg /hibernate off"
        objShell.run "rundll32.exe powrprof.dll,SetSuspendState"
        WScript.Sleep 200
        objShell.run "powercfg /hibernate on"
    End If
      My System SpecsSystem Spec

  9. #9


    Central IL
    Posts : 3,468
    Linux Mint 17.2


    Again it does not. That command disables the capability of Hibernate to be used on the machine. Stop trying to reinvent the wheel, when the work has already been done.
      My System SpecsSystem Spec

  10. #10


    Posts : 301
    Windows 8 Pro


    You must understand that if I am not satisfied, I will pursue the matter to the end. I am now satisfied that this issue has been resolved and works. Here is the gadget that I wrote.

    Click image for larger version
      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
Cannot run elevated shortcut from html
Related Threads
Elevated task manager disable in User Accounts and Family Safety
Hi I want to be able to disable elevated task manager, but not normal task manager for certain accounts How would I do this? OS: Windows 8 Professional Thank you
How to See if Process is running as administrator (elevated) in Windows 8 and 8.1 This tutorial will show you how to determine if a program or process is running as administrator (elevated) or not in Windows 8, Windows RT, Windows 8.1, and Windows RT 8.1. Here's How:
Hey. I have downloaded a game on steam called "Dragon Nest". When I start the game up, a UAC window pops up and tells me that I need administrator privileges. No problem. This is my laptop so I am the admin. The problem is that I don't want this program to require elevated privileges and I am...
Solved Only have elevated adminstrator login in User Accounts and Family Safety
I need to find my login in windows 8 pro. I used Winaero User List Enabler and restarted it boots to elevated adminstrator account and gives no options and doesn't ask for a password. Not sure which tutorial applies to my situation. I think I need to create another user for me. I lost my account...
trying to get full elevated admin privileges in User Accounts and Family Safety
I am the admin and sole user. I tried to move a system file and the dialogue stated you do not have elevated privileges. So, my admin priv is not elevated. thank you in advance, M
Solved elevated command prompt...huh? in General Support
how do I open an elevated command prompt?
Hi, For those who'd like to use the power of a permanent admin (can of course be reverted) prompt here's how: Elevated Command Prompt Shortcut - Windows 7 Forums Open Explorer and drill down to: C:\Users\"Username"*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools
Eight Forums Android App Eight Forums IOS App Follow us on Facebook