Jump to content

pc restart then run clean up ?


Recommended Posts

hi im having trouble using my clean up script to clean off some unwanted desktop icons and rerout my start menu programs,,

the problem is my cleanup script is running before the desktop gets a chance to fully setup so the script runs before everthing is fully set so it has nothing to delete and reroute, then its set to auto matically restart the pc

is there any way i can set the pc to restart after everything is finally set up , then have it in the cmd remember to run the cleanup script after the desktop is setup then delete it self ?

Link to comment
Share on other sites


You could entry the files in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager under the REG_EXPAND_SZ value PendingFileRenameOperations. Then the files are deleted after next restart.

Just google for the value name and you'll find enough explanations.

Of course, you also could run a batch through runonceex, but I prefer first method, cause you don't need to call a batch with this.

Edited by Doc Symbiosis
Link to comment
Share on other sites

In the first cleanup cmd you copy a batch file into the startup folder of the user that automatically log's on.. the startup folder wil be loaded after the desktop, this is the way i worked around this problem..

Greets!

Link to comment
Share on other sites

I'm with AndreK on this one, but with a twist: I place a WinRAR SFX called Finish.exe in the All Users Startup folder ($OEM$\$Docs\All Users\Start Menu\Programs\Startup) that unpacks the .cmd file to the temp directory and runs it from there. The last line of the .cmd deletes the SFX from the Startup directory.

Finish.exe WinRAR SFX Archive comment:

Path=%windir%\Temp

Setup=cleanup.cmd

Silent=1

Overwrite=1

Title=...

cleanup.cmd:
@ECHO OFF

::Clean up Start Menu shortcuts

SET AllStart=%systemdrive%\Documents and Settings\All Users\Start Menu

SET AllDesk=%systemdrive%\Documents and Settings\All Users\Desktop

DEL /F "%AllStart%\Set Program Access and Defaults.lnk"

etc.

DEL "%AllDesk%\WinZip.lnk"

etc.

RD /S /Q "%systemdrive%\blah\blah\blah"

etc.

ECHO Y | Del "%systemdrive%\WINDOWS\*.bmp"

DEL "%systemdrive%\Documents and Settings\All Users\Start Menu\blah.lnk"

etc.

DEL /F "%systemdrive%\Documents and Settings\All Users\Start Menu\Programs\Startup\Finish.exe"

CLS

EXIT

Link to comment
Share on other sites

I'm with AndreK on this one, but with a twist: I place a WinRAR SFX called Finish.exe in the All Users Startup folder ($OEM$\$Docs\All Users\Start Menu\Programs\Startup) that unpacks the .cmd file to the temp directory and runs it from there. The last line of the .cmd deletes the SFX from the Startup directory.

Finish.exe WinRAR SFX Archive comment:

Path=%windir%\Temp

Setup=cleanup.cmd

Silent=1

Overwrite=1

Title=...

cleanup.cmd:

@ECHO OFF

::Clean up Start Menu shortcuts

SET AllStart=%systemdrive%\Documents and Settings\All Users\Start Menu

SET AllDesk=%systemdrive%\Documents and Settings\All Users\Desktop

DEL /F "%AllStart%\Set Program Access and Defaults.lnk"

etc.

DEL "%AllDesk%\WinZip.lnk"

etc.

RD /S /Q "%systemdrive%\blah\blah\blah"

etc.

ECHO Y | Del "%systemdrive%\WINDOWS\*.bmp"

DEL "%systemdrive%\Documents and Settings\All Users\Start Menu\blah.lnk"

etc.

DEL /F "%systemdrive%\Documents and Settings\All Users\Start Menu\Programs\Startup\Finish.exe"

CLS

EXIT

yea blinktd that is what i tried also it works like a charm,, thanks for your advice unfortunatly ,, i thought that one up to the day i wrote this thread :) great minds think alike,

Link to comment
Share on other sites

  • 1 month later...

Just a quick follow up from me.

Thanx to member Djé for this simple code that makes a batch file delete itself upon finishing.

DEL /Q /F %0

Hope it helps someonelse down the line. If so give the props to Djé. I'm just a 'LiL middle man.

Link to comment
Share on other sites

Thanx to member Djé for this simple code that makes a batch file delete itself upon finishing.

DEL /Q /F %0

Almost ;)

You need to include in your batch.

@echo off
SetLocal enableextensions

::Your cleanup code below here


::Your cleanup code above here

del /q "%~f0"

EndLocal

Link to comment
Share on other sites

just adding

DEL /Q /F %0

Exit

to the end of my .cmd file worked for me.

I could of just got lucky, but 100% deleted itself. 5 different times or so now too.

Just F.Y.I. because I dang sure can't dispute anyone let alone a 6 star MSFN Expert. :}

Link to comment
Share on other sites

  • 1 year later...

Old post to be sure, but I recall putting the .cmd into the WinRAR SFX (.exe format) because it would not run from Startup. Can't recall now . . . sounds like the batch file is all that is needed, thanks.

Link to comment
Share on other sites

Since this old thread has been resurrected (*I* didn't do it :angel ), I hope someone can explain something to me. I've seen two lines that have been used to delete a currently running cmd file. I understand that DEL /Q /F %0 will DELete the current file (%0 referring to the 0th argument of the original cmd, or the file itself) Quietly (/Q) and Force the deletion even if it's a read-only file (/F).

Then there's DEL /Q "%~f0" which appears to Quietly DELete (something). Obviously, that something is the current cmd file in this case, but how does the "%~f0" get parsed? I can see how "%0" would be better than %0 in case there are spaces in the file name. Is ~f equivelent to /F? Why is it included within the %0 argument? Does the second version do anything different from the first?

I'd like to understand this for general knowledge purposes. I've written thousands of batch files in my life but I've never used the syntax of the second example. DEL /? doesn't even describe it.

Ray

FYI: In case anyone shares my curiosity, I just tested adding quotes to %0 in a simple cmd file. To execute a cmd file with spaces in its name, you already had to enclose the file name in quotation marks ("test this.cmd" as opposed to test this.cmd). %0 already includes the quotation marks and enclosing it in additional quotation marks in the DEL command doesn't work ("%0" expands to ""test this""). So nevermind what I said about "%0" being an improvement over %0. It's not.

Edited by NOTS3W
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...