Jump to content

Recommended Posts

Posted (edited)

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)

 

Edited by Ignacio
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.
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-----------------------------------

 

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.

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

 

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
×
×
  • Create New...