Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

can copy running application itself in vc ?

Posted on 2002-03-25
4
Medium Priority
?
206 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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  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 concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

722 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