Jump to content

Recommended Posts

Posted

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.

Posted

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

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
  • Recently Browsing   0 members

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