Board index » cppbuilder » Uninstalling shortcuts

Uninstalling shortcuts


2005-03-29 05:34:53 AM
cppbuilder87
Greetings.
I am using some code to create shortcuts.
The shortcuts will install on w2000 or nt4 most likely.
I don't write anything explicitly to the registry to keep track of
things though.
I would like to, when the user uninstalls the application,
to remove the shortcuts.
The only caveat I guess is that they need to supply the original
installation information (install location and whether startmenu or
desktop shortcuts were installed).. I know the files accessed by the
shortcuts then.
So can someone explain the proper way to make my cbuilder installation
program remove shortcuts?
I'm not sure if I need to use some sort of ipersistfile.delete call or
what.
The code I am using to create them in the first place is below...
Thanks
Jeff
bool __fastcall TFormIPCInstall::CreateShortcutLink(vAnsiString &
inVErrors,
AnsiString LinkDesc,//"MyDemo"
AnsiString LinkPath, //this is sprintf(path,
//"%s\\%s.lnk",
//DesktopPath.c_str()
//where DesktopPath is GetSpecialFolder(CSIDL_DESKTOP);
AnsiString TargetPath, //target file to activate via shortcut
AnsiString TargetArgs,//null
AnsiString WorkingDirectory) //null
{
// Must be done before any other calls to make it work.
CoInitialize(NULL);
bool retval = false;
HRESULT hres;
IShellLink* psl = NULL;
SetLastError(0);
LPCLASSFACTORY pcf = NULL;
hres = CoGetClassObject( CLSID_ShellLink,
CLSCTX_INPROC_SERVER,
NULL,
IID_IClassFactory,
(LPVOID*)&pcf);
if(SUCCEEDED(hres))
{
hres = pcf->CreateInstance(
NULL,
IID_IShellLink,
(LPVOID*)&psl);
pcf->Release();
}
if(SUCCEEDED(hres))
{
IPersistFile* ppf = NULL;
// Set the path to the shortcut target, and add the description.
psl->SetPath(TargetPath.c_str()); /* typically:
"d:\\ipc2.2p6\\ini\\ipc.bat"*/
psl->SetArguments(TargetArgs.c_str()); /* typically: NULL */
psl->SetDescription(LinkDesc.c_str()); /* typically:
d:\\program files\\msx411\\maxcust.dll */
if (WorkingDirectory.Length() < 1)
{
psl->SetWorkingDirectory(ExtractFilePath(TargetPath).c_str());
}
else
{
psl->SetWorkingDirectory(WorkingDirectory.c_str());
}
// Query IShellLink for the IPersistFile interface for saving
the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, &(void*)ppf);
if(SUCCEEDED(hres))
{
wchar_t wsz[MAX_PATH];
// Ensure that the string is ANSI.
MultiByteToWideChar(CP_ACP, 0, LinkPath.c_str(), -1, wsz,
MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
retval = SUCCEEDED(hres);
}
AnsiString AsErrorPrefix = "Error Creating Shortcut " + LinkDesc;
AnsiString asReturnedErrorInfo = "";
switch(hres)
{
case S_OK:
//ShowMessage("Link was successfully created");
break;
case REGDB_E_CLASSNOTREG:
asReturnedErrorInfo = AsErrorPrefix + "A specified class is not
registered in the registration database";
ShowMessage(asReturnedErrorInfo);
break;
case E_OUTOFMEMORY:
asReturnedErrorInfo = AsErrorPrefix + "Out of memory";
ShowMessage(asReturnedErrorInfo);
break;
case E_INVALIDARG:
asReturnedErrorInfo = AsErrorPrefix + "One or more arguments are
invalid";
ShowMessage(asReturnedErrorInfo);
break;
case E_UNEXPECTED:
asReturnedErrorInfo = AsErrorPrefix + "An unexpected error
occurred";
ShowMessage(asReturnedErrorInfo);
break;
case CLASS_E_NOAGGREGATION:
asReturnedErrorInfo = AsErrorPrefix + "Class cannot be created as
part";
ShowMessage(asReturnedErrorInfo);
break;
case E_FAIL:
asReturnedErrorInfo = AsErrorPrefix + "Could not create link";
ShowMessage(asReturnedErrorInfo);
break;
case E_NOTIMPL:
asReturnedErrorInfo = AsErrorPrefix + "Interface not implemented";
ShowMessage(asReturnedErrorInfo);
break;
default:
asReturnedErrorInfo = AsErrorPrefix + "Unknown error";
ShowMessage(asReturnedErrorInfo);
}
CoUninitialize();
if (asReturnedErrorInfo.Length()>0)
{
inVErrors.push_back(asReturnedErrorInfo);
}
return retval;
}
Jeff Kish
 
 

Re:Uninstalling shortcuts

"Jeff Kish" < XXXX@XXXXX.COM >wrote in message
Quote
I don't write anything explicitly to the registry to keep
track of things though.
Then you won't be able to do what you are asking for.
Quote
So can someone explain the proper way to make my
cbuilder installation program remove shortcuts?
The only way to do that is to do what every other install package does -
keep track of the files you create during installation, so you know what to
remove during uninstallation. That doesn't take into account the user
manually moving the shortcuts after than have been created. You won't be
able to do anything about that. No other install package can handle that,
either. I suppose you could write a Shell Extension DLL that implements the
ICopyHook interface so that you can update your tracking when files are
being moved/deleted. But that is just more work on your part.
Quote
I'm not sure if I need to use some sort of ipersistfile.delete
call or what.
Once you know the filename of a .lnk file, just delete it like any other
file.
Gambit
 

Re:Uninstalling shortcuts

On Mon, 28 Mar 2005 14:40:10 -0800, "Remy Lebeau \(TeamB\)"
< XXXX@XXXXX.COM >wrote:
Quote

"Jeff Kish" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I don't write anything explicitly to the registry to keep
>track of things though.

Then you won't be able to do what you are asking for.

>So can someone explain the proper way to make my
>cbuilder installation program remove shortcuts?

The only way to do that is to do what every other install package does -
keep track of the files you create during installation, so you know what to
remove during uninstallation. That doesn't take into account the user
manually moving the shortcuts after than have been created. You won't be
able to do anything about that. No other install package can handle that,
either. I suppose you could write a Shell Extension DLL that implements the
ICopyHook interface so that you can update your tracking when files are
being moved/deleted. But that is just more work on your part.

>I'm not sure if I need to use some sort of ipersistfile.delete
>call or what.

Once you know the filename of a .lnk file, just delete it like any other
file.


Gambit

OK. If I know the .lnk filename, then deleting that will "undo" what
the original creation of shortcuts did? I should be able to figure
that out I believe.
Thanks much
Jeff Kish
 

{smallsort}

Re:Uninstalling shortcuts

"Jeff Kish" < XXXX@XXXXX.COM >wrote in message
Quote
OK. If I know the .lnk filename, then deleting that will "undo"
what the original creation of shortcuts did?
IShellLink creates a .lnk file for each shortcut. Simply deleting a .lnk
file removes the shortcut from the machine.
Gambit
 

Re:Uninstalling shortcuts

Jeff Kish wrote:
Quote
I don't write anything explicitly to the registry to keep track of
things though.
If you don't want to mess with the registry, then you would create an
install log that lists all the files/shortcuts and paths actually used
during the installation.
Then on uninstall, you could parse the log and undo everything.
 

Re:Uninstalling shortcuts

On Mon, 28 Mar 2005 15:24:19 -0800, "Remy Lebeau \(TeamB\)"
< XXXX@XXXXX.COM >wrote:
Quote

"Jeff Kish" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>OK. If I know the .lnk filename, then deleting that will "undo"
>what the original creation of shortcuts did?

IShellLink creates a .lnk file for each shortcut. Simply deleting a .lnk
file removes the shortcut from the machine.


Gambit

Thanks. I wasn't sure if there was any other internal / registry sort
of thing that needed to be addressed.
Jeff Kish
 

Re:Uninstalling shortcuts

On Mon, 28 Mar 2005 19:11:30 -0800, Bob Gonder
< XXXX@XXXXX.COM >wrote:
Quote
Jeff Kish wrote:

>I don't write anything explicitly to the registry to keep track of
>things though.

If you don't want to mess with the registry, then you would create an
install log that lists all the files/shortcuts and paths actually used
during the installation.
Then on uninstall, you could parse the log and undo everything.

Thanks. Now I know where to go with this.
I guess I could somehow search for .lnk files that
belong to my app(s) and remove those.
Jeff Kish