Batch file for Hibernate on/off with admin privilege.


  1. Posts : 15
    Windows 7 Ultimate
       #1

    Batch file for Hibernate on/off with admin privilege.


    Hi,

    I trying to create a batch file for hibernate on/off.
    I tried this:

    @echo off
    :Ask
    echo Activating Hibernate (Y/N)?
    :INPUT
    set /P INPUT=Type input: %=%
    If /I "%INPUT%"=="y" goto yes
    If /I "%INPUT%"=="n" goto no
    echo Incorrect input & goto Ask
    :yes
    C:\Windows\System32\powercfg.exe /hibernate on
    pause
    :no
    C:\Windows\System32\powercfg.exe /hibernate off
    pause

    But I want to use it without "right click -> Run As Admin."
    Can you help me how to do this.

    Thank you. :)
      My Computer


  2. Posts : 206
    Windows 10 Pro x64
       #2

    This batch script will prompt the user to run batch script with administrators privileges.

    Code:
    @echo off
    
    Cd %TMP%
    
    REM  --> Check for permissions
    Reg query "HKU\S-1-5-19\Environment" 
    REM --> If error flag set, we do not have admin.
    if %errorlevel% NEQ 0 (
    ECHO                 **************************************
    ECHO                  Running Admin shell... Please wait...
    ECHO                 **************************************
    
        goto UACPrompt
    ) else ( goto Ask )
    
    :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
    
    
    :Ask
    Cls
    echo Activating Hibernate (Y/N)?
    :INPUT
    set /P INPUT=Type input: %=%
    If /I "%INPUT%"=="y" goto yes
    If /I "%INPUT%"=="n" goto no
    echo Incorrect input & goto Ask
    :yes
    C:\Windows\System32\powercfg.exe /hibernate on
    pause
    :no
    C:\Windows\System32\powercfg.exe /hibernate off
    pause
      My Computer


  3. Posts : 15
    Windows 7 Ultimate
    Thread Starter
       #3

    FreeBooter, thank you. :)
      My Computer


  4. Posts : 714
    Win 7 Pro, SP1, x86, Win-11/Pro/64
       #4

    Some folks just love writing batch files as complicated as possible.

    I like getting a job DONE, and not making it complicated.
    KISS! (keep it simple stupid!)

    I can't even imagine a case where I'd want to turn ON Hibernate, so I use just one simple little batch file to turn it OFF. I do know to right click on the batch file and "Run as Administrator".

    @Echo off
    cls
    Rem: this program will disable Hibernation in windows 7/8.
    powercfg -h off
    Echo: Reboot. Then check for presence of Hiberfil.sys file in root directory.
    pause

    This is one of the first programs that I run when setting up a new install of Win-7.

    Cheers Mate!

      My Computer


  5. Posts : 206
    Windows 10 Pro x64
       #5

    Lautrec said:
    FreeBooter, thank you. :)
    You are very welcome!
      My Computer


  6. Posts : 25,847
    Windows 10 Pro. 64/ version 1709 Windows 7 Pro/64
       #6
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 15:22.
Find Us