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
Solved

can copy running application itself in vc ?

Posted on 2002-03-25
4
200 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

808 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