Computer Hope

Microsoft => Microsoft DOS => Topic started by: Jonas Wauters on May 03, 2007, 03:06:35 PM

Title: (solved)defragmentation at startup.(Pause for x many seconds?)
Post by: Jonas Wauters on May 03, 2007, 03:06:35 PM
Is there a way how you can take a pause for x many seconds in a batch file?
Without having to download the wait attribute.

Thanks in advance Jonas
Title: Re: Pause for x many seconds?
Post by: Nuclear Playboy on May 03, 2007, 05:13:24 PM
You can use the
Code: [Select]
TIMEOUT  nn    [RK] Only works if you have the NT resource kit.

 nn = seconds.

Do you have RK?
Title: Re: Pause for x many seconds?
Post by: 2k_dummy on May 04, 2007, 07:34:30 AM
ping 1.1.1.1 -n 10 -w 1000 >%tmp%null

This example would be a 10 second delay. Change the 10 to the desired number of second and insert the line at the point you want the delay. Its not as precise as a real timer but its close enough.
Title: Re: Pause for x many seconds?
Post by: Dark Blade on May 05, 2007, 05:54:44 PM
Code: [Select]
@echo off
set /p TIMER=How long to wait?
cls
ping 1.1.1.1 -n %TIMER% -w 1000 > nul

Use that code if you want to prompt for how long to wait.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 06, 2007, 03:40:29 AM
I do not have RK and its not a real solution for my problem.
I want to create a program with I save on my shared drive.
The program needs to defrag all the drives and the user should have the chose with he wants to do after the program is done.
This is it thaks to this forum
Code: [Select]
Title Defragmenteren
@echo off
cls
echo Dit programma is gemaakt door Jonas Wauters.
echo Dit programma defragmenteerd C: en D: schijf.
echo Defragmentatie zorgt voor een optimaal gebruik van uw harde schijven.
Ping 1.1.1.1 -n 15 -w 1000 > nul
cls
echo Wat wil je doen nadat het process voltooid is?
echo 1:De computer afsluiten
echo 2:De computer opnieuw opstarten
echo 3:Dit venster afsluiten en gewoon verdergaan met werken
Set /P Quit=Typ (1,2of 3)
Vol C:
defrag -f C:
If not exist d: GOTO e
vol d:
defrag -f d:
:e
if not exist e: GOTO f
vol e:
defrag -f e:
:f
if not exist F: goto g
vol f:
defrag -f f:
:g
If %Quit%=1 then goto Q1
If %Quit%=1 then goto Q2
Exit
:Q1
Shutdown -s -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer afsluiten!"
:Q2
Shutdown -r -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer opnieuw opstarten!"
shutdown -s -t 01
It is written in dutch
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 06, 2007, 09:54:15 AM
Can you create a count down that you can skip with the enterkey?
If this isn't possible please say so.
Thanks
Title: Re: Pause for x many seconds?
Post by: Nuclear Playboy on May 06, 2007, 03:03:50 PM
Out of curiosity, what does the shutdown comment say?  :)
Title: Re: Pause for x many seconds?
Post by: Dark Blade on May 08, 2007, 12:02:49 AM
If you wanted, you could download the Wait program for Command Prompt, where the computer waits a said amount of time, but it can aborted with space.

I don't know the site where you can download it, so just Google it. (if anyone knows, post it)
Title: Re: Pause for x many seconds?
Post by: WillyW on May 08, 2007, 09:12:03 AM
If you wanted, you could download the Wait program for Command Prompt, where the computer waits a said amount of time, but it can aborted with space.

I don't know the site where you can download it, so just Google it. (if anyone knows, post it)

See:
http://www.computerhope.com/forum/index.php/topic,34932.0/all.html

« Reply #16 on: May 01, 2007, 11:24:57 AM »



But -  the original poster of this thread is also the original poster of that thread, and is therefore aware of it.    I think he meant to exclude it as an option, in his first post here when he referred to it as "wait attribute".



Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 08, 2007, 09:24:40 AM
Wait isn't usefull in this situation.
I use it on the network and it is used by 4 computers sow if I use Wait then all those computers should download the wait applecation.
Code: [Select]
:Q1
Shutdown -s -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer afsluiten!"
:Q2
Shutdown -r -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer opnieuw opstarten!"
shutdown -s -t 01
Comment of Q1 Save all your setting before the countdown is completed because then the computer will be forced to shutdown.
Comment of Q2 Save all your setting before the countdown is completed because then the computer will be forced to restart.
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 08, 2007, 04:36:37 PM
The ping is useful for a generic timer where you don't know what resources will be available, or you don't want to rely on extra programs, so that is a great solution.  I do have 1 comment and 1 suggestion, though:

