Can a script duplicate itself? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DavidP
Posts: 220
Joined: 10 Aug 2014, 07:31

Can a script duplicate itself?

Post by DavidP » 13 Jun 2021, 15:37

Hi forum,

Is it possible that a running script makes a copy of itself to somewhere else?

And if yes, does it also work after the script is compiled and then executed?

Particularly, will this copy a running, compiled script to C:\Some Existing Path\:

Code: Select all

FileCopy, A_ScriptFullPath, C:\Some Existing Path\*.*

User avatar
DavidP
Posts: 220
Joined: 10 Aug 2014, 07:31

Re: Can a script duplicate itself?

Post by DavidP » 13 Jun 2021, 16:55

Hmm, I just tried it with a script (even before compiling it) -- and it didn't work...

Code: Select all

FileCopy, A_ScriptFullPath, C:\*.*
SoundBeep
ExitApp

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Can a script duplicate itself?  Topic is solved

Post by mikeyww » 13 Jun 2021, 17:07

Use a directory where you have access rights. AHK commands use literal strings.

Code: Select all

FileCopy, %A_ScriptFullPath%, %A_MyDocuments%
If ErrorLevel
 MsgBox, 48, Failure, An error occurred while copying the file.
Else MsgBox, 64, Success, Done!

User avatar
DavidP
Posts: 220
Joined: 10 Aug 2014, 07:31

Re: Can a script duplicate itself?

Post by DavidP » 13 Jun 2021, 17:23

OK the problem was that I forgot to use "%"...

Thanks very much, it works now -- also after compiling!

Post Reply

Return to “Ask for Help (v1)”