Jump to content

copy script to temp then run


nitr0
 Share

Recommended Posts

Im new to the world of scripting and im fighting for almost 3 days to get this to work... I searched this forum like crazy, been viewing examples etc but

I can't find anything usefull, so I desided to plant the question in the forum.

I am trying to make my script "test.exe" to copy itself upon execute to a temp folder, and then execute itself from the temp folder. (so it runs from temp)

And then run the rest of the code, notepad.exe and traymenu etc...

Reason: If someone downloads my test.exe to desktop and execute it, they need to be able to delete the test.exe from desktop. So it needs to be run from temp...

This is my script:

; Script name is test.exe
#requireadmin

DirCreate (@TempDir & "\test")
FileInstall("notepad.exe", @TempDir & "\test\notepad.exe", 1)
FileCopy(@ScriptFullPath, @TempDir & "\test\", 1)

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)

; Tray menu items
$MenuItem1 = TrayCreateItem("Stop")
TrayItemSetOnEvent(-1, "MenuItem1Click")
TrayTip("", "Test", 10, 1)

; Run notepad.exe
Run(@TempDir & "\test\notepad.exe")

While 1
    Sleep(100)
WEnd

Func MenuItem1Click()
    ProcessClose("notepad.exe")
    Exit
EndFunc

Tia

Edited by nitr0
Link to comment
Share on other sites

I Did it like this:

If $CMDLine[0] > 0 and FileExists($CMDLine[1]) and @compiled = 1 Then
    Sleep(100)
    If StringRight($CMDLine[1], 4) = ".exe" then FileDelete($CMDLine[1])
EndIf

If @ScriptDir <> @tempdir & "\test" Then
    DirCreate(@tempdir & "\test")
    FileCopy(@autoitexe, @tempdir & "\test\" & @scriptname, 1)
    Run(@tempdir & "\test\" & @scriptname & ' "'  & @scriptfullpath & '"')
    Exit
EndIf

senthor

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