🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi.win32
Article #232

Re: How to create file so it disappears when my app vanishes.

#232
From: Pieter Zijlstra
Date: Fri, 25 Jul 2008 21:36
83 lines
3883 bytes
Ian Boyd wrote:

> > at #1
> > Does it really needs to be deleted instantly when your app is
> > closed or killed?
> No
> 
> > Would a delayed delete until the next reboot of the PC or restart of
> > your program also be an option?
> Yes.
> 
> > Do you need it to work on Vista?
> Yes
> 
> > Do all the users have admin rights?
> No.

I was thinking that you might be be able to use MoveFileEx with 
MOVEFILE_DELAY_UNTIL_REBOOT but that one requires admin rights. Adding
the need for Vista is also not helping much ;-)
I don't know if there is a similar function which can be used by normal
users.


> > WinExecAndWait32V2
> 
> But the gist of it is: what if the associated application finds an
> already running instance, pokes that existing instance to handle your
> file, and the itself closes?

Indeed that would not work in that case.
 

> i'd be saving files in GetTempPath, which every user has their own
> of, and can fully access - whether they're standard user on XP or
> standard user on Vista. My goal is to do one better than leaving
> temporary files forever.
> 
> If you have an alternative solution under #1, i'm definetly
> interested. 


Option #1
It shouldn't be to hard to keep a list in a txt file (or ini-file) of
temporary files you app created and keep that file in the same
directory.

Next make a little utility that can read that ini-file and delete the
files which are in the list. Remove the file from the list when it was
actual possible to delete the file (some will fail to delete when the
file is still in use by another application).

You could start this utility when your application is closed. That
should take care of most of the temporary files assuming that your app
is used frequently (and closed frequently).

Next thing you also might consider is to start this utility at startup
by creating an entry in the RunOnce as soon as a temporary file is
created. See...
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

The utility should also check and remove that entry when it succeeded
in deleting all files mentioned in the ini-file.


Option #2
You might want to switch from using the standard temporary path to a
directory in of the other user paths (CSIDL_APPDATA for instance) to
store the temporary files. Dump all temporary files in this directory
and just delete all files in it when your application closes.
You can then also again use the RunOnce key to empty the folder at
startup of windows...
  DeleteJunk REG_SZ cmd /C del /q "%APPDATA%\YourAppName\YourTemp\*.*"


> But the goal of my post was to hopefully leverage behaviour i saw in
> IE. Turns out that technology cannot be used here.

I don't know of a way to make that work with the bunch of office
applications you mentioned.

-- 
Pieter
Technical Details
Message-ID: <xn0ft423g1qohrp00g@newsgroups.codegear.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <488632ef$1@newsgroups.borland.com> <xn0ft2n4jan6bq003@newsgroups.codegear.com> <488a2f08$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 14438e,f051ab9bb506c4bb
X-Google-Attributes: gid14438e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Pieter Zijlstra" <p.zylstra.notthis@hccnet.nl>
Subject: Re: How to create file so it disappears when my app vanishes.
Newsgroups: borland.public.delphi.nativeapi.win32
References: <488632ef$1@newsgroups.borland.com> <xn0ft2n4jan6bq003@newsgroups.codegear.com> <488a2f08$1@newsgroups.borland.com>
Date: Fri, 25 Jul 2008 23:36:57 +0200
User-Agent: XanaNews/1.18.1.9
Message-ID: <xn0ft423g1qohrp00g@newsgroups.codegear.com>
X-Ref: newsgroups.codegear.com ~XNS:000006A2
X-Ref: newsgroups.codegear.com ~XNS:000006A2
NNTP-Posting-Host: 80.100.173.199
X-Trace: newsgroups.borland.com 1217022633 80.100.173.199 (25 Jul 2008 14:50:33 -0700)
Lines: 83
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 3725