Welcome Guest ( Log In | Join )

Discover the best free computer help!
Learn more about Geeks to Go by taking the tour. Want to ask a question, reply to a topic, or remove all advertising? It's easy, fast and free. Join today!
Spyware, virus, trojan, fake security or privacy alerts? Please start with our malware cleaning guide.
     
 
Reply to this topicStart new topic
Batch file help, Del command
stettybet0
post Apr 11 2007, 04:00 PM
Post #1


Trusted Tech
Group Icon
Posts: 1,981
OS: Vista Ultimate SP1 x64, XP Pro SP3



I'm never sure where to ask questions about batch files, but since I'm writing it for XP, this is as good a place as any.

My question is: how can I get a batch file to delete itself? I tried "del /f", but to no avail. I was thinking maybe I could get it to "move" itself to the trash can, but how would I do this? (what is the trash can's file location?)
Go to the top of the page
 
+Quote Post
Neil Jones
post Apr 11 2007, 04:48 PM
Post #2


Member 5k
********
Posts: 5,648
From: UK
OS: Windows XP Home Edition Service Pack 3



Not possible AFAIK. Would have been under old DOS, but XP won't let you delete something its using itself. This could also include batch files.
Go to the top of the page
 
+Quote Post
stettybet0
post Apr 11 2007, 04:51 PM
Post #3


Trusted Tech
Group Icon
Posts: 1,981
OS: Vista Ultimate SP1 x64, XP Pro SP3



no chance even by using my "move" to trash can theory? I know a file can move itself... so why not to the trash can? I just don't know how to reference the trash can.
Go to the top of the page
 
+Quote Post
Whiskeyman
post Apr 11 2007, 05:35 PM
Post #4


Tech Apprentice
Group Icon
Posts: 462
From: Central, NY
OS: Win98SE. XP Home



To test this create a folder and place a text file within it. I made a new folder in C:\ named Test. I then created a text file in Notepad named test.txt. I used the following batch file (test.bat) to remove the text file from the folder then delete the batch file itself.

CODE
del C:\Test\test.txt
del test.bat
Go to the top of the page
 
+Quote Post
stettybet0
post Apr 11 2007, 07:56 PM
Post #5


Trusted Tech
Group Icon
Posts: 1,981
OS: Vista Ultimate SP1 x64, XP Pro SP3



umm... im not sure what the text file thing was for... but del .\test.bat works... But why wasn't it working before??? Hmm... the only thing I can think of is that right before I have the file delete itself, I have it run shutdown -r -t 0. So, it begins the restart process immediately. I would think it would be able to delete the file while shutting down, but maybe not... but I need the file to initialize a restart... how can I make it do that and delete itself?!? I tried adding more time before the restart process started, but that didn't help.
Go to the top of the page
 
+Quote Post
Whiskeyman
post Apr 12 2007, 03:04 PM
Post #6


Tech Apprentice
Group Icon
Posts: 462
From: Central, NY
OS: Win98SE. XP Home



Following my same setup.

CODE
shutdown /f /r
del C:\Test\test.txt
del test.bat


The only reason I use C:\Test\test.txt is because I constantly use the Test folder for testing purposes. No sense in continually recreating it. This way only the file located within it gets deleted.
Go to the top of the page
 
+Quote Post
dsenette
post Apr 12 2007, 03:08 PM
Post #7


Ruler of Omicron Persei 8
Group Icon
Posts: 20,860
From: kn-ARGH!-xville Tenn-ARGH!-see
OS: 3.1, 95, 98SE, xp, 2000, NT4, 2003 Standard Edition, linux (various flavors)



when you initiate the shutdown command with the /f command it FORCES anything else running to terminate..therefor as soon as you hit the line shutdwon /f /s it terminates the batch file

why are you trying to delete a batch file as soon as it runs?
Go to the top of the page
 
+Quote Post
stettybet0
post Apr 12 2007, 04:46 PM
Post #8


Trusted Tech
Group Icon
Posts: 1,981
OS: Vista Ultimate SP1 x64, XP Pro SP3



Im using it as part of the installation process for a program of mine to automatically install an included font file. However, once the person runs it, they have no reason to run it again, and it would have errors (the font file to install would no longer be there!) So I want it to delete itself. I need it to restart, because newly installed fonts don't always work immediately unless a restart occurs.

I could write a second batch file that deletes the original one and itself and make a registry file that lets it run on startup, but I really don't want to (more trouble than its worth).
Go to the top of the page
 
+Quote Post
dsenette
post Apr 13 2007, 06:26 AM
Post #9


Ruler of Omicron Persei 8
Group Icon
Posts: 20,860
From: kn-ARGH!-xville Tenn-ARGH!-see
OS: 3.1, 95, 98SE, xp, 2000, NT4, 2003 Standard Edition, linux (various flavors)



well...theoretically...you could have the installer create the second batch that would delete the first and itself in the startup folder...that way as soon as the PC restarts they both get deleted....you could also have it pop up a message box that says "you must restart your computer" and have it delete itself but NOT force the restart
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies / Views Topic Information
No New Posts   2 / 401 4th November 2005 - 09:28 PM
FGM started - last by Swandog46
No New Posts   0 / 288 3rd August 2006 - 08:10 AM
Preeko started - last by Preeko
No New Posts   12 / 416 7th May 2008 - 05:32 AM
Sera started - last by Sera
No New Posts   4 / 496 16th October 2008 - 05:31 PM
pr0n started - last by pr0n

RSS Time is now: 8th January 2009 - 02:32 AM
Advertisements do not imply our endorsement of that product or service. The forum is run by volunteers who donate their time and expertise. We make every attempt to ensure that the help and advice posted is accurate and will not cause harm to your computer. However, we do not guarantee that they are accurate and they are to be used at your own risk.