How do I make a hibernation batch file? - windows

I'm trying to make a batch file that executes a simple command:
shutdown -h
I've created a shutdown.bat file with that exact line in it, yet when I run it, all it does is spam the command prompt like crazy.
I've looked at batch file sites, #echo off seems popular, but doesn't that just hide output while the commands are executed just the same?

It turns out that adding a change directory command to the root of the drive fixes the problem. The final text that I ended up using in the .bat file was:
cd c:\
shutdown /h

I believe I am very late for this but just in case someone else comes across this.
The issue was indeed with the name of the bat file. You were calling shutdown -h and the bat file was called shutdown.bat hence the bat file was calling itself causing the loop of the command prompts. To fix this you either rename the bat file or specify the directory where shutdown is located.

Would love to say I figured this out but I simply googled it.
The code you need is
%windir%System32rundll32.exe powrprof.dll,SetSuspendState
If you go to start -> run and then type this in it should work.
So if you have hibernate enabled in the poweroptions this should also work in a batch file.
Hope this helped you
Edit:
P.s. click the white little V under the arrows (left of this answer) to accept the answer ;)

For shutdown:
c:\windows\system32\shutdown -s -f -t 00
(or do ...shutdown -p -f).
E.g.: set the time -t 1000 and save and run it.
To abort just c:\windows\system32\shutdown -a in different batch file.
Very important point to note: if you locate this batch file in your startup then it will execute the s/h/r immediately. E.g. you create a logoff batch file and you locate it in startup
it will logoff the pc within the given time/immediately. However, when you hold shift when logging then it will abort the logoff batch file otherwise you pc will logoff again and again. You don't have to do this I am not sure if it works on every PC.
Create a user and try it there in case you could not log in. good luck
For restart:
c:\windows\system32\shutdown -r -t 00
For hibernate:
c:\windows\system32\shutdown /h
Reference: https://www.instructables.com/id/Shutdown-restart-or-hibernate-your-computer-on-a/

Related

Why does ffmpeg.exe started from Windows batch file close immediately without waiting for user input?

I searched google for an hour but I could not find anything to fix my issue. I found only "similar" fixes for problems I'm not having.
I am opening ffmpeg.exe from a batch file that only has ffmpeg.exe with no arguments in it and it doesn't work even though it did few hours ago.
If I open command line from the folder and enter ffmpeg.exe it works because it's not closing ffmpeg but waits for my input which is exactly how the batch file worked before.
What could be the issue?
I have not changed the batch file or ffmpeg one or their locations.
Running on Windows 7 x64 if that matters.
Edit: File name is start ffmpeg.bat. It's content is only ffmpeg.exe which used to work. I also tried start ffmpeg.exe and ffmpeg and changed the filename to 1.bat and 1.cmd but neither worked.
Edit2: Sorry i can't explain myself better my english isn't very good, however I will try to explain using these images:
This is what i get if i run CMD from the desktop and enter ffmpeg.exe
This is what I get when i run the batch file (after i added pause)
Batch contents: 1st line=ffmpeg.exe, 2nd line=pause.
As you can see without the pause ffmpeg will terminate and not remain on the screen like the in first image.
I tried renaming the file and I tried to run it as admin but neither worked, Any suggestion why is it suddenly not running as it did yesterday?
So first things first. I suppose you meant your batch file name is ffmpeg.bat and not start ffmpeg.bat but you are calling it from cmd.exe as start ffmpeg.bat?
Regardless, never call your batch file names the same as the executable name.
Then why do you need to run start? You can just call the executable inside the batch file with full path. When doing start it will initiate a new cmd window which is not needed. So this should work just fine.
"C:\program files\wherever ffmpeg is\ffmpeg.exe"
In a batch file it will automatically wait for the external program to close before it will exit the batch. if you are unsure as to why it closes, it probably gave an error. You specifically said it "does not work, even though it worked a few hours ago". That is not conclusive. so then just add a pause at the bottom of your script to catch the exeption.
"C:\program files\wherever ffmpeg is\ffmpeg.exe"
pause
EDIT
After you added screenshots, ffmpeg is still running fine. That is the idea of a batch file is to run and exit when done. ffmpeg.exe obviously completed as it showed you the command is not complete, and will exit. This does not happen when you run from cmd as you have a session in keep mode. So if you want to start the session and wait, then just make your batch like this:
cmd /k ffmpeg.exe

