Jump to content

script selfrename


sandin
 Share

Recommended Posts

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.

Link to comment
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)
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...