Solved

can copy running application itself in vc ?

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

Independent Software Vendors: 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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.

763 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