Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file for Hibernate on/off with admin privilege.

3 Weeks Ago   #1
Lautrec

Windows 7 Ultimate
 
 
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 System SpecsSystem Spec
.
3 Weeks Ago   #2
FreeBooter

Windows 10 Pro x64
 
 

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 System SpecsSystem Spec
2 Weeks Ago   #3
Lautrec

Windows 7 Ultimate
 
 

FreeBooter, thank you.
My System SpecsSystem Spec
.

2 Weeks Ago   #4
TechnoMage2016

Windows 7 Ultimate, SP1, x86
 
 

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 System SpecsSystem Spec
2 Weeks Ago   #5
FreeBooter

Windows 10 Pro x64
 
 

Quote   Quote: Originally Posted by Lautrec View Post
FreeBooter, thank you.
You are very welcome!
My System SpecsSystem Spec
2 Weeks Ago   #6
Layback Bear

Windows 10 Pro. 64/ version 1709
 
 

My System SpecsSystem Spec
Reply

 Batch file for Hibernate on/off with admin privilege.




Thread Tools




Similar help and support threads
Thread Forum
How to run Batch File as Admin?
Hello, I want to know how can i run a Batch File (.bat) as administrator since the Run as Administrator Checkbox in Compatibility tab is gray (can't check)? This is the Batch File: @echo off cd /d "C:\Program Files (x86)\Ubisoft\Far Cry 2\bin" start /realtime FarCry2.exe Should i put...
General Discussion
Remove Admin Rights and Move instead of Copy | Batch file
I have a list of 1000 files names that I put in a text file named list.txt. Need to find them in more folders, sub folders which has 12000+ files in it. The below script works fine but I would like the Admin Right to be removed and also I want the files to be moved permanently into C:\your_files....
General Discussion
Internet Download Manager Admin Privilege
Just now i installed IDM, on my dedicated server. Now when i am opening IDM, I am getting the message that "you are running IDM with admin privileges. IDM wont be able to take over downloads from browser in this mode. So i went to the installation folder, there i checked properties of ...
Software
Launch batch file from the context menu in admin mode
Hi, I found a registry script that creates an option on the windows explorer context menu that allows you to run a batch file. The program that I use within the batch file is producing an access denied error which I dont get if I run the batch file normally. I wondered if this was something to...
General Discussion
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion


Our Sites

Site Links

About Us

Find 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 03:41.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App