Ignacio

Issue with deleting a compiled script with Filedelete()

5 posts in this topic

#1 ·  Posted

Good day and thanks for your time, recently i made a script to help me to store some info, but i want it to also Move itself (the .exe) to a specific folder (in my case to documents, so i ahve a backupt of the exe), i tried using Filemove(), but i have to chose to run it as admin (even tough im the admin in both pc i tested it) to work, so i tried Filecopy(), and it does copy (and run the script as intended) and since i can simulate to "Move" it i decided to delete it with Filedelete() but im just unable to see how to make it work and delete it

 

$date=@year&@mon&@mday
$log="C:\logs"
$copyto="C:\Users\admin\Documents"

DirCreate($log)
FileCopy(@ScriptDir & "\" & @ScriptName, $copyto)
FileDelete(@ScriptDir & "\" & @ScriptName)

$file = FileOpen($log&"\logfiles"&$date&".htm", 1)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

you can use this instead: @ScriptFullPath

There are several examples in the 'examples forum' on how to create a temp batch file to delete your script...but the bat must have some delay in it, and you script must exit prior to that bat file deleting your script.

Standard Windows behavior to not allow delete of an in use exe.

Another route, is to copy your script, and execute it from the copied location to delete the original script...you can pass in a command line param to know the location.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted

18 hours ago, jdelaney said:

you can use this instead: @ScriptFullPath thanks for the tip, it saves a lot of time

There are several examples in the 'examples forum' on how to create a temp batch file to delete your script...but the bat must have some delay in it, and you script must exit prior to that bat file deleting your script.  im planning on always having it running after starting it so i would need to find a workaraund for it.

Standard Windows behavior to not allow delete of an in use exe. ohhh, that explains a lot.

Another route, is to copy your script, and execute it from the copied location to delete the original script...you can pass in a command line param to know the location. That kind of defeats the purpose, i want it to do it on a single launch.

I found a comspec line that it kind of work, it creates the directiories/files, copy itself on the new directory and deletes itself from where it was launched, but now, since the comspec line forces it to exit and auto delete, i tried making it  to work when it  restarts/rexecute from the intended directory, but it stills keeps deleting itself, even with and "IF" statement, leaving me witouth an exectuble to run it

$date=@year&@mon&@mday
$log="C:\logs"
$exe ="c:\logs\exe"

DirCreate($log)
DirCreate($exe)
If not  FileExists($exe & @ScriptName) Then
FileCopy(@ScriptFullPath, $exe )
$file = FileOpen($log&"\logfiles"&$date&".htm", 1)
Exit (run(@ComSpec & ' /c del/f/q "' & @ScriptFullPath & '"|del/f/q "' & @ScriptFullPath & '"|del/f/q "' & @ScriptFullPath & '"', @ScriptDir, @SW_HIDE))
;example of command line i found
EndIf

$file = FileOpen($log&"\logfiles"&$date&".htm", 1)
;main script after this-----------------------------------

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Remembered in Scite you can type:

selfdelete

(lowercase only) followed by space and it should create a SelfDelete function which you can then use to delete yourself upon exit.

Share this post


Link to post
Share on other sites

#5 ·  Posted

2 hours ago, Subz said:

Remembered in Scite you can type:

selfdelete

(lowercase only) followed by space and it should create a SelfDelete function which you can then use to delete yourself upon exit. I saw it, but from what i understood, im going to re-read it, thanks

OK, thanks to both of you for your time and suggestions.

I managed to make it work the way i wanted (sadly i didt fully grasp how the Exit line worked).

$log="C:\logs"
$exe ="c:\logs\exe"
DirCreate($log)
DirCreate($exe)

DirCreate($log)
DirCreate($exe)
If @ScriptDir <> $exe Then 
FileCopy(@ScriptFullPath, $exe )
$file = FileOpen($log&"\logfiles"&$date&".htm", 1)
Exit (run(@ComSpec & ' /c del/f/q "' & @ScriptFullPath & '"|del/f/q "' & @ScriptFullPath & '"|del/f/q "' & @ScriptFullPath & '"', @ScriptDir, @SW_HIDE))
EndIf

$file = FileOpen($log&"\logfiles"&$date&".htm", 1)
;main script after this-----------------------------------

 

Share this post


Link to post
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

  • Similar Content

    • dascondor
      By dascondor
      I  need to has Opt(GUISetOnEvent,-1) available in my script, but since I'm using koda designer it uses GUIgetmessage is there any work around for this. I'm pretty new to this stuff so any help is great appreciated.
      Any Thoughts?
       
    • guinness
      By guinness
      This post outlines correct usage of reporting a documentation error in AutoIt.

      To report a help file issue, first navigate to Trac and create a new ticket. Ensure that the issue isn't present in the latest available version e.g. beta version and follow the following requirements for submitting:
      Change the "Component" option to Documentation. Change the "Version" option to whichever version you saw the issue in. It's preferred that you check the latest version .e.g. current beta, before submitting the ticket. Be as descriptive as you can when posting an issue, the more information you can provide e.g. where you found the issue and what it should be, will aid in the problem being fixed quickly. Up until now those that have posted have done so in a clear and concise manner, so lets keep it that way please. If this starts to deviate in any way then I will be forced to adopt a more strict approach.
      >Previous 'Report Help File Issues' thread.

      Issues with AutoIt:
      For reporting an issue with AutoIt ensure you've isolated the problem in a small script that reproduces the error, assessed in the General Help and Support Forum that it's not a problem with poorly written code and then if none of those fix the problem, post to Trac for an AutoIt Developer to assess the issue.
    • Tuurngait
      By Tuurngait
      I've been trying to add a hotkey to a script but I only started out earlier today and I am already struggling with the basics (not a big surprise for starting new) anyway I was hoping someone could give me an example on how to make a simple On/Off Hotkey




      #include <Misc.au3>
      Global $Paused
      HotKeySet("{PAUSE}", "TogglePause")
      HotKeySet("{ESC}", "Terminate")
      HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

      $dll = DllOpen("user32.dll")
      Dim $coord[3]
      Func TogglePause()
      $Paused = Not $Paused
      While $Paused
      Sleep(100)
      ToolTip('Script is "Paused"', 0, 0)
      WEnd
      ToolTip("")
      EndFunc ;==>TogglePause
      While 1
      If _IsPressed("1[", $dll) Then ExitLoop
      For $i = 0 To 1024 Step 1

      $coord = PixelSearch( 0, 0, $i, 768, 0xFF0000, 10 )
      If Not @error Then
      MouseMove($coord[0],$coord[1])
      EndIf
      If _IsPressed("1[", $dll) Then ExitLoop
      Next

      WEnd