Solved

bat file self delete

Posted on 2003-12-03
4
2,757 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:free-k
  • 2
4 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 9867739
Remove the pause statement.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 9867766
Your script may also hang on the registry import.
Try this instead:

@echo off
regedit /s c:\update.reg
del %0.bat
0
 
LVL 3

Accepted Solution

by:
cwp earned 50 total points
ID: 9869227
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
 

Author Comment

by:free-k
ID: 9872654
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

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question