Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[HELP] How to copy itself

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Wed Mar 12, 2008 11:56 am    Post subject: [HELP] How to copy itself Reply with quote

I need my program to copy itself to C:\windows\system32. I have tried lots of stuff but it wont work My program is called FunnyBunny.exe. Heres my code so far


Code:

        Dim FileToCopy As String
        Dim NewCopy As String

        FileToCopy = "C:\test.txt"
        NewCopy = "C:\windows\system32\funnybunny.exe"


        System.IO.File.Copy(FileToCopy, NewCopy)


The part where it says
FileToCopy ="C:\test.txt"
its supossed to be my program but it dont know how to copy it if I dont even know the location of where my program is.

So basically I want my program to copy itself.
Back to top
View user's profile Send private message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Wed Mar 12, 2008 11:59 am    Post subject: Reply with quote

Application.Path & "\App.exe"

Try that

_________________
Back to top
View user's profile Send private message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Wed Mar 12, 2008 12:00 pm    Post subject: Reply with quote

Blader wrote:
Application.Path & "\App.exe"

Try that


SO my new code would be




Code:

        Dim FileToCopy As String
        Dim NewCopy As String

        FileToCopy = "Application.Path & "\App.exe"
        NewCopy = "C:\windows\system32\funnybunny.exe"


        System.IO.File.Copy(FileToCopy, NewCopy)
Back to top
View user's profile Send private message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Wed Mar 12, 2008 12:02 pm    Post subject: Reply with quote

No, it would be

FileToCopy = Application.Path & "\App.exe"

_________________
Back to top
View user's profile Send private message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Wed Mar 12, 2008 12:06 pm    Post subject: Reply with quote

didnt work. I got the blue line under Application.Path

-----------------

I search google and this code gave me the app path.
Code:

dim loc as string
loc= application.startuppath

Back to top
View user's profile Send private message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Wed Mar 12, 2008 12:57 pm    Post subject: Reply with quote

Oh, that would work, I don't use 2008 so I thought it was .Path, in VB6 it is App.Path
Just replace Application.Path with Application.StartUpPath

_________________
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Wed Mar 12, 2008 1:26 pm    Post subject: Reply with quote

Here's how I would do it in c#.
Code:

string location = System.IO.Directory.GetCurrentDirectory() + "\\" + System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe";
            System.IO.File.Copy(location, "c:/WINDOWS/system32/" + System.IO.Path.GetFileName(location));

This way, the program will be moved even if the user renames it.
Back to top
View user's profile Send private message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Wed Mar 12, 2008 1:33 pm    Post subject: Reply with quote

killersamurai wrote:
Here's how I would do it in c#.
Code:

string location = System.IO.Directory.GetCurrentDirectory() + "\\" + System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe";
            System.IO.File.Copy(location, "c:/WINDOWS/system32/" + System.IO.Path.GetFileName(location));

This way, the program will be moved even if the user renames it.


That code is long and confusing.. VB2008 FTW
Back to top
View user's profile Send private message
Blader
I post too much
Reputation: 2

Joined: 19 Jan 2007
Posts: 2049

PostPosted: Wed Mar 12, 2008 1:40 pm    Post subject: Reply with quote

No it's not confusing at all, all it does is gets the current directory, then get the current process's process name, add a .exe to it and copy it
_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Mar 12, 2008 2:54 pm    Post subject: Reply with quote

mageknight wrote:
killersamurai wrote:
Here's how I would do it in c#.
Code:

string location = System.IO.Directory.GetCurrentDirectory() + "\\" + System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".exe";
            System.IO.File.Copy(location, "c:/WINDOWS/system32/" + System.IO.Path.GetFileName(location));

This way, the program will be moved even if the user renames it.


That code is long and confusing.. VB2008 FTW


It would be almost EXACTLY the same in VB. Rolling Eyes
Back to top
View user's profile Send private message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Wed Mar 12, 2008 4:33 pm    Post subject: Reply with quote

Your new code:

Code:
Dim FileToCopy As String
Dim NewCopy As String

FileToCopy = System.Environment.CurrentDirectory & "\file.exe"
NewCopy = "C:\windows\system32\funnybunny.exe"

System.IO.File.Copy(FileToCopy, NewCopy)


or the code from C# above in VB

Code:
Dim location as String
location = System.IO.Directory.GetCurrentDirectory() & "\" & System.Diagnostics.Process.GetCurrentProcess().ProcessName & ".exe"
System.IO.File.Copy(location, "c:\WINDOWS\system32\funnybunny.exe"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites