Solved

can copy running application itself in vc ?

Posted on 2002-03-25
4
187 Views
Last Modified: 2010-07-27
Hi ,

Anyone know how to copy the executive itself when he is running in vc . I did it but sometimes the operation caused an exception ( does not get successful every time ).

I appreciate any piece of code if available .

Best Regards!
 
0
Comment
Question by:zoushen
4 Comments
 
LVL 6

Expert Comment

by:Triskelion
Comment Utility
Virus?
0
 
LVL 4

Accepted Solution

by:
AssafLavie earned 200 total points
Comment Utility
Try to open it for read access and if you succeed you can copy it:

#include <iterator>
#include <fstream>
{
     std::ifstream f(argv[0], ios::in | ios::binary);
     if (f)
     {
          std::ofstream fout("targetfile.exe", ios::out | ios::binary);
          assert(fout.good());
          copy(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>(),
               std::ostreambuf_iterator<char>(fout));
     }
}
0
 
LVL 11

Expert Comment

by:griessh
Comment Utility
Dear zoushen

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "AssfLavie"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
Comment Utility
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now