reg.exe help please

E

ecellis

Hello, I know this is a wierd request but here it goes... I need to have 1
batch file that does the following:
1) runs chkdsk next time the system restarts
2) add a registry string value to the "runonce" key that will run "defrag.exe"
I am having problems with number 2. Here is what I wrote and why it isn't
working:
reg add hkcu\software\microsoft\windows\currentversion\runonce /v defrag /t
reg_sz /d c:\windows\batfiles\defrag.exe c: -f /f
The problem is that defrag.exe needs the "c:" and I would like to have the
"-f" to force it to defrag even if the free drive space gets low. Since
there is a space between defrag.exe and "c" (I don't know if the ":" is also
causing a problem) the reg.exe program is getting messed up and gives an
error stating "Too many command-line parameters." The next /f is for reg.exe
to force overwriting the existing registry entry without prompting.

I made sure that the rest of the command was right by deleting the "c: -f"
from the end of the command. It made the string value registry entry called
"defrag" with the value "defrag.exe"

I need to keep this as 1 bat file and no other files (no .reg, txt, or other
file). This is something I am making for a friend and he's going to put it
on all his business computers. I'm pretty sure that it is a lot of computers
and his reasoning is that this batch file is going to be put on everyone's
desktop. He doesn't want to have to go to each computer and copy one file to
the desktop and another into the windows directory (or anywhere else), or
have an extra file on the desktop annoying people. It would take him longer
and it is easier to deal with just one file if things get messed up.

So how can I get the path and command switch to be able to be entered with
the reg.exe program?

I told him to just schedule a defrag but he wants to be sure to run chkdsk
first and then defrag. He can schedule the bat file, have it restart, run
chkdsk, then defrag the drive overnight instead of waiting for chkdsk to do
it's job and then manually running defrag before leaving for the night.

Thanks for your help! It's been a long time since I worked in a DOS type
(ok somewhat DOS type hahaha) environment. I'm sure there has got to be
something simple that I am over looking.

Thanks,
Eric
 
P

Pegasus \(MVP\)

ecellis said:
Hello, I know this is a wierd request but here it goes... I need to have
1
batch file that does the following:
1) runs chkdsk next time the system restarts
2) add a registry string value to the "runonce" key that will run
"defrag.exe"
I am having problems with number 2. Here is what I wrote and why it isn't
working:
reg add hkcu\software\microsoft\windows\currentversion\runonce /v defrag
/t
reg_sz /d c:\windows\batfiles\defrag.exe c: -f /f
The problem is that defrag.exe needs the "c:" and I would like to have the
"-f" to force it to defrag even if the free drive space gets low. Since
there is a space between defrag.exe and "c" (I don't know if the ":" is
also
causing a problem) the reg.exe program is getting messed up and gives an
error stating "Too many command-line parameters." The next /f is for
reg.exe
to force overwriting the existing registry entry without prompting.

I made sure that the rest of the command was right by deleting the "c: -f"
from the end of the command. It made the string value registry entry
called
"defrag" with the value "defrag.exe"

I need to keep this as 1 bat file and no other files (no .reg, txt, or
other
file). This is something I am making for a friend and he's going to put
it
on all his business computers. I'm pretty sure that it is a lot of
computers
and his reasoning is that this batch file is going to be put on everyone's
desktop. He doesn't want to have to go to each computer and copy one file
to
the desktop and another into the windows directory (or anywhere else), or
have an extra file on the desktop annoying people. It would take him
longer
and it is easier to deal with just one file if things get messed up.

So how can I get the path and command switch to be able to be entered with
the reg.exe program?

I told him to just schedule a defrag but he wants to be sure to run chkdsk
first and then defrag. He can schedule the bat file, have it restart, run
chkdsk, then defrag the drive overnight instead of waiting for chkdsk to
do
it's job and then manually running defrag before leaving for the night.

Thanks for your help! It's been a long time since I worked in a DOS type
(ok somewhat DOS type hahaha) environment. I'm sure there has got to be
something simple that I am over looking.

Thanks,
Eric

There is no need to hack the registry to do this. All he needs is this:

1. Schedule Job #1 to perform a chkdsk at the desired time.
He can do this with this batch file:
@echo off
echo Y | chkdsk c: /f
echo %date% %time% > c:\chkdsk.log

2. Schedule Job #2 to perform a defrag at boot time:
@echo off
if not exist c:\chkdsk.log goto :eof
del c:\chkdsk.log
defrag /.. /..

The above batch files should work but are untested.

You could use schtasks.exe to schedule the jobs centrally,
without going to each machine.

Personally I think your friend is wasting his time with his
frequent defrags. He won't notice any difference whatsoever
in performce but he risks losing a machine if a power failure
occurs in the middle of a defrag.
 
E

ecellis

Pegasus (MVP) said:
There is no need to hack the registry to do this. All he needs is this:

1. Schedule Job #1 to perform a chkdsk at the desired time.
He can do this with this batch file:
@echo off
echo Y | chkdsk c: /f
echo %date% %time% > c:\chkdsk.log

2. Schedule Job #2 to perform a defrag at boot time:
@echo off
if not exist c:\chkdsk.log goto :eof
del c:\chkdsk.log
defrag /.. /..

The above batch files should work but are untested.

You could use schtasks.exe to schedule the jobs centrally,
without going to each machine.

Personally I think your friend is wasting his time with his
frequent defrags. He won't notice any difference whatsoever
in performce but he risks losing a machine if a power failure
occurs in the middle of a defrag.
Sorry for the slow reply. The guy I am trying to help out was out of town.
I told him what you said but he doesn't want this to be a scheduled task. It
is something he wants to start manually. From what he has told me, his
chkdsk takes a couple hours to complete. He wants to just be able to click
the bat file and then, when the computer is restarted, the chkdsk and defrag
will take care of themselves. Since this will be on many machines, he just
wants to have the single bat file on the desktop.

I have most of this figured out, just I've never really added entries with
the reg.exe program and I am not sure how I can get it to add in the command
(defrag.exe) and all the parameters (c: -f) for the command. The parameters
cause the "reg add" command to error out.

I would really appreciate it if someone could tell me how to get the
following command to work:
reg add hkcu\software\microsoft\windows\currentversion\runonce /v defrag /t
reg_sz /d c:\windows\batfiles\defrag.exe c: -f /f (note that the command is
really only on one line)

Thanks,
Eric
 
E

ecellis

I just figured it out. I tried using the quotes before but there must have
been some other mistake. After adding the quotes the command & parameters
are added to the runonce key.

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top