Solved

can copy running application itself in vc ?

Posted on 2002-03-25
4
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Expert Comment

by:Triskelion
ID: 6893805
Virus?
0
 
LVL 4

Accepted Solution

by:
AssafLavie earned 200 total points
ID: 6893943
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
ID: 6956109
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
ID: 6979154
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 clear a vector as well as how to detect empty vectors in C++.

738 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