The reason to ping localhost instead of a real IP address is many reasons.  Post back if you really want to know what some of them are.

The reason you need to add 1 to the number of seconds to ping is because the first ping gets executed immediately, and there is about 1 second between the rest.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 13, 2007, 08:44:55 AM
Yes it would be wonderful to know that reason.
And what do you mean white about one second?(Does it change from time to time or is it always just e.g. .999 seconds or something?)
And is there any way how I can run my program when I boot just before I get the welcome screen?
Thanks for the reply.
sorry that I noticed it so late.

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: 2k_dummy on May 13, 2007, 09:53:50 AM
Quote
Ping 1.1.1.1 -n 15 -w 1000 > nul

1.1.1.1 is not a public address. It is non existant. You can substitute your local host if desired.
-n 15 is the number of pings to be sent
-w 1000 is the time, in ms, to wait between pings (1000ms = 1 sec)

As I stated before, it is not perfect, but is close enough.

Quote
the first ping gets executed immediately

Its almost immediate. So adding an extra second will make it more accurate. However, there is a small amount of overhead so it would be slightly more than (time). Slightly over or slightly under, in this case, probably does not matter.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 13, 2007, 03:56:44 PM
No it doesn't matter in this case.
I do have an other question Diskeeper lite gives me the message that I need to defrag when my PC boots.
But to do that white that program I need to buy the full version.
Can't I just change the batch file so I can defrag when my PC boots?

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: 2k_dummy on May 13, 2007, 04:33:27 PM
You could try adding a line at the end of autoexec.nt in the system32 folder. Include the full path to the batch file.
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 13, 2007, 06:09:05 PM
If you want the program to run when Windows loads, you will probably want to put a shortcut to the file (or batch file) in the Startup group.  If there is an icon that lets it run automatically, you can just copy that icon to
C:\Documents and Settings\All Users\Start Menu\Startup
Or you may need a batch file that starts it for you.  Is there a switch to get it to run without clicking an any buttons?  If so you could copy a batch file (or link to the batch file) to the Startup directory.  The batch file would probably look something like:
Code: [Select]
"C:\Program Files\Diskeeper\Diskeeper.exe" /defrag C:Note that I am guessing at the path, filename and switches since it has been a few years since I have used Diskeeper.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 14, 2007, 10:04:39 AM
First of all thanks for answering.
Code: [Select]
echo Wat wil je doen nadat het process voltooid is? [b]What do you want to do after the proces is compeled?[/b]
echo 1:De computer afsluiten [b]Shutdown computer[/b]
echo 2:De computer opnieuw opstarten [b]Reboot computer[/b]
echo 3:Dit venster afsluiten en gewoon verdergaan met werken [b]Just close this window[/b]
Set /P Quit=Typ (1,2of 3)
Can't I just add an option like "Reboot you computer and defrag on startup"
Sow then the computer should reboot and run that program before I get to the welcome screen it should pass the option partition.
It this possible what I'm asking?
Please if this thanks to long for you, than do not spend to much time with it.
I do not want to insist you.
But I do appreciate it.

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 14, 2007, 10:28:58 AM
I don't know much about Diskeeper, but I think the task you want is dependent on your software.   It sounds like what you really want is to schedule a defrag before the OS completes booting, similar to the way you can schedule a CHKDSK /F, is that correct?  If so, is it possible to schedule a defrag to launch at the next boot from within the program?  If you can do it within the program then I don't think it would be too hard to do.  If the program can't do it by itself,  then it is probably not practical to attempt to make the program do this.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 14, 2007, 10:39:19 AM
Yes it is possible white the program but that you have to have the Full version.
And then you have to pay for it.
But thats not really what I want to do.

Isn't it possible to create 2 batch files.
1 the one I allready have. and just add the option to defrag while booting.
When I choose that option than it should create:
You could try adding a line at the end of autoexec.nt in the system32 folder. Include the full path to the batch file.
Then it should create that to the full path of my second batch file.
The second batch file should defragment and then remove that line at autoexes.nt.
Is that possible?

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 14, 2007, 10:49:28 AM
I don't think adding a line to your AUTOEXEC.NT will work.  I could be wrong, but I think that just loads the environment for when DOS programs are loaded from within Windows.  I don't think that the AUTOEXEC.NT gets executed when the computer boots / login, etc.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 14, 2007, 10:59:51 AM
Can it do any harm by just trying it?
Otherwise I'll just add my first batch file to try.
Than how do I have to do that?
By the way thanks for replying this fast.

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 14, 2007, 03:40:03 PM
It won't do any harm by trying it.  You can always remove it from the AUTOEXEC.NT if it causes problems with your PIF files.

