ktuimala Posted July 2, 2007 Posted July 2, 2007 Is there a way to have a compiled AutoIT script self delete after execution? Currently I am using VBS scripts to do the deletion, but it isn't fool proof.
ChrisL Posted July 2, 2007 Posted July 2, 2007 read this..http://www.autoitscript.com/forum/index.php?showtopic=37289 [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
weaponx Posted July 2, 2007 Posted July 2, 2007 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"' )
Developers Jos Posted July 2, 2007 Developers Posted July 2, 2007 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.
ChrisL Posted July 2, 2007 Posted July 2, 2007 Or you could just use the tried and tested method I linked to before [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Developers Jos Posted July 2, 2007 Developers Posted July 2, 2007 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. It isn't ...whatever you say in any language ... 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.
ktuimala Posted July 5, 2007 Author Posted July 5, 2007 Foolproof Inderdaad ... dat die niet fout kan gaan .... "bij de hand" .... It isn't ...whatever you say in any language ... 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... ). 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.
Developers Jos Posted July 5, 2007 Developers Posted July 5, 2007 (edited) 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 . Edited July 5, 2007 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.
weaponx Posted July 5, 2007 Posted July 5, 2007 My version is only one line and nobody even tried it?
ktuimala Posted July 5, 2007 Author Posted July 5, 2007 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.
Developers Jos Posted July 5, 2007 Developers Posted July 5, 2007 (edited) 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 July 5, 2007 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.
nenadc Posted July 5, 2007 Posted July 5, 2007 I tried your one line version and it works well with my script, I just added @SW_HIDE to hide that dos box RunWait("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.bmp"' , @ScriptDir, @SW_HIDE) cheers
MrCreatoR Posted July 5, 2007 Posted July 5, 2007 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 Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
MrCreatoR Posted July 5, 2007 Posted July 5, 2007 P.SAT command requierd that there will be tasks service runing, so it's not perfect solution Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
apetrunk Posted December 17, 2013 Posted December 17, 2013 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.
Moderators Melba23 Posted December 17, 2013 Moderators Posted December 17, 2013 apetrunk, I realize this is a rather old topicThen 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. M23P.S. Welcome to the AutoIt forum, by the way. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts