| View previous topic :: View next topic |
| Author |
Message |
OSIRIS Grandmaster Cheater
Reputation: 0
Joined: 27 Aug 2006 Posts: 654
|
Posted: Wed Mar 12, 2008 11:56 am Post subject: [HELP] How to copy itself |
|
|
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 |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Wed Mar 12, 2008 11:59 am Post subject: |
|
|
Application.Path & "\App.exe"
Try that
_________________
|
|
| Back to top |
|
 |
OSIRIS Grandmaster Cheater
Reputation: 0
Joined: 27 Aug 2006 Posts: 654
|
Posted: Wed Mar 12, 2008 12:00 pm Post subject: |
|
|
| 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 |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Wed Mar 12, 2008 12:02 pm Post subject: |
|
|
No, it would be
FileToCopy = Application.Path & "\App.exe"
_________________
|
|
| Back to top |
|
 |
OSIRIS Grandmaster Cheater
Reputation: 0
Joined: 27 Aug 2006 Posts: 654
|
Posted: Wed Mar 12, 2008 12:06 pm Post subject: |
|
|
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 |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Wed Mar 12, 2008 12:57 pm Post subject: |
|
|
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 |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Wed Mar 12, 2008 1:26 pm Post subject: |
|
|
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 |
|
 |
OSIRIS Grandmaster Cheater
Reputation: 0
Joined: 27 Aug 2006 Posts: 654
|
Posted: Wed Mar 12, 2008 1:33 pm Post subject: |
|
|
| 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 |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Wed Mar 12, 2008 1:40 pm Post subject: |
|
|
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Mar 12, 2008 2:54 pm Post subject: |
|
|
| 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.
|
|
| Back to top |
|
 |
Estx Expert Cheater
Reputation: 0
Joined: 04 Mar 2008 Posts: 172
|
Posted: Wed Mar 12, 2008 4:33 pm Post subject: |
|
|
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 |
|
 |
|