Hi!
Look at my Uninstall program at the bottom of the .vbs file and how I use
the env shared object and such. So, if you do not have the app, download it and
extract the .vbs file and near the end of the file there is the subroutine that
use the shared env variable...for this purpose.
Bruce
Sent: Monday, June 25, 2012 2:43 AM
Subject: Creating temporary files?
Listers,
Does anyone here happen to have a simple snip-it code, for the following
scenario? Or any good suggestions?
I have an app, that creates a temporary file for a certain task. The creation
of the file has worked fine so far. But since this is only a temporary file, I
had hoped to find a way of storing it in the Temporary folder on the computer.
That is, the folder that is defined in the environment variable as either "tmp"
or "temp", in Windows itself.
I did a bit of research on the net, and found a way to retrieve the contents
of the Temp variable. Here is that code:
Dim Shell: Set Shell = CreateObject( "WScript.Shell")
Dim Environment: Set Environment = Shell.Environment( "System")
Dim Tmp: Tmp = Environment( "Temp")
The code works fine, and returns the contents of the variable. Problem is,
that it returns things like:
%systemroot%\Temp
. Now trying a command like:
Dim FSO: Set FSO = CreateObject( "Scripting.FileSystemObject" )
Dim F: Set F = FSO.OpenTexstFile( Tmp &"\MyFile.tmp", 2, True)
, I get an error thrown at me, telling that the path is invalid. My guess is,
that the OpenTextFile does not like the %SystemRoot% part of the created
filename.
Reason why I tried to get hold of the Temp variable of the OS, is that I then
could have the file stored in the temporary folder, no matter which machine the
app was running on. Is there some kind of property or method, that will handle
the expansion of the %systemroot% into a valid path? We migh even think of
situations where the part between the two percent-signs could be anythhing
else, depending on the computer configuration.
Hope all of this makes any sense. Any good workaround here?
Thanks,