Sign in to follow this  
Followers 0
sandin

script selfrename

7 posts in this topic

I'm trying to figure out how to selfrename a working script. Any help is more than welcome

here's my attempt:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

MsgBox(0, "scriptname", @ScriptName)
Global $filename = "temp_batch.bat"
if FileExists($filename) then FileDelete($filename)

$Form1 = GUICreate("Set your script's filename here", 320, 65)
$Input1 = GUICtrlCreateInput(@ScriptName, 5, 5, 305, 20)
$Button1 = GUICtrlCreateButton("OK", 190, 30, 120, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            if @Compiled Then
                FileWrite($filename, '@echo off' & @CRLF _
                                        & 'pause' & @CRLF _
                                        & 'rename ' & '"' & @ScriptName & '"' & ' ' & '"' & GUICtrlRead($Input1) & '"' & @CRLF _
                                        & '"' & @ScriptDir & "\" & GUICtrlRead($Input1) & '"')
                ShellExecute($filename, "", @ScriptDir)
                Exit
            Else
                MsgBox(0, "error", "script must be compiled")
            EndIf
    EndSwitch
WEnd

I thought of making a batch file that will do the work for me, but the "pause" part is annoying, and if the user press any key to continue, it remains working...

I tried the "sleep" instead of "pause" but not all windows has "sleep.exe". A winexist batch command would be most useful, but I couldn't find any...

Is there a way to rename the script (without having 2 of them working in the same time, like Copy @scriptname then run it, and then exit the current working one.

Share this post


Link to post
Share on other sites



Just a thought, but what if when your script ran it automatically copied itself in the temp folder ran the copy and closed the original. Then where you have it placed originally can be changed around, because you're running the copy in the temp folder.


Giggity

Share this post


Link to post
Share on other sites

There is "self delete" code here that could easily be modified to handle rename. It's in the forum... you just need to go find it.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

tnx, I've found it

I'll try to modify it for renaming

edit: ok, I tried, but still requires "pause" to hit any key and then continue...

Larry meant the one from the FAQ #Q12 (doesn't use pause)

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
Sign in to follow this  
Followers 0