Jump to content

Self delete scripts...


Recommended Posts

I came up with an alternative. 2 lines of code.

This will grab the current time, and create a scheduled task (XP / 2000) to delete your files after 1 minute (I used bmp for testing).

#Include <Date.au3>
RunWait ("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.bmp"' )
Link to comment
Share on other sites

  • Developers

or try this:

MsgBox(0, "Running", "Press ENTER to delete ME")
If @Compiled Then Exit Run(@ComSpec & " /c DEL  """ & @ScriptFullPath&"""" , "", @SW_HIDE)
This is not fullproof ... the script could still be in use and thus making this command fail.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

fullproof ??

Foolproof Inderdaad ... dat die niet fout kan gaan .... "bij de hand" ....

OK, lets it make foolproof...

MsgBox(0, "Running", "Press ENTER to delete ME")
If @Compiled Then Exit Run(@ComSpec & " /c PING -n 10 127.0.0.1 | DEL  """ & @ScriptFullPath&"""" , "", @SW_HIDE)

PING delays the DEL command about 10 seconds. Should be enough. Or increase -n 10 to whatever you want. :rambo:

It isn't ...whatever you say in any language ...

:rolleyes:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Foolproof Inderdaad ... dat die niet fout kan gaan .... "bij de hand" ....

It isn't ...whatever you say in any language ...

:whistle:

I used the tried and true method mentioned in the FAQ's

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

I had 75 Kiosk autologin accounts to change the password on (Damn SOX!! Every 6 months!!). Once the script ran I wanted it to be deleted. Unfortunately 5 didn't self delete using this function. The script remained after the computer was restarted. I messed with it a bit and found that the computer shutdown sequence must have beat the script. Therefore the script did not self delete. Not bad 5/75.

However, for this type of maintenance I have chosen to use a VBScript that I have AutoIT create and execute with the AutoIT executable PID as a command line. The VBS monitors the PID until it is gone, deletes itself, deletes the AutoIT executeable, and then restarts the computer. (Yes, VBS can still be good for something... :lmao: ). I know I could put the AutoIT parser executeable on every computer and use au3 scripts the same way, but Corporate IT doesn't like non M$ technologies. I need to protect the AutoIT GEM in my corp!!!

The good thing is. This self delete method works in just about every other instance I tried. Just having your AutoIT script initiate a shutdown and self delete is not fool proof.

Link to comment
Share on other sites

  • Developers

Makes sense that doing a reboot after you shelled the batch file will make the batchfile quit before it performs its task.

One thing you could do is add the Shutdown command at the end of the batchfile to allow the batchfile to kill the autoitscript for sure and then do the reboot ... just a thought . :whistle:

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

My version is only one line and nobody even tried it?

I would have tried it, but it was not conducive to what I needed to do. The shutdown sequence would have interfered.

JdeB, I did have the shutdown command at the end of the script. I imagine that is why only 5 out of the 75 computers the script ran on did not self delete.

Link to comment
Share on other sites

  • Developers

I would have tried it, but it was not conducive to what I needed to do. The shutdown sequence would have interfered.

JdeB, I did have the shutdown command at the end of the script. I imagine that is why only 5 out of the 75 computers the script ran on did not self delete.

I meant putting the SHutdown command in the Batch file created and shelled , not in the script to avoid that the Btach file is terminated before it has performed the Delete command. Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I tried your one line version and it works well with my script, I just added @SW_HIDE to hide that dos box :whistle:

RunWait("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.bmp"' , @ScriptDir, @SW_HIDE)

cheers

Link to comment
Share on other sites

Opt("OnExitFunc", "SelfDestroy")

FileCopy(@ScriptFullPath, @ScriptFullPath & ".bak", 1)

MsgBox(16, "Thats it!", "I am gona kill my self now... goodby :`(", 4)

Func SelfDestroy()
    If Not @Compiled Then
        FileDelete(@ScriptFullPath)
    Else
        $ProgramPath = FileGetShortName(@ScriptFullPath)
        Run(@ComSpec & ' /c ping -n 2 localhost > nul & del /q /f "' & $ProgramPath & '"', '', @SW_HIDE)
    EndIf
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

P.S

AT command requierd that there will be tasks service runing, so it's not perfect solution :whistle:

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 6 years later...

I realize this is a rather old topic, but this could still help out others that find this topic by searching, so why not, eh?

OnAutoItExitRegister("Del")

Func Del ()
   Run(@ComSpec&" /c del /f /q """&@ScriptFullPath&"""","",@SW_HIDE)
EndFunc

This is nice and simple, doesn't rely on any timing events, doesn't create any unnecessary files, and just works.

Link to comment
Share on other sites

  • Moderators

apetrunk,

 

I realize this is a rather old topic

Then please do not necro-post in it as we take a dim view of that. This subject is already covered in the Wiki FAQ which did not exist when this thread was last active. ;)

M23

P.S. Welcome to the AutoIt forum, by the way. :)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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