I think the better solution is adding a batch file to your startup group.

Starting the Diskeeper program isn't going to be that difficult.  But if you want it fully automated, I think there are buttons and icons to click on to get the defrag started, which will be difficult to script.
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 15, 2007, 10:36:51 AM
I can't edit autoexe.nt or do I have to do it otherwise than right clicking it and go to edit (because edit is missing.)
If I put my Batch file in the startup file than it'll run when I get my desktop and not before the welcome screen sow it will not be able to defrag  the running processes.
Starting the Diskeeper program isn't going to be that difficult.  But if you want it fully automated, I think there are buttons and icons to click on to get the defrag started, which will be difficult to script.
Yes but then it will again be after the welcome screen.
Or am I wrong??

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: 2k_dummy on May 15, 2007, 11:27:41 AM
You can open and edit autoexec.nt in Notepad.
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 15, 2007, 11:29:17 AM
You are right, both ways would be after the welcome screen.

The autoexec.nt won't start the defrag before the welcome screen either, though.  But to edit the file, try this:
Start -> Run -> notepad %windir%\System32\autoexec.nt
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 16, 2007, 03:59:28 AM
If autoexe.nt doesn't extrude before the welcome screen then it also isn't a solution.
Maybe safemode but then there are still some running processes.
Sow I think it is just impossible.
Thanks for helping.

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: contrex on May 16, 2007, 04:34:22 AM
start button
Run
Gpedit.msc
Windows Settings
Scripts (Startup/Shutdown)
Startup
Add Script

Quote
To assign computer startup scripts
Open the Group Policy snap-in.
In the console tree, click Scripts (Startup/Shutdown).
In the details pane, double-click Startup.
In the Startup Properties dialog box, click Add.
In the Add a Script dialog box, type the following information, and then click OK:
Script Name: Type the path to the script, or click Browse to search for the script file in the Netlogon share of the domain controller.

Script Parameters: Type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called //logo (display banner) and //I (interactive mode), type the following: //logo //I


Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 19, 2007, 12:54:52 PM
start button
Run
Gpedit.msc
Windows Settings
Scripts (Startup/Shutdown)
Startup
Add Script

Quote
To assign computer startup scripts
Open the Group Policy snap-in.
In the console tree, click Scripts (Startup/Shutdown).
In the details pane, double-click Startup.
In the Startup Properties dialog box, click Add.
In the Add a Script dialog box, type the following information, and then click OK:
Script Name: Type the path to the script, or click Browse to search for the script file in the Netlogon share of the domain controller.

Script Parameters: Type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called //logo (display banner) and //I (interactive mode), type the following: //logo //I



I've tried this but it doesn't seem to work.
Code: [Select]
Title Defragmenteren
@echo off
cls
echo Dit programma is gemaakt door Jonas Wauters.
echo Dit programma defragmenteerd C: en D: schijf.
echo Defragmentatie zorgt voor een optimaal gebruik van uw harde schijven.
Ping 1.1.1.1 -n 5 -w 1000 > nul
cls
echo Wat wil je doen nadat het process voltooid is?
echo 1:De computer afsluiten
echo 2:De computer opnieuw opstarten
echo 3:Dit venster afsluiten en gewoon verdergaan met werken
Set /P Quit=Typ (1,2of 3):
Vol C:
defrag -f C:
If not exist d: GOTO e
vol d:
defrag -f d:
:e
if not exist e: GOTO f
vol e:
defrag -f e:
:f
if not exist F: GOTO g
vol f:
defrag -f f:
:g
If %Quit%=1 then GOTO Q1
If %Quit%=1 then GOTO Q2
This is the code of the program I want to run after startup I dind't fil in any Parameters.
Or is this my mistake?

Thanks for this post I hope that I just made a mistake.

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 19, 2007, 01:42:33 PM
I think I should make a new topic on this-one.
Should I?
Title: Re: Pause for x many seconds?
Post by: contrex on May 19, 2007, 01:45:19 PM
I think the scripts that execute before login are special in some way.

In your script,

you should not have "then"

If %Quit%=1 then GOTO Q1
If %Quit%=1 then GOTO Q2

What does the second of those lines do?

