Examples Delphi

changing the windows temp directory
Win API call
Use CreateProcess to start the other app.
CreateProcess has the parameter lpEnvironment where
you can specify things like the temp directory.
This is just a guess, but you could probably do it something
like this :
================= Code Begins Here ===============
function CreateProcessSimple(sExecutableFilePath : string ):
string;
var
pi: TProcessInformation;
si: TStartupInfo;
begin
FillMemory( @si, sizeof( si ), 0 );
si.cb := sizeof( si );
CreateProcess(Nil, PChar( sExecutableFilePath ),
Nil, Nil, False, NORMAL_PRIORITY_CLASS,
PChar('temp=c:\mydocs' + #0 + 'tmp=c:\mydocs' + #0 +
SomeOtherVar), Nil, si, pi );
{ "after calling code" such as
the code to wait until the
process is done should go here }
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
end;
================= Code Ends Here ===============
You may also want to use GetEnvironmentStrings and use that
(with a different temp directory), and use the results of that in the
CreateProcess call. The application may depend on other
environment variables besides the temp directory.
================= Code Begins Here ===============
fprocedure TForm1.Button8Click(Sender: TObject);
var
pBase, pExtra : pchar;
strAdd : string;
EnvStringList : TStringList;
EnvListCount : Integer;
begin
EnvStringList := TStringList.Create;
pBase := GetEnvironmentStrings;
if pBase = nil then exit;
pExtra := pBase;
while pExtra^<>#0 do
begin
strAdd := pExtra;
EnvStringList.Add(strAdd);
pExtra := pExtra + length(strAdd) + 1;
end;
FreeEnvironmentStrings(pBase);
// Now lets add these to a ListBox so we can see them
For EnvListCount := 0 To EnvStringList.Count - 1 Do
ListBox1.Items.Add(EnvStringList.Strings[EnvListCount]);
EnvStringList.Free;
end;
================= Code Ends Here ===============
Both of those code snippets came from my web page, which
currently has no home.
Happy Coding
On 29 Jan 2001, at 10:05, Mike Benowitz wrote:
> Does anyone know of a way to change the windows temp directory.
>
> I'm using an app that always saves to c\windows\temp. I would like to
> change the temp directory to c:\mydocs and when the app closes set the temp
> directory back to c:\windows\temp.
>
> Thanks,
>
> Mike Benowitz
> FUND E-Z Development Corp.
> mikeb@fundez.com
> www.fundez.com
> (914) 696-0900
****************************************************************************************
ANOTHER EXAMPLE
The windows function GetTempPath reads the environment variable TMP and TEMP.
The windows help says that you can change the environment variable for the current process.
The SetEnvironmentVariable function sets the value of an environment variable for the current process.
BOOL SetEnvironmentVariable(
LPCTSTR lpName, // address of environment variable name
LPCTSTR lpValue // address of new value for variable
);

Parameters
lpName
Points to a null-terminated string that specifies the environment variable whose value is being set. The operating system creates the environment variable if it does not exist and lpValue is not NULL.
lpValue
Points to a null-terminated string containing the new value of the specified environment variable. If this parameter is NULL, the variable is deleted from the current process's environment.

Return Values
If the function succeeds, the return value is nonzero.
******************************************************************************
ANOTHER SUGGESTION
try setting environment variables TEMP o TMP,
with command line,
set temp=c:\mydocs
set tmp=c:\mydocs
i hope this help
Hugo
At 10:05 AM 29/01/2001 -0500, you wrote:
>Does anyone know of a way to change the windows temp directory.
>
>I'm using an app that always saves to c\windows\temp. I would like to
>change the temp directory to c:\mydocs and when the app closes set the temp
>directory back to c:\windows\temp.