Sign in to follow this  
Followers 0
Guest Davebert

New user, Can AutoIt delete or run once?

5 posts in this topic

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

:)

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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

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