Jump to content

Failure to delete $OEM$ directories post RunOnceEx


Recommended Posts

Well, I can safely say I am becoming insane. All programs are copied to my %systemdrive% correctly and then installed correctly via RunOnceEx. The last command it runs is a compiled AutoIt script that places a RunOnceEx command to delete the copied $OEM$ directories and then forces a reboot. The problem is, nothing happens!!! The $OEM$ directories remain.

I am using the following method for placing the key into RunOnceEx (I've tried both HKLM and HKCU but nothing is working :realmad: ):

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx", "Cleanup Install", "REG_SZ", "cmd /C RD /S /Q %systemdrive%\install")

The key does not delete upon reboot and nothing happens. I've also tried placing the key in RunOnce and despite it being removed upon reboot, the directory remains!!!!

I've also tried running RD via CMDOW and also tried using XRD but to no avail.

Here's something even more weird, if I place the key into the registry using REG ADD from runonceex.cmd it deletes nearly everything (there is a lock on one of the directories for some unknown reason).

Can anyone help??? I'm at a loss as to why this is occurring... :(

Link to comment
Share on other sites


This Is What I Did

I Inserted A Line In RunOnceEx To Run My Batch File At The End Of My Application Setup That Inserted These Lines Back Into RunOnceEx, Then Rebooted My PC & Deleted My Unwanted Folders

Del /Q Should Work For You, I Still Have Dos Frm Win98 Around, I'm Kinda Partial To It

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Deleteing Extra Setup Folders" /f

REG ADD %KEY%\010 /VE /D "Delete Drivers Folder" /f

REG ADD %KEY%\010 /V 1 /D "Deltree /Y C:\Drivers" /f

REG ADD %KEY%\020 /VE /D "Delete Install Folder" /f

REG ADD %KEY%\020 /V 1 /D "Deltree /Y C:\Install" /f

shutdown.exe -r -f -t 60 -c "Reboot For Cleanup"

Link to comment
Share on other sites

Batch files are much more reliable than trying to include a command in the RunOnceEx. Instead of

cmd /C RD /S /Q %systemdrive%\install

create a cleanup.cmd file with the RD command in it and then call the batch file. I call my batch file directly from the CD drive, so instead of %systemdrive% I use %cdrom% and use a For statement with all drive letters at the beginning of the RunOnceEx batch to identify the correct drive. This seems to work well and allows the cleanup of *any* stray folders or files on the system drive.

In fact, check out Fritz_saxi's flash file for credits (in the MSFN forum) which you can run at the end during that final cleanup and 60 second wait before reboot. It's brilliant! :o)

Edited by DonDamm
Link to comment
Share on other sites

cmd /C RD /S /Q %systemdrive%\install

Well, I cannot fault this. It does work, as tested.

I would possibly consider timing as the issue. Re-adding a entry into reononceex maybe failing? And an entry into runonce, which happens a split second after runonceex, maybe too early also. Something is still running? Which folder, or what file, would be a good clue.

My last entry is an Autoit script, that is executed from the run key, waits for a program to launch, does some startmenu cleaning, that is not available in runonceex, deletes the run key, then deletes itself.

Anyway, try to put this at the end of your autoit file. I would assume it is on the HDD also? This will delete the autoit file, then delete the install folder, by a created temporary batch file. The batch file loops with goto, until the items do not exist no more.

Func OnAutoItExit()
   Local $cmdfile
   FileDelete(@TempDir & "\Scratch.bat")
   $cmdfile = ':loop' & @CRLF _
           & 'del "' & @ScriptFullPath & '"' & @CRLF _
           & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
           & ':folder' & @CRLF _
           & 'rd  /s /q %systemdrive%\Install' & @CRLF _
           & 'if exist %systemdrive%\install goto folder' & @CRLF _
           & 'del ' & @TempDir & '\Scratch.bat'
   FileWrite(@TempDir & "\Scratch.bat", $cmdfile)
   Run(@TempDir & "\Scratch.bat", @TempDir, @SW_HIDE)
EndFunc

Link to comment
Share on other sites

Here A VBS Script That Will Remove A Folder Called Install On %Systemdrive%

Save As DelInstallFolder.vbs

Blue Text Can Be Removed To Take Out The No Folder Msgbox

Red Text Is The Stuff That get Deleted

If Createobject("Scripting.FilesystemObject").FolderExists("\Install") Then Createobject("Scripting.FilesystemObject").DeleteFolder("\Install") Else CreateObject("Wscript.Shell").popup "Folder Is Missing, Nothing To Delete", 3,"No Folder", 0 + 32 End If

If Createobject("Scripting.FilesystemObject").FileExists("\DelInstallFolder.vbs") Then Createobject("Scripting.FilesystemObject").DeleteFile("\DelInstallFolder.vbs") End If

This Write The Clean Up File Then Deletes The Folder And The File

Save As RmInstall.vbs

Dim Fso : Set Fso = Createobject("Scripting.FilesystemObject")

Set TS = Fso.OpenTextFile("\DelInstallFolder.vbs",2,True)

Ts.WriteLine "If Createobject(""Scripting.FilesystemObject"").FolderExists(""\Install"") Then Createobject(""Scripting.FilesystemObject"").DeleteFolder(""\Install"") Else CreateObject(""Wscript.Shell"").popup ""Folder Is Missing, Nothing To Delete"", 3,""No Folder"", 0 + 32 End If "

Ts.WriteLine "If Createobject(""Scripting.FilesystemObject"").FileExists(""\DelInstallFolder.vbs"") Then Createobject(""Scripting.FilesystemObject"").DeleteFile(""\DelInstallFolder.vbs"") End If "

Ts.close

Createobject("Wscript.shell").Run("\DelInstallFolder.vbs")

Edited by gunsmokingman
Link to comment
Share on other sites

Thanks guys... other events have taken me away from putting your replies into action (try like a logon stop error!!! aargghh - note to others, don't delete VGA Save drivers or you may find you can't access WinXP Pro at all, except without doing a repair over the top!!!)...

Will let you know the outcome.. I think it is a timing issue but I'm not sure how to fix it but your comments above have provided some food for thought.

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...