Article View: borland.public.cppbuilder.nativeapi
Article #4770Re: How to unmap file ?
From: Bob Gonder
Date: Wed, 30 Nov 2005 19:22
Date: Wed, 30 Nov 2005 19:22
40 lines
2326 bytes
2326 bytes
Ed Mulroy wrote:
>I have concerns about doing it that way. One item is the race condition.
Yep.
>The gross way to have a program delete itself is to create a batch file
Yes quite gross.
>A variant is to create an executable which delays and then
>deletes and execute it but antivirus programs may not be happy with this
>technique.
NAV doesn't complain, but I'm replacing, not patching, the exe with an
update..
A second program that takes an ascii PID can do quite well.
if( argc > 3 ) /* if launched, wait for launcher to quit */
{
ProcessID = atol(argv[3]);
OldProcess = OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE, ProcessID);
if( OldProcess == NULL )
{
MessageBox( 0, "Did not aquire old process handle",
"Failure!",MB_OK|MB_ICONSTOP|MB_TOPMOST);
return 9;
};
WaitForSingleObject(OldProcess, INFINITE);
CloseHandle(OldProcess);
Sleep(4000); // give Windows more time to release
/* delete/update the original exe */
{ ... }
};
The origianl exe launches the updater with its ASCII PID as a
parameter. To be generic, I also pass the original exe name, and the
name of the replacement file.
Technical Details
Message-ID:
<f3tro19706s7e3vbps5ea68t38jp6dks43@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4344fc1d$1@newsgroups.borland.com> <438db468@newsgroups.borland.com> <438dcf60$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dbb65edaa3343676 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: How to unmap file ? Date: Wed, 30 Nov 2005 11:22:31 -0800 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <f3tro19706s7e3vbps5ea68t38jp6dks43@4ax.com> References: <4344fc1d$1@newsgroups.borland.com> <438db468@newsgroups.borland.com> <438dcf60$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.69.90.203 X-Trace: newsgroups.borland.com 1133378507 69.69.90.203 (30 Nov 2005 11:21:47 -0700) Lines: 42 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail