Sign in to follow this  
Followers 0
=sinister=

Renaming EXE automatically

6 posts in this topic

All I need is my script to rename the exe run to something random. I tried this but it won't run the new exe:

$StringArray = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","")

Func _Randomstring($Lenght)
$String = ""
$I = 0
Do
$String = $String & $StringArray[Random(1,$Stringarray[0])]
$I += 1
Until $I = $Lenght
Return $String
EndFunc

$EXE = IniRead("./Settings.ini", "Settings", "EXE", "NotFound")
$String = _RandomString(7)
If $EXE <> "NotFound" Then
    If Not FileExists("./" & $EXE) Then
FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
    IniWrite("./Settings.ini", "Settings", "EXE", $String & ".exe")
            Run("./" & $EXE, @ScriptDir)
        Exit
ElseIf $EXE = "NotFound" Then
    FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
    IniWrite("./Settings.ini", "Settings", "EXE", $String & ".exe"))
        Run("./" & $EXE, @ScriptDir)
        Exit
EndIf
EndIf

Share this post


Link to post
Share on other sites



I'm not sure what you were trying to do with stuff like "./" but I've never seen that before and I don't think it was working... try this:

$StringArray = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","")

Func _Randomstring($Lenght)
$String = ""
$I = 0
Do
$String = $String & $StringArray[Random(1,$Stringarray[0])]
$I += 1
Until $I = $Lenght
Return $String
EndFunc

$EXE = IniRead("Settings.ini", "Settings", "EXE", "NotFound")
$String = _RandomString(7)

If $EXE <> "NotFound" Then
    If Not FileExists($EXE) Then
        FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
        IniWrite("Settings.ini", "Settings", "EXE", $String & ".exe")
        Run($EXE, @ScriptDir)
        Exit
    EndIf
ElseIf $EXE = "NotFound" Then
        FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
        IniWrite("Settings.ini", "Settings", "EXE", $String & ".exe")
        Run($EXE, @ScriptDir)
            Exit
EndIf
I reworked you elseif statement because I think you had yours nested wrong.

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

using the dot in the ./ just specifies where the directory is (I think) I don't remember where I learned that, but i've been using it my whole life.

Anyways, it still isn't running the exe, it creates it but it won't run it still =\

Share this post


Link to post
Share on other sites

using the dot in the ./ just specifies where the directory is (I think) I don't remember where I learned that, but i've been using it my whole life.

Anyways, it still isn't running the exe, it creates it but it won't run it still =\

You could try changing the forward slashes in the path to backslashes like they should be.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

GEO, when I do that it doesn't even create ("Copy") an exe

--edit--

got it, i'm stupid =P it wouldn't work because the file DID exist hehe

$StringArray = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","")

Func _Randomstring($Lenght)
$String = ""
$I = 0
Do
$String = $String & $StringArray[Random(1,$Stringarray[0])]
$I += 1
Until $I = $Lenght
Return $String
EndFunc

$String = _RandomString(7)
$EXE = IniRead("./Settings.ini", "Settings", "EXE", "NotFound")
If $EXE <> "NotFound" Then
    If Not FileExists("./" & $EXE) Then
FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
    IniWrite("./Settings.ini", "Settings", "EXE", $String & ".exe")
        Do
            Sleep(100)
        Until FileExists(IniRead("./Settings.ini", "Settings", "EXE", "NotFound"))
            Run(IniRead("./Settings.ini", "Settings", "EXE", ""), @ScriptDir)
        Exit
    ElseIf FileExists("./" & $EXE) And @ScriptName <> $EXE Then
        If Not ProcessExists($EXE) Or Not ProcessExists(IniRead("./Settings.ini", "Settings", "EXE", "")) Then
        FileDelete($EXE)
        FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
        IniWrite("./Settings.ini", "Settings", "EXE", $String & ".exe")
        EndIf
        Do
            Sleep(100)
        Until FileExists(IniRead("./Settings.ini", "Settings", "EXE", "NotFound"))
        Run(IniRead("./Settings.ini", "Settings", "EXE", ""), @ScriptDir)
        Exit
EndIf
ElseIf $EXE = "NotFound" Then
    FileCopy(@ScriptFullPath, @ScriptDir & "/" & $String & ".exe")
    IniWrite("./Settings.ini", "Settings", "EXE", $String & ".exe"))
        Do
            Sleep(100)
        Until FileExists(IniRead("./Settings.ini", "Settings", "EXE", "NotFound"))
        Run(IniRead("./Settings.ini", "Settings", "EXE", ""), @ScriptDir)
        Exit
EndIf
Edited by =sinister=

Share this post


Link to post
Share on other sites

Hi,

If @ScriptName = '_renameScript.exe' Then _renameScript(25)
MsgBox(64, @ScriptName, @ScriptName)

Func _renameScript($length = 10)
    Local $sCmdFile = '', $name = '', $flag = 0
    For $i = 0 To $length
        Switch Random(0, 2, 1)
            Case 0
                $name &= Chr(Random(65, 90, 1))
            Case 1
                $name &= Chr(Random(48, 57, 1))
            Case 2
                $name &= Chr(Random(97, 122, 1))
        EndSwitch
    Next
    $name &= '.exe'
    
    FileDelete(@TempDir & "rename.bat")
    $sCmdFile = 'ping -n ' & 50 & '127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'ren "' & @ScriptFullPath & '" ' & $name & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & 'rename.bat' & @CRLF _
             & 'start ' & $name
    FileWrite(@TempDir & "rename.bat", $sCmdFile)
    Run(@TempDir & "rename.bat", @TempDir, @SW_HIDE)
EndFunc   ;==>_renameScript

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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