Solved

bat file self delete

Posted on 2003-12-03
4
2,749 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
Comment Utility
Remove the pause statement.
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now