And where are labels Q1 and Q2?
Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 19, 2007, 02:08:41 PM
Here is the newer vesion:
Code: [Select]
If %Quit%=1 GOTO Q1
If %Quit%=1 GOTO Q2
Exit
:Q1
Shutdown -s -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer afsluiten!"
:Q2
Shutdown -r -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer opnieuw opstarten!"
shutdown -s -t 01
I forgot to post the end of the batch file srry for that.
But still can you give an answer on my question why you methode doesn't work?
By the way thanks for helping.
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 19, 2007, 02:38:38 PM
Instead of pinging "1.1.1.1", you should ping either "localhost" or "127.0.0.1", like:
Code: [Select]
ping localhost -n 5 >nul
Also add some sort of extra text in your string comparison which will reduce the possibility of errors or warnings if the user enters a blank value for "Quit".  Also, use double equal signs (==), like:
Code: [Select]
If {%Quit%}=={1} GOTO Q1
If {%Quit%}=={2} GOTO Q2

Title: Re: Pause for x many seconds?
Post by: Jonas Wauters on May 19, 2007, 02:59:26 PM
This is my newist version after editing those mistakes.
Code: [Select]
Title Defragmenteren
@echo off
cls
echo Dit programma is gemaakt door Jonas Wauters.
echo Dit programma defragmenteerd C: en D: schijf.
echo Defragmentatie zorgt voor een optimaal gebruik van uw harde schijven.
Ping localhost -n 2 > nul
echo 5
Ping localhost -n 2 > nul
echo 4
Ping localhost -n 2 > nul
echo 3
Ping localhost -n 2 > nul
echo 2
Ping localhost -n 2 > nul
echo 1
Ping localhost -n 2 > nul
cls
echo Wat wil je doen nadat het process voltooid is?
echo 1:De computer afsluiten
echo 2:De computer opnieuw opstarten
echo 3:Dit venster afsluiten en gewoon verdergaan met werken
:Retry
Set /P Quit=Typ (1,2of 3):
If {%Quit%}>3 GOTO error
Vol C:
defrag -f C:
If not exist d: GOTO e
vol d:
defrag -f d:
:e
if not exist e: GOTO f
vol e:
defrag -f e:
:f
if not exist F: GOTO g
vol f:
defrag -f f:
:g
If {%Quit%}=={1} GOTO Q1
If {%Quit%}=={1} GOTO Q2
Exit
:Q1
Shutdown -s -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer afsluiten!"
:Q2
Shutdown -r -f -t 25 -c "Sla al u gegevens op voordat de timer op 0 staat want dan zal de computer opnieuw opstarten!"
shutdown -s -t 01
:error
Echo Dit is geen mogelijkheid gevieve opnieuw te proberen.
GOTO Retry
Actually would it have worked on my way?
Again thanks for showing me my mistakes but isn't there a way to run this program at startup before the welcome screen?

Jonas ;)
Title: Re: Pause for x many seconds?
Post by: GuruGary on May 20, 2007, 12:38:17 AM
The only way I can think of to run the script before the Welcome Screen is Contrex's idea about using the Group Policy startup script.  I think the GP startup scripts run before the Welcome Screen.  I also think that if it is going to work, you would need to remove any prompts for the user, as there will not be a console to display any output.  So if it were to work, you would have to change the script to something like
Code: [Select]
defrag -f C:
defrag -f D:
defrag -f E:
defrag -f F:
and it would defrag every time the computer booted.  I think it will run as a process in the background, so you could still log in while it was defragging.  The computer would probably run slow until the defrag was finished, unless you killed the process with a program like TASKMGR or TASKKILL.
Title: Re:defragmentation at startup. (Pause for x many seconds?)
Post by: Jonas Wauters on May 20, 2007, 12:48:18 AM
But F: is a removable disk and isn't always attached.
are you sure that it will not work if I use:
Code: [Select]
defrag -f E:
defrag -f D:
defrag -f E:
if exists F: defrag -f F:
I also think that if it is going to work, you would need to remove any prompts for the user, as there will not be a console to display any output.
How do I have to do this?
I tryed it but I can't find any process My program is called "boot defragmentation.bat" but the only process I can find is "defrag.exe".

(edit)
Jonas ;)
Title: Re: defragmentation at startup.(Pause for x many seconds?)
Post by: GuruGary on May 20, 2007, 09:07:55 AM
The code you have should be fine the way it is written.  Using the code you posted, you have already removed all prompts for the user.

The process you would have to end would be one or more of:
defrag.exe
dfrgntfs.exe
dfrgfat.exe

And you may have to end them as many as 4 times (once for each drive letter).  Or better yet, let them run until they finish, or run the defrag command manually.
Title: Re: (solved)defragmentation at startup.(Pause for x many seconds?)
Post by: Jonas Wauters on May 20, 2007, 09:21:55 AM
OK thanks for all the help I really appreciate it.
Now it works fine.

Jonas ;)