Windows Shortcuts

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Windows Shortcuts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:39 pm

by katsales >> Tue, 10 Sep 2002 6:14:26 GMT

Is it possible to create a windows shortcut from a Jade application? (prefered solution)

If there is no way in jade could someone point me in the direction of any windows call I could use. Failing that even a batch file command.

A shortcut within Windows is just a file of type 'shortcut'.

Any help would be appreciated.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Windows Shortcuts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:39 pm

by allistar >> Tue, 10 Sep 2002 20:58:45 GMT

Hi there,
You can do this easily in C++ like this: (sorry about poor
formatting).

IShellLink* pLink;
IPersistFile* pPersistFile;

// First, we have to initialize the COM library
if(SUCCEEDED(CoInitialize(NULL)))
{
// If CoInitialize doesn't fail, then instantiate an
// IShellLink object by calling CoCreateInstance.
if(SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink, (void **)
&pLink)))
{
// if that succeeds, then fill in the shortcut attributes
pLink->SetPath(file.c_str());
pLink->SetDescription("Woo hoo, look at Homer's
shortcut");
pLink->SetShowCmd(SW_SHOW);

// Now we need to save the shortcut to the hard drive. The
// IShellLink object also implements the IPersistFile interface.
// Get the IPersistFile part of the object using QueryInterface.
if(SUCCEEDED(pLink->QueryInterface(IID_IPersistFile,
(void
**)&pPersistFile)))
{
// If that succeeds, then call the Save method of the
// IPersistFile object to write the shortcut to the desktop.
WideString strShortCutLocation("C:\\bcbshortcut.lnk");
pPersistFile->Save(strShortCutLocation.c_bstr(),
TRUE);
pPersistFile->Release();
}
pLink->Release();
}

// Calls to CoInitialize need a corresponding CoUninitialize
call
CoUninitialize();
}


It would very easy to put this into a .dll that you could then call
from Jade as an external function.

Regards,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Windows Shortcuts

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:39 pm

by CarlRanson >> Tue, 10 Sep 2002 21:17:23 GMT

Ewwww! Get that 'orrible c++ stuff outta 'ere.

If you import the "Windows Script Host Object Model (ver1.0)" automation library its much easier.

// create the shortcut
create wsh transient;
shellLink := wsh.createShortcut(shortcutName).IWshShortcut;
shellLink.targetPath := '"' & binPath & '\\jade.exe"';
shellLink.arguments := 'app=Jade server=singleuser path="' & filesDirectory & '" ini="' & filesDirectory & '\jade.ini"';
shellLink.workingDirectory := '"' & binPath & '"';
shellLink.save;
delete wsh;

CR


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 22 guests

cron