Jump to content

Recommended Posts

Guest Davebert
Posted

Hi, I read about AutoIt some time ago but didn't realize what I could do with it until today. I was wondering if AutoIt V3 can run a script and either delete itself or delete the exe file I need to run? This is not for malicious purpose as I am a developer and have a copy protection that I want to be able to run a registry type clean to reset some values for a new software release. I probably only need to run it on 2 pc's but don't want the end users to keep the exe that can be used again to reset the protection thereby rendering it useless.

Thanks in advance,

Davebert

:)

Posted

Hmmm...I'm not sure, but I'm a newbie, so I could be wrong.

I think the main problem is that you won't know where the file will be running from. I tried it on a script i'm working on, and it didn't remove the EXE.

If it's a static file location, it still does not work for me. I think you'd have to spawn another process to remove the original file, but then again I'm not sure if that's possible either.

Here's what I was trying, assuming the script is running from the C: drive.

[Note: this did not work...]

While FileDelete("C:\Script.exe") = 0
    $ErrorCount = $ErrorCount + 1
    Sleep(500)
    If $ErrorCount >= 4 Then
        ExitLoop
    EndIf
WEnd
  • Developers
Posted

Func _SelfDelete()
    Local $sCmdFile
    FileDelete(@TempDir & "Scratch.bat")
    $sCmdFile = ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & 'Scratch.bat'
    FileWrite(@TempDir & "Scratch.bat", $sCmdFile)
    Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE)
EndFunc; SelfDelete

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Guest Davebert
Posted

Func _SelfDelete()
    Local $sCmdFile
    FileDelete(@TempDir & "Scratch.bat")
    $sCmdFile = ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & 'Scratch.bat'
    FileWrite(@TempDir & "Scratch.bat", $sCmdFile)
    Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE)
EndFunc; SelfDelete

<{POST_SNAPBACK}>

Thanks for the quick reply. Now I will go learn how to script with AutoIt. I use VB6 now so it looks like it should be easy enough to learn...

Regards,

Posted

Func _SelfDelete()
    Local $sCmdFile
    FileDelete(@TempDir & "Scratch.bat")
    $sCmdFile = ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & 'Scratch.bat'
    FileWrite(@TempDir & "Scratch.bat", $sCmdFile)
    Run(@TempDir & "Scratch.bat", @TempDir, @SW_HIDE)
EndFunc; SelfDelete

<{POST_SNAPBACK}>

JdeB, You are wonderful. :)

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