Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bat file self delete

Posted on 2003-12-03
4
Medium Priority
?
2,763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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