• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Info about desktop shortcut

Started by Patrice Terrier, October 23, 2008, 11:56:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

What is the best way (and easiest too) to retrieve informations about the desktop shortcuts?

- target path
- working directory
- arguments
- icon location

Currently i am using something like this one:
http://www.powerbasic.com/support/pbforums/showthread.php?t=25075&highlight=shortcut
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

José Roca

 
This one is the easiest:


' SED_PBCC - Use the console compiler
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "WSHOM.INC"

FUNCTION PBMAIN () AS LONG

   ' Creates an instance of the Windows Script Host
   LOCAL pWsh AS IWshShell
   pWsh = NEWCOM "WScript.Shell"

   ' Creates a shortcut programatically (if it already exists, CreateShortcut opens it)
   LOCAL pLnk AS IWshShortcut
   pLnk = pWsh.CreateShortcut(UCODE$(<path of the shortcut>))

   STDOUT "Shortcut description: " & ACODE$(pLnk.Description)
   STDOUT "Shortcut working directory: " & ACODE$(pLnk.WorkingDirectory)
   STDOUT "Shortcut arguments: " & ACODE$(pLnk.Arguments)
   STDOUT "Shortcut hot key: " & ACODE$(pLnk.HotKey)
   STDOUT "Shortcut icon location: " & ACODE$(pLnk.IconLocation)
   STDOUT "Shortcut target path: " & ACODE$(pLnk.TargetPath)
   STDOUT "Shortcut window style: " & FORMAT$(pLnk.WindowStyle)

END FUNCTION


Patrice Terrier

#2
José,

Thanks.

But what i need, is the easiest way to read existing shortcut data, not to create a new one.

I need this to detect all the desktop shortcuts to populate my DockBar demo, like in MAC OS.

I know how to do it (the old way), but there may be easiest way of doing it with the new PB9 COM facilities.
Hence why i am asking there ;)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Ok, i think i shall go with the plain old SHELL32.DLL

DECLARE FUNCTION SHFileOperation LIB "SHELL32.DLL" ALIAS "SHFileOperationA" (lpFileOp AS SHFILEOPSTRUCT) AS LONG
DECLARE FUNCTION SHGetDesktopFolder LIB "SHELL32.DLL" ALIAS "SHGetDesktopFolder" (ppshf AS ANY) AS LONG
DECLARE FUNCTION SHGetFileInfo LIB "SHELL32.DLL" ALIAS "SHGetFileInfoA" (pszPath AS ASCIIZ, BYVAL dwFileAttributes AS DWORD, psfi AS SHFILEINFO, BYVAL cbFileInfo AS DWORD, BYVAL uFlags AS DWORD) AS DWORD
DECLARE FUNCTION SHGetPathFromIDList LIB "SHELL32.DLL" ALIAS "SHGetPathFromIDListA" (pidList AS ANY, lpBuffer AS ASCIIZ) AS LONG
DECLARE FUNCTION SHGetSpecialFolderLocation LIB "SHELL32.DLL" ALIAS "SHGetSpecialFolderLocation" (BYVAL hwndOwner AS DWORD, BYVAL nFolder AS LONG, pidl AS ANY) AS LONG
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

José Roca

#4
 
The code that I have posted doesn't create a shortcut, but opens an existing one and retrieves the values. Don't be fooled by the name of the method, CreateShortcut: see my remarks (if it already exists, CreateShortcut opens it).

This will be the code to create a shortcut:


' Creates an instance of the Windows Script Host
LOCAL pWsh AS IWshShell
pWsh = NEWCOM "WScript.Shell"

' Creates a shortcut programatically (if it already exists, CreateShortcut opens it)
LOCAL pLnk AS IWshShortcut
pLnk = pWsh.CreateShortcut(UCODE$(EXE.PATH$ & "Test.lnk"))

' Sets variuos properties and saves them to disk
pLnk.Description = UCODE$("Hello world")
pLnk.WorkingDirectory = UCODE$(EXE.PATH$)
pLnk.Arguments = UCODE$("/c")
pLnk.HotKey = UCODE$("Ctrl+Alt+e")
pLnk.IconLocation = UCODE$(EXE.PATH$ & "PROGRAM.ICO,0")
pLnk.RelativePath = UCODE$(EXE.PATH$)
pLnk.TargetPath = UCODE$(EXE.PATH$ & "EX_WHLNK_CreateShortcut.EXE")
pLnk.WindowStyle = %WshNormalFocus
pLnk.Save


Patrice Terrier

Ok, José, i see it now!

Thanks for the head up  8)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#6
Do you know how to retrieve the label shown under each desktop icon?

I can't get it with any of the IWshShortcut property

Added:
Ok, i found the answer myself.
Indeed the Label shown below the desktop icon matches exactly the name of the lnk file, that was too obvious :o
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

José Roca

 
If instead of the path, you have a pidl, you can retrieve the display name calling the SHGetFileInfo function:


LOCAL dwRes AS DWORD
LOCAL shfi AS SHFILEINFO

dwRes = SHGetFileInfo(BYVAL pidl, 0, shfi, SIZEOF(shfi), %SHGFI_DISPLAYNAME)
PRINT shfi.szDisplayName


Patrice Terrier

I found that the IShellLink interface is unable to resolve a ".lnk" file targeting a ".cpl" file.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

If you want to see/learn how this topic has been sorted out, then look at the source code of the "OfTheBay" project.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com