I have developed an MSI on Windows XP SP2, using Visual studio 6.0. I am using AI 6.4.1 and building an enterprise project.
It is working fine on all Operating Systems except Vista (Ultimate edition).
On Vista (Ultimate edition), the problem occurs when I am creating shortcuts programmatically and saving the .LNK file in following folder to make them show in "Start Menu":
C:\Documents and Settings\All Users\Start Menu\Programs\MyApp
When i ran MSI as administrator (on right click, chossing option "Run As Administrator") it works fine. But, I can not ask user to right click MSI and run it as administrator.
I would like to run MSI, just by double clicking it.
Note: I know, I could try Media->Bootstrapper->security->Execution level->"Require Administrator", but it will make .exe instead of MSI, and, coz of some reasons, i don't want .exe file for my setup.
Code to create Shortcut:
Code: Select all
HRESULT CreateShortcut(LPCSTR pszShortcutFile, LPCSTR pszArgs, LPCSTR pszDir, LPCSTR pszLink, LPSTR pszDesc, int iconIndex)
{
HRESULT hres;
IShellLink *psl;
// Create an IShellLink object and get a pointer to the IShellLink
// interface (returned from CoCreateInstance).
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **)&psl);
if (SUCCEEDED(hres))
{
IPersistFile *ppf;
// Query IShellLink for the IPersistFile interface for
// saving the shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH]; // buffer for Unicode string
// Set the path to the shortcut target.
// This is the name of the item that the shortcut points to.
// Target :
hres = psl->SetPath(pszShortcutFile);
// Sets the command-line arguments for a shell link object.
hres = psl->SetArguments(pszArgs);
if(iconIndex != -1)
hres = psl->SetIconLocation(pszShortcutFile, iconIndex);
// Set the folder that contains the original item or some
// related files. Sometimes, programs need to use files from
// other locations. You may need to specify the folder where
// these files are located so that the programs can find them.
// Start in :
hres = psl->SetWorkingDirectory(pszDir);
if (!SUCCEEDED(hres))
AfxMessageBox("SetPath failed!");
// Set the description of the shortcut.
hres = psl->SetDescription(pszDesc);
if (!SUCCEEDED(hres))
AfxMessageBox("SetDescription failed!");
// Ensure that the string consists of ANSI characters.
int retvalue = MultiByteToWideChar(CP_ACP, 0, pszLink, -1, wsz, MAX_PATH);
// Save the shortcut via the IPersistFile::Save member function.
hres = ppf->Save(wsz, FALSE);
if (!SUCCEEDED(hres))
AfxMessageBox("Save failed!");
// Release the pointer to IPersistFile.
ppf->Release();
}
// Release the pointer to IShellLink.
psl->Release();
}
return hres;
}
So, plz help me to sort the problem.
Regards,
Vicky
FOLLOW US
Get the latest news in Application Packaging