PDA

View Full Version : How to use the MsiGetTargetPath & MsiSetTargetPath?



vivekprasanna
02-28-2005, 01:05 AM
Hi,

I am using IS 10.5. I am working on InstallScript Msi project. How do I use MsiGetTargetPath and MsiSetTargetPath in the Install script code?

thx,
Vivek.

RadhaK
02-28-2005, 01:49 AM
Hi vivek,

Hope this article will be helpful

http://helpnet.installshield.com/Robo/BIN/Robo.dll?mgr=agm&tpc=%2Frobo%2Fprojects%2Finstallshield10-5langref%2FLangrefMsiApis.htm&wnd=InstallShieldLivingHelp%7CMain&agt=wsm&ctxid=search%2Fgsearch.asp

RadhaK
02-28-2005, 02:34 AM
Hi Vivek,

Check this link

http://support.installshield.com/kb/view.asp?articleid=Q105723

or

Hope this example helps you, Try this and if you dont understand let me know



// Include Isrt.h for built-in InstallScript function prototypes



function ExFn_GetValidDrivesList(hMSI)
LIST listID;
NUMBER nResult,nvBuf;
STRING szString,svDir;
begin

//Set a Directory property called DIR1
MsiSetTargetPath(hMSI,"DIR1", "C:\\Test");
//displays the value of DIR1
MsiGetTargetPath(hMSI,"DIR1", svDir, nvBuf);
MessageBox(svDir, INFORMATION);
end;

vivekprasanna
02-28-2005, 09:13 AM
Hi,

I get a blank value for DIR1 using MsiGetTargetPath(). This happens when I use OnBegin(). But when I declare a function ExFn_Sample(HWND) and declare it, I get the value of DIR1 using MsiGetTargetPath(). How do I get the value of DIR1 using OnBegin().

#include "Ifx.h"

#define MSG_TEXT "Please enter the location here."
#define DEFAULT_LOCATION "C:\\Program Files"

function OnBegin()
STRING svLocation, szTitle;
NUMBER nResult;
LIST listID;
NUMBER nResult1,nvBuf;
STRING szString,svDir;
NUMBER hMSI;
HWND hInstall;
begin
AskText (MSG_TEXT, DEFAULT_LOCATION, svLocation);
hMSI=GetWindowHandle(hInstall);
MessageBox ("Company: " + svCompany, INFORMATION);
MsiSetTargetPath(hMSI,"DIR1",svCompany);
MsiGetTargetPath(hMSI,"DIR1", svDir, nvBuf);
MessageBox(svDir, INFORMATION);
end;


Thx,
Vivek

RobertDickau
02-28-2005, 09:25 AM
Instead of GetWindowHandle, the handle you want is represented by the ISMSI_HANDLE variable. You might also want to initialize the size-buffer variable nvBuf with a value like MAX_PATH...

vivekprasanna
02-28-2005, 11:05 AM
Thanks a lot, Radha and Robert. It works fine.

RadhaK
03-01-2005, 02:39 AM
Hi Vivek,

In your code make a change in
MsiSetTargetPath(hMSI,"DIR1",DEFAULT_LOCATION);

vivekprasanna
03-01-2005, 04:31 AM
Hi Radha,

When using with OnBegin() where window handler is not defined, I used ISMSI_HANDLE as per Robert's suggestion.

MsiSetTargetPath(ISMSI_HANDLE,"DIR1", DEFAULT_LOCATION);
MsiGetTargetPath(ISMSI_HANDLE,"DIR1", svDir, nvBuf);

Whenusing in other function where window handlers are defined Eg: AskText(hMSI), one can use

MsiSetTargetPath(hMSI,"DIR1", DEFAULT_LOCATION);
MsiGetTargetPath(hMSI,"DIR1", svDir, nvBuf);
Thx,
Vivek

RadhaK
03-01-2005, 06:58 AM
Hi vivek,

Is it working fine now?

vivekprasanna
03-01-2005, 07:08 AM
IT works fine now. thx once again.

ankurtyagi
09-12-2005, 08:10 AM
gone through the series of mail above.
but of no help.

I have directory table looking like,
(Directory)...............(Directory_Parent).........(DefaultDir)
--------------------------------------------------
(MY_DIR).................(MY_OTHER_DIR)..........(Files)
(MY_OTHER_DIR).......(INSTALLDIR)...............(MyProjectFolder)
(INSTALLDIR)............(MY_PROJECT).............(.)
(MY_PROJECT)..........(ProgramFilesFolder)......(Project)

I hope this isn't too confusing.
Now, when ever i use,
MsiSetTargetPath ( hMsi, "MY_DIR", strPath );
or
MsiGetTargetPath ( hMsi, "MY_DIR", strPath, &buffer );
i always get ERROR_DIRECTORY.

I think i am not using the MsiSetTargetPath/MsiGetTargetPath in the right way, so please help.

The interesting part is, if i use MsiSetProperty/MsiGetProperty methods it works fine.

vivekprasanna
09-16-2005, 05:15 AM
Create a directory and assign a directory identifier and use the following code,

#include "Ifx.h"

#define MSG_TEXT "Please enter the path:"
#define DEFAULT_PATH "C:\\Program Files\\"

function OnBegin()
STRING svPath[256], szTitle;
NUMBER nResult;
LIST listID;
NUMBER nResult1,nvBuf;
STRING szString[256],svDir[256];
NUMBER hMSI;

begin
nvBuf=256;
AskText (MSG_TEXT, DEFAULT_PATH , svPath);
MessageBox ("Path: " + svPath, INFORMATION);
MsiSetTargetPath(ISMSI_HANDLE,"DIR1",svPath);
MsiGetTargetPath(ISMSI_HANDLE,"DIR1", svDir, nvBuf);
MessageBox(svDir, INFORMATION);
end;

ankurtyagi
09-17-2005, 06:42 AM
Hi vivek,
As i have said earlier, I have used,
MsiSetTargetPath ( hMsi, "MY_DIR", strPath ); // hMsi is MSI Handle.
This code is executed in a DLL, MSI Handle is passed as an argument. And this is exactly what you have suggested.
But this returns ERROR_DIRECTORY everytime.
So can anyone tell where i am wrong ?

Additionally, if i write,
MsiSetProperty ( hMsi, "MY_DIR", strPath ); // hMsi is MSI Handle.
everything works.

vivekprasanna
09-19-2005, 04:43 AM
Try using "ISMSI_HANDLE" instead of "hMSI".

ankurtyagi
09-19-2005, 06:23 AM
Hello Vivek,

As i have earlier mentioned, "This code is executed in a DLL." So i can not use ISMSI_HANDLE. hMsi is a variable that points to MSI Handle.

Good Day.