PDA

View Full Version : Variable question


KevinD
10-14-2008, 11:46 AM
Is the %TempFolder% variable represent the temporary folder on the system the install runs on, as the hep sems to indicate, or the folder the setup is running from?

I have used a PostInstall action to create an entry in an INI file to set a working directory for a program. However, when I check the entry it refers to a folder which does not exists. This is the action I use:

-- CPS.INI
result = File.DoesExist(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\cps.ini"));
if result then
-- WorkDir
CurVal = INIFile.GetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\\\cps.ini"), "CPS", "ScanFolder");
if CurVal == "" then
INIFile.SetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\\\cps.ini"), "CPS", "WorkDir", SessionVar.Expand("%TempFolder%"));
end

-- ScanFolder
CurVal = INIFile.GetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\\\cps.ini"), "CPS", "ScanFolder");
if CurVal == "" then
INIFile.SetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\\\cps.ini"), "CPS", "ScanFolder", SessionVar.Expand("%SystemDrive%"));
end
end

Kevin

upeters
10-14-2008, 08:28 PM
You could try this:


result = File.DoesExist(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\cps.ini"));
if result then
-- WorkDir and ScanFolder
CurVal = INIFile.GetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\cps.ini"), "CPS", "ScanFolder");
if CurVal == "" then
INIFile.SetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\cps.ini"), "CPS", "WorkDir", _TempFolder);
INIFile.SetValue(SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\cps.ini"), "CPS", "ScanFolder", SessionVar.Expand("%SystemDrive%"));
end
end

Additionally, in at the Command Prompt (DOS window), you could check if the TMP/TEMP environment variables are set correctly. At the prompt, type "SET TMP" and press Enter, then "SET TEMP" and press Enter again. Those environment variables should point somewhere, otherwise SUF could have difficulties to define the location of the temporary folder...

Ulrich

KevinD
10-15-2008, 01:10 PM
Ulrich,

The code I provided works and does store a value in the INIFile. However, the problem is that the value written is not the same returned by the TMP and TEMP environment variables.

When the program runs and tries to copy a file to the folder set by the installer it fails because the directory does not exist. That is why I was asking if the variable returned the folder used by the installer (if sub folder of the TEMP) or the TEMP folder itself.

As yet I have not had a chance to test it on another machine yet.

Kevin

upeters
10-15-2008, 01:47 PM
Hi Kevin,

it makes no little to have a different folder written in the INI file than those appointed to by the environment variables, if you don't change the environment by yourself at some moment of your install...

If everything else fails, you could try to save _TempFolder into a custom variable in On Startup, and recover that variable instead of _TempFolder when writing the info into the INI file.

Out of curiosity, what is the path written in your INI file? It should be the TEMP folder by itself, not some subfolder.

Ulrich

KevinD
10-17-2008, 02:42 AM
Ulrich,

I do not knowingly change the TEMP folder setting. The code I posted is all the code I have added to the setup.

When I check the TMP and TEMP enviroment variablesthey both point to a folder called TEMP. After installation checking the INI file the folder is TEMP\2 but that folder does not exist any longer. This is why i was wondering the variable pointed to the folder being used by the installer.

I will try storing the variable before installation begins, write thatm to the II file and see what happens.

Kevin

jassing
10-17-2008, 07:12 AM
Ulrich,

I do not knowingly change the TEMP folder setting. The code I posted is all the code I have added to the setup.

When I check the TMP and TEMP enviroment variablesthey both point to a folder called TEMP. After installation checking the INI file the folder is TEMP\2 but that folder does not exist any longer. This is why i was wondering the variable pointed to the folder being used by the installer.

I will try storing the variable before installation begins, write thatm to the II file and see what happens.

Kevin

Are you using RDP to connect to a system?

For RDP (terminal server) a temp-temp folder is created which is the temporary folder for the user (as if you were at the console) followed by a #. The number is your session #.

Terminal server automatelly removes this folder when you log out.

this is so that if you login twice, your temp files do not collide with your other sessions.

KevinD
10-17-2008, 09:08 AM
I am indeed logging in remotely. It had not occured to me that the folder would be specific to the login and then removed afterwards. Makes sense.

Now to find way a way around it, removing that last folder level. Or I ight just create a working directory for the progrm.

Thanks for the help.

Kevin

jassing
10-17-2008, 09:15 AM
you could use _TempFolder .. "\\.." to get "above"

so; something like: (on startup)


if String.Find("0123456789", String.Right( _TempFolder,1)) > 0 then
cTempFolder = _TempFolder .. "\\..";
else
cTempFolder = _TempFolder
end

And then use cTempFolder in your script instead of _TempFolder.
I don't like to change "built in" variables, as other scripts may rely on them being "right".

Another folder you could use is
_WindowsFolder.."\\temp";
but that would require you to have rights to it...

KevinD
10-18-2008, 09:44 AM
I could not get the code to pick up the folder correctly. It kept using a sub folder of the TEMP and sometimes looking in the INI file it did not look like a valid path ( had '\...\' in the middle of it). Using the selection option in the program indicated the folder did not exist. The code is below.

--cTempStart = SessionVar.Expand("%TempFolder%")
cTempStart = _TempFolder
nLast = String.ReverseFind(cTempStart, "\\Temp", false);
nLast = nLast + 6

sTempFolder = String.AbbreviateFilePath(cTempStart, nLast);
--cTempFolder = _TempFolder;

--if String.Find("0123456789", String.Right( _TempFolder,1)) > 0 then
-- cTempFolder = _TempFolder .. "\\..";
--else
-- cTempFolder = _TempFolder
--end

In the end I resorted to creating a sub folder in the config folder and set that in the INI. Not the solution I was aiming for but it will work.

Thanks for the help.

Kevin

jassing
10-18-2008, 10:23 AM
Not sure where the 3 periods would be coming from.
with your nlast, shouldn't it be 5 not 6? "\\temp" is 5 characters long...

-josh

KevinD
10-19-2008, 10:23 AM
I initially tried it with 5 but it did not seem to work. My understanding from the help file was that it would return a valid path trimming the end off till it got one. The 6 was tor try force it to the 'temp' without success.

Kevin

jassing
10-19-2008, 10:33 AM
I still think using the ".." is a better way to go.