Solved

bat file self delete

Posted on 2003-12-03
4
2,762 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 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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