PDA

View Full Version : Problem creating shortcuts


KevinD
11-04-2008, 12:58 PM
Can someone please tell me what is wrong with the following code?

sFolder = SessionVar.Expand("%AppShortcutFolderName%");
sTarget = SessionVar.Expand("%AppFolder%\\cpsproc.exe");
sArgs = "-L:" .. sFile;
sDescription = sFile;

SetupData.WriteToLogFile( "SCFolder\t" .. sFolder .. "\r\n", true );
SetupData.WriteToLogFile( "SCTarget\t" .. sTarget .. "\r\n", true );
SetupData.WriteToLogFile( "SCArgs\t" .. sArgs .. "\r\n", true );
SetupData.WriteToLogFile( "SCTitle\t" .. sDescription .. "\r\n", true );
Shell.CreateShortcut(sFolder, sDescription, sTarget, sArgs, SessionVar.Expand("%AppFolder%"), sTarget, 0, SW_SHOWNORMAL, nil, "");


The program that is being installed has four configuration settings which the user can select to install or not. In the On Post Install Actions tab I have a table which the names of the config files. a loop checks for the presence of the config file and makes a few modifications if needed. That part works fine.

Next I want the installer to create individual shortucts to the EXE passing the config file as an arugment and using a different name for each. The script fails at the Shell.CreateShortcut line above. The log file returns

Error Script: On Post Install, Line 37 (2300)

The help file describes this as "Could not create the folder for the shortcut.".

I get the same error if the EXE file properties are set to create an icon or not. The SetupData lines return the following which are as expected:


[11/04/2008 17:59:14] SCFolder Kevin Murphy\CPS Processor
[11/04/2008 17:59:15] SCTarget E:\Program Files\Kevin Murphy\CPS Processor\cpsproc.exe
[11/04/2008 17:59:15] SCArgs -L:cps.ini
[11/04/2008 17:59:15] SCDescript cps.ini

The installer is being run on Windows Server 2003.

What am I missing?

Thanks in advance.
Kevin

searcher123
11-04-2008, 04:50 PM
(...)
sArgs = "-L:" .. sFile;
sDescription = sFile;
(...)

First of all, where is sFile defined in your code?

jassing
11-04-2008, 04:53 PM
Error Script: On Post Install, Line 37 (2300)
What am I missing?



Telling us what is on line 37...
If you use home-brew functions in post-install; line 37 could be from global functions or lua script file... not necessarily in post-install actions.

also you're not showing us the right stuff.
On the code you show
SetupData.WriteToLogFile( "SCTitle\t" .. sDescription .. "\r\n", true );
but the output shows
[11/04/2008 17:59:15] SCDescript cps.ini

KevinD
11-05-2008, 01:05 AM
searcher123,
sFile is defined earlier in the code and is the name of the configuration file which is to updated in the loop and for which a shortcut is to be created.

jassing,
Line 37 is the line where the Shell.CreateShrotCut function is called. I thought I mentioned that in my original post but apparently not.

As for the output, the SetupData entries I added to record the values being set and included them to try indicate that the correct values were being set and to show the values being passed to the ShortCut routine but obviously did not include enough explanation.

I did not include the full code as I thought it might be a distraction as it works if I leave out the call to Shell.CreateShortCut. It is now shown below.

-- File list
aCfg = {};
aCfg[1] = "cps.ini";
aCfg[2] = "cps_cpsonly.ini";
aCfg[3] = "cps_threshold.ini";
aCfg[4] = "cpssuspicious299.ini";

sCfgDir = SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\config\\")


-- Loop through files
for i,k in aCfg do
sFile = k;

result = File.DoesExist(sCfgDir .. sFile);
if result then
SetupData.WriteToLogFile( "CfgFile\t" .. sFile .. "\r\n", true )

-- Create shortcut
sFolder = SessionVar.Expand("%AppShortcutFolderName%");
sTarget = SessionVar.Expand("%AppFolder%\\cpsproc.exe");
sArgs = "-L:" .. sFile;
sDescription = sFile;

SetupData.WriteToLogFile( "SCFolder\t" .. sFolder .. "\r\n", true );
SetupData.WriteToLogFile( "SCTarget\t" .. sTarget .. "\r\n", true );
SetupData.WriteToLogFile( "SCArgs\t" .. sArgs .. "\r\n", true );
SetupData.WriteToLogFile( "SCTitle\t" .. sDescription .. "\r\n", true );
Shell.CreateShortcut(sFolder, sDescription, sTarget, sArgs, SessionVar.Expand("%AppFolder%"), sTarget, 0, SW_SHOWNORMAL, nil, "");

-- Add CfgDir to file
sFile = sCfgDir .. sFile;

-- WorkDir
cWorkDir = INIFile.GetValue( sFile, "CPS", "WorkDir" );
if cWorkDir == "" then
cWorkDir = SessionVar.Expand("%ApplicationDataFolderCommon%\\%CompanyName%\\%Pro ductName%\\work");
Folder.Create(cWorkDir);

created = Application.GetLastError();

if created > 0 then
cWorkDir = cTempFolder;
else
SetupData.WriteToLogFile( "Created\tWorkDir" .. cWorkDir );
end

INIFile.SetValue(sFile, "CPS", "WorkDir", cWorkDir);
end

-- RemoteScan Section
-- Folder
CurVal = INIFile.GetValue( sFile, "RemoteScan", "RemoteFolder");
if CurVal == "" then
INIFile.SetValue( sFile, "RemoteScan", "RemoteFolder", "#RemoteFolder#" );
end

-- Drive
CurVal = INIFile.GetValue(sFile, "CPS", "MapTo");
if CurVal == "" then
INIFile.SetValue(sFile, "CPS", "MapTo", "#MapTo");
end

-- Username
CurVal = INIFile.GetValue(sFile, "CPS", "UserName");
if CurVal == "" then
INIFile.SetValue(sFile, "CPS", "UserName", "#UserName");
end

-- Password
CurVal = INIFile.GetValue(sFile, "CPS", "Password");
if CurVal == "" then
INIFile.SetValue(sFile, "CPS", "Password", "#Password");
end
end
end

cTempFolder is created in On Startup as follows:

cTempStart = _TempFolder;
nLast = String.ReverseFind(cTempStart, "\\", false);

cTempFolder = String.AbbreviateFilePath(SessionVar.Expand( "%TempFolder%" ), nLast);

As I said the code works except for the Shell.CreateShortCut call (line 37) this is where it fails.

Kevin

jassing
11-05-2008, 11:53 AM
you're using string.abbriviatepath incorrectly....
sfolder needs to be a Full path; not just a relative path

KevinD
11-05-2008, 01:30 PM
jassing,

Thanks for that. I assumed that %AppShortcutFolderName% would give the full path or when needed the method would know what to do. I didn't spot this.

Thanks again.

Kevin