bat file self delete

I have a little problem.

I have a file that runs and updates sertain registry settings. it is just a little .bat file that runs and then calls the .reg file which gets added into the users registrty.

The bat file is only suppose to run once.

I want the .bat file to delete itself after it has run and I am able to do this if I run it from the command prompt. But if it runs from the startup folder or if I double click on it, it only updates the registry and does not delete itself.

the .bat file looks like this

@echo off
c:\update.reg
pause
del %0.bat
free-kAsked:
Who is Participating?
 
cwpCommented:
When you double click on the batch file, %0 is "[full path to the file]\file.bat". When you run it in the command prompt, you'd usually just type "file", so %0 contains only "file", which will work in your case. So, choose just one method of doing this (running in command prompt or running in startup folder/double clicking on it) and stick with it (del %0.bat or del %0, respectively).
0
 
sirbountyCommented:
Remove the pause statement.
0
 
sirbountyCommented:
Your script may also hang on the registry import.
Try this instead:

@echo off
regedit /s c:\update.reg
del %0.bat
0
 
free-kAuthor Commented:
Hey cwp

Thank you very much for the help and the advice. It works exactly the way I want it to now.

Regards,

Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.