Solved batch file for shutting down windows 7

Dell / DIMENSION 2400
June 12, 2013 at 08:53:34
Specs: Windows 7 64 bit, i7-3770k / 8 gigs
Hi guys,

Finally moved on from XP to Windows 7 Ultimate 64 bit, and I would like to place a short cut on my desktop to do two commands.

I would like the first command to copy everything within a specific folder, like C:\Data and have it copy all of the files from that folder to D:\Data I think I have figured out how to do that with the following command: powershell.exe xcopy C:\Data\*.* D:\Data\*.* /d /e /v /y although I am not sure if the /d /e /v /y are correct. Basically, I want this batch file to run when I shut my machine off, so that it copies any NEW or CHANGED files within that folder at shutdown.

The second command I would like to then do is a shutdown command, and this is the one that is driving me up the wall, cause when i try to run it, it opens a cmd window which just scrolls the shutdown command endlessly.

So in closing I have this for a batch file, but it just doesn't work right:

powershell.exe xcopy C:\Data\*.* D:\Data\*.* /d /e /v /y
shutdown -s -f -t 5


I appologize if this has already been covered in someone elses question.

Thank you.


See More: batch file for shutting down windows 7

Report •


✔ Best Answer
June 12, 2013 at 15:22:55
Okay guys, I thought I would put my results here, for the next guy who might be able to use it:

First of all, I named the batch file shuttingdown.bat

I then went to my desktop, and in a unused space I right clicked and chose NEW and then SHORTCUT. I browsed to the root directory, which is where i placed the shuttingdown. bat file, so that allowed me to just click on the icon on the desktop to do the copying/updating of the files in the specific folders I wanted.

I then set the time to 15 ( which equals 15 seconds ), once windows 7 tells you it is shutting down.

The only thing that is not working, is the folder called C:\Program Files\Qualcomm\Eudora and I believe the problem might be the space between Program and Files, so I will have to do some reading up on that part of it.

Anyways, here is the batch file:

start /w xcopy C:\Data\*.* D:\Data\*.* /d /e /v /y
start /w xcopy C:\MyDocuments\*.* D:\MyDocuments\*.* /d /e /v /y
start /w xcopy C:\Program Files\Qualcomm\*.* D:\Program Files\Qualcomm\*.*
@echo off
shutdown.exe -s -t 15

Thanks guys, for all the help!



#1
June 12, 2013 at 08:57:39
I think I have figured out how to do that with the following command: powershell.exe xcopy . . .
Don't invoke powershell unless you're using powershell. XCOPY works just fine in the command prompt.

it opens a cmd window which just scrolls the shutdown command endlessly.
Don't name your batch file "shutdown."

How To Ask Questions The Smart Way


Report •

#2
June 12, 2013 at 11:50:27
Still no luck.....

I have changed the BAT file so it looks like this:

xcopy C:\Data\*.* D:\Data\*.* /d /e /v /y
@echo off
shutdown -s -t 0

it seems to copy the files that need to be copied, but the shutdown command never is initiated. anyone know what i am doing wrong?


Report •

#3
June 12, 2013 at 11:51:52
I am sorry, but i meant to add, that i made a LNK file of the batch file, and am clicking on a shortcut from the desktop icon, and it does not shut down.

Report •

Related Solutions

#4
June 12, 2013 at 11:59:27
Razor2.3: Don't name your batch file "shutdown."
Also, do not have any files called "shutdown."

How To Ask Questions The Smart Way


Report •

#5
June 12, 2013 at 12:01:09
I guess I need to do a lot of reading, because the batch file DOES work, if I click on it with explore, BUT NOT if I try to run it from an icon on the desktop, which doesn't quite make sense to me.

Report •

#6
June 12, 2013 at 12:01:31
Re #2

Was the shutdown command a typo?
It is normally given as this:

shutdown.exe /s /t 00

EDIT:
I overlapped with #4 & #5 (too slow LOL).

Always pop back and let us know the outcome - thanks


Report •

#7
June 12, 2013 at 12:04:34
the only word "shutdown", is in the batch file itself. I have called the file A.BAT so I'm not sure what is going on. It runs fine if i click on the A.BAT from the explore command, but not from a shortcut that I created on my desktop called A.BAT

Report •

#8
June 12, 2013 at 12:08:04
Any different it you name the shortcut ABAT
ie. without the dot?

Always pop back and let us know the outcome - thanks


Report •

#9
June 12, 2013 at 12:11:42
Guys, THANK YOU very much, as now it is working. I feel like a complete you know what, when Derek brought it to my attention that I left off the .EXE extention.... DUHHHH

On a different note, let me ask you guys the cons of doing this with a batch file. By that I mean, I am running two SSD hard drives C: and D: and I take it that no matter how much has to be copied by the xcopy line, once that is complete, it will then run the shutdown.exe command line. Changing the time to say 10 or more, is that sufficient for any windows 7 shut down work????


Report •

#10
June 12, 2013 at 12:18:35
I think this should do it (wait until completed):

start /w xcopy C:\Data\*.* D:\Data\*.* /d /e /v /y
etc
etc

EDIT:
See #10 below.


Report •

#11
June 12, 2013 at 12:44:29
Re #10

Sorry, my bad, I don't think that will do what you want after all.

Keep watching for better advice.


Report •

#12
June 12, 2013 at 15:22:55
✔ Best Answer
Okay guys, I thought I would put my results here, for the next guy who might be able to use it:

First of all, I named the batch file shuttingdown.bat

I then went to my desktop, and in a unused space I right clicked and chose NEW and then SHORTCUT. I browsed to the root directory, which is where i placed the shuttingdown. bat file, so that allowed me to just click on the icon on the desktop to do the copying/updating of the files in the specific folders I wanted.

I then set the time to 15 ( which equals 15 seconds ), once windows 7 tells you it is shutting down.

The only thing that is not working, is the folder called C:\Program Files\Qualcomm\Eudora and I believe the problem might be the space between Program and Files, so I will have to do some reading up on that part of it.

Anyways, here is the batch file:

start /w xcopy C:\Data\*.* D:\Data\*.* /d /e /v /y
start /w xcopy C:\MyDocuments\*.* D:\MyDocuments\*.* /d /e /v /y
start /w xcopy C:\Program Files\Qualcomm\*.* D:\Program Files\Qualcomm\*.*
@echo off
shutdown.exe -s -t 15

Thanks guys, for all the help!


Report •

#13
June 12, 2013 at 16:01:50
With long file names you have to enclose the paths within quotes. Just to confuse the issue further, the start command sees the first appearance between quotes as a title.

I'm not 100% on the placement of the double quotes but think this (or something very similar) is the way to go with the Qualcomm line:

start /w "" xcopy "C:\Program Files\Qualcomm\*.*" "D:\Program Files\Qualcomm\*.*"

The double quotes after start /w are just a title with no characters in it.

I'm a bit surprised you got away with MyDocuments. Usually in Windows that location has a space in it, so you use a similar procedure to that given.

The other way is to truncate the long file names to 8 characters like this:

start /w xcopy C:\Progra~1\Qualcomm\*.* D:\Progra~1 Files\Qualcomm\*.*

That's OK if the system has allocated 1 (mostly the case). But if there is something else in the same directory starting with progra then it could be progra~2 or whatever.

There are guys on this forum who could sort all this properly in a jif - maybe one will pop by shortly. In the meantime I hope the above is food for thought.

Always pop back and let us know the outcome - thanks


Report •

#14
June 12, 2013 at 18:12:04
Great Derek, and thanks. I shortened it to Progra~1 and that did the trick.

I appreciate all the help you and Razor gave me!!!


Report •

Ask Question