Invalid number of parameters in Batch but not in cmd

I am trying to make a scheduled batch file to run with the volume shadow copy service to copy the outlook.pst file from microsoft outlook.
The commands work properly when i enter them in the command panel but when i setup the same code in a batch file it gives me an invalid number of parameters error in during the second line.
You have to use administrator access on cmd and the batch file for it to even work and i am doing that but i have no clue as to why i get an error only in the batch version but not in cmd?
I found this link helpful.
Its where i found the batch file which simplifies the process incase anyone is wondering.
Heres the code :
CALL MountLatestShadowCopy "C:\MyShadow\"
xcopy /y "C:\MyShadow\Users\%USERNAME%\Documents\Outlookove datoteke\*.pst" "\\hyp\backup"
RMDIR "C:\MyShadow"
pause
Anyone have any ideas as to the cause of my problems? Its supposed to simply copy the .pst file to a server for backup which i will run on a regular schedule.
Outlook is usually the first thing people open when they turn on their computers so i have to use volume shadow copy otherwise getting a copy might be hard on certain computers.
Thanks for the help in advance!

Scheduling automated scripts suite run from schedular

So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.

Running batch file at Windows 7 UNLOCK

I have a very simple .bat file. It only has one line:
powercfg -h off
What this does is turn off the computer's ability to hibernate. It works fine when I double click the file. I can confirm this by going into the command prompt and typing "powercfg /a", which shows me that hibernate is indeed off. The problem is that this batch file doesn't seem to be running at logon even though it's in my Startup folder.
I've tested it by turning hibernate on using the command prompt ("powercfg -h on") and then actually putting my computer into hibernation. Then I turn it back on and log in to Windows. But when I open a command prompt and type "powercfg /a" it shows me that hibernate is still on. It seems the batch file doesn't run at logon even though it is in my Startup folder.
I've also tried making it run from a task scheduled to run at logon, but that didn't work either.
Some ideas:
Make sure you set the Start in and Program/script options of the batch file correctly.
If (1) doesn't work then try moving the .bat file to a directory with basic permissions.
Try to schedule the execution of the batch file like this cmd /c "c:\path\batch.bat"
Also take a look at this: Batch runs manually but not in scheduled task.
I got it to work using Task Scheduler. The problem was that I was using the trigger "At log on," when I should have chosen "On workstation unlock."
It's obvious to me now, but I didn't think of it at the time: hybernating didn't actually log me off, it only locked me out.

Batch file - Remote Copy and Execute issue

I have a batch file that part of it copies a folder and its content to a local directory and then continues through the batch process which then tries to execute the contents of the folder . locally run it works on all wintel os and copies the files from \networkshare\folder*.* to %systemdrive%\temp\ .
I have attempted to use e.g psexec #serverlist.txt -c batfile.bat -s -f -d to copy the file and then execute it remotely how ever the issue is that this will not copy the files when run remotely . I think its a authentication issues after you a have remotely executed the batch file the remote system will not allow me to access/authenticate the networkshare
i have tried xcopy , copy , robocopy .
AFAIK you can only authenticate against the next hop using implicit credentials. Connection attempts from the first hop to a second hop will fail, even if your user has the required permisssions. See e.g. here for an explanation.
Try this:
psexec #serverlist.txt -u %USERDOMAIN%\%USERNAME% -d -c batfile.bat
Use explicit credentials so you're authenticated against the remote host. With that the second hop will be the next hop for your authenticated session. Don't run the script as LOCAL SYSTEM (-s), because that account is restricted to local resources.
I've had this issue in the past. Instead of trying to copy/run the BAT file just run the script things from a UNC path if you are able to. I think the problem lies in the BAT file not actually able to run through PSEXEC and copy like you think. Does it give an exit code?
Here's an example I used a while ago to install Adobe reader. I tried to do it through a batch file but no dice. I could not get it to run within the batch file whether I copied it or not. I can't remember the exact reason, I think it had something with the way a batch file is called in the system and runs in some sort of local context. Don't quote me on that though as I can't remember the exact why.
Here is my code example:
psexec /accepteula \\%computer% -s cmd /c msiexec /i "\\UNC\Software\adobe\Adobe Reader 7.0.9.msi" TRANSFORMS="acrobat7.mst" /qn

Resources