Jump to content

__AutoSelfDelete() - AutoDelete the running executable.


zalomalo
 Share

Recommended Posts

Inpired by a script by guinness, here:

'?do=embed' frameborder='0' data-embedContent>>

he gave me an idea and i did another one for autodelete for some compiled scripts i dont want to execute out of his intended directory (privileges stuff). Thanks   :zorro:

; #FUNCTION# ====================================================================================================================
; Name .......:    __AutoSelfDelete; Author: Zalomalo, inspired in guinness's _SelfRename.
; Description.:    AutoDelete executing script because unauthorized bad conditions (bad finemame, wrong path, etc.).
;        The purpose is it autodelete as fast as possible and force relog session after return this function, and exiting.
;        Is assumed the script is running compiled (exe), and all conditions have been set before.
; Do no error comprobations since have no sense for this purposes.
; Parameters:    $iDelay [optional]    An integer value for the delay to wait (in seconds) before beging trying to delete the executable.
; Return values: Success - Returns the PID of the bat file.
;     Failure - Returns 0 & sets @error to non-zero
; -------------------------------------------------------------------------------------------------------------------------------
Func __AutoSelfDelete($iDelay=1)
If Not StringInStr(@ScriptName,'.exe',2) Then Return
Local $sTmpBat=@TempDir &'\TmpFile.bat'
While FileExists($sTmpBat)
    $sTmpBat=@TempDir &'\TmpFile'& Chr(Random(65,122,1)) &'.bat'
WEnd
Local Const $sTmpBatData='@ECHO OFF' &@CRLF _
    & 'PING -n '& Int($iDelay) &' -w 1000 127.0.0.1>nul' &@CRLF _
    & 'TASKKILL /PID '& @AutoItPID &' /F'&@CRLF _        ; The script must have been exited allready, just by the case
    & 'DEL /F /Q "'& @AutoItExe &'"' &@CRLF _
    & 'DEL /F /Q "'& @TempDir &'\*.bat"'
Local Const $hfBat=FileOpen($sTmpBat,2)
FileWrite($hfBat,$sTmpBatData)
FileClose($hfBat)
Return Run($sTmpBat, @TempDir, @SW_HIDE)
EndFunc    ;==>__AutoSelfDelete
Edited by zalomalo

My english shucks, i know it.

Link to comment
Share on other sites

Guinnness's one is _SelfRename(). Well, the purpose is totally diferent. Mine is much more simpler and faster because the needs. I put the context where i going to using it, (autodeleting the script, relog windows sesion without any track) so you can realise:

; #FUNCTION# ====================================================================================================================
; Nombre: _RelogSesion  ; Author: Zalomalo                                                                                      1
; Cierra la sesion de usuario debido a un error o violacion grave (Motivo), despues de escribir el Error en el log.
; -------------------------------------------------------------------------------------------------------------------------------
Func _RelogSesion($CODCall)
   _Error(10,0,0,'Relog}'&@ScriptFullPath&' %'&$CODCall)    ; Descomentar en la definitiva
If $UserGame='adminsuper' Or $UserGame='adminprog' Then
   MsgBox(0x1010,'AVISO:'&$UserGame,'^^ JODER',$CODCall)    ; dejar esto para prevenir fallos
Else
   ;  MsgBox(0x1010,'AVISO:'&$UserGame,'^^ JODER',$CODCall) ; Comentar esto en la definitiva ///
   If $CODCall=3 Then __AutoSelfDelete(3)                   ; Descomentar en la definitiva
   Shutdown(4)                                              ; Intenta cerrar sesion una vez
   Exit($CODCall)                                           ; Descomentar en la definitiva
EndIf
EndFunc ;==>_RelogSesion
Edited by zalomalo

My english shucks, i know it.

Link to comment
Share on other sites

  • Moderators

guinness has a _SelfDelete(), as well as the _SelfRename(), which is why I asked. I put the link in the thread so you can realise:

'?do=embed' frameborder='0' data-embedContent>>

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I also mentioned it in my _SelfRename() thread as well!

Edit: I don't mind, I'm just curious as JLogan3o13 to know how your version brings value?

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Well, its true. I didnt saw it, my fault.  :

To compensate the ridiculous, someone could neeed a simple function to change the Gateways of the NIC in windows 8, by using PowerShell ? :P

Edited by zalomalo

My english shucks, i know it.

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
 Share

×
×
  • Create New...