Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need some help extracting desktop shortcut paths to a table or to excel please 2

Status
Not open for further replies.
Jan 20, 2007
237
US
Hi Everyone,
a little annoying question

we got hit by ransomware, no all computers but since we can have still traces we are going to reformat all computers hhds and upgrade all possibles WiN 7 to Win 10 pro 64bit, so before i do that i will need.

1- go to each computer and run some sort of routine to read from the desktop the shortcuts path, extract them to excel or a table, so i can know later when i install win 10 the needed path for those shortcuts

it is possible to extract that?
can anyone has experimented this before or have a help to share please ?
Thanks a lot
 
The desktop is just a directory. It is accessible just like any other directory. Its actual location varies with the version of Windows (in Windows 7, you can find it at [tt]/users/<user name>/desktop[/tt], for example).

To find the directory programmatically, you can use the code shown here: Finding the paths to Windows' special folders in VFP. (The value to pass as the parameter is 16.)

Once you have found the directory, the shortcuts are present as ordinary files.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
will this function allow me to list all the path name of each desktop shortcut ?

can you please elaborate a little more please, i am a beginner as you know.

i copied that code into a prg file, so then i added to the prg file "set procedure to getspecial,16"
this actually does not show me anything, sorry something i am not doing correct at all.
Thanks

 
Ernesto,

No, "set procedure to getspecial,16" is quite wrong.

You need to do something like this:

1. Save the code to a PRG. Name it, say, GetSpecial.PRG

2. [tt]SET PROCEDURE TO GetSpecial[/tt]

3. [tt]? GetSpecial(16)[/tt]

That last line will display the Desktop path on the screen. More likely, you will want to save it to a variable, and then loop through looking for the files within the Desktop. Something like this:

Code:
LOCAL ARRAY laFiles(1)
SET PROCEDURE TO GetSpecial
lcDesktop = GetSpecial(16)
lnCount = ADIR(laFiles, lcDesktop + "*.lnk")
? lnCount
FOR lnI = 1 TO lnCount
  ? laFiles(lnI, 1)
ENDFOR

That will display the names of all the shortcuts on the desktop. Is that you want? Or do you want to get the target that each shortcut points to? If so, that's possible but a little more difficult.

I'm not sure how any of this is going to help you recover from ransomware, but presumably you know what you are doing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes Mikle,
i need to get the names of the shortcut but also the "target that each shortcut points to
Thanks so much

 
Hi Mike
i am running the below prg as follow and what i get is the lnCount value = 0, the laFiles =.F. and lcDesktop = c:\Users\admin.M100\Desktop.
i added the messagebox() to see the values

should be lnCount = 1 ?
Thanks a lot

Code:
LOCAL ARRAY laFiles(1)
SET PROCEDURE TO GetSpecial
lcDesktop =GetSpecial(16)
lnCount = ADIR(laFiles,lcDesktop + "*.Ink")
messagebox("see below ")
** ? lnCount
messagebox(lncount)
MESSAGEBOX(lafiles)
MESSAGEBOX(lcDesktop)

FOR lnI = 1 TO lnCount 
 ? laFiles(lnI, 1)   
ENDFOR 

FUNCTION GetSpecial
* Returns the path to one of Windows' "special folders", 
* such as My Documents, Application Data, Program Files, 
* etc.

* Parameters:
* - The folder's CSIDL;
* - A flag to say the folder should be created if it
*   doesn't already exist.

* Returns the path to the specified folder. If the CLSID
* is invalid, or the folder doesn't exist (and the second
* parameter is .F.), returns an empty string.

LPARAMETERS tnFolder, tlCreate

LOCAL lcPath, lnPidl, lnPidlOK, lnFolderOK

#DEFINE MAX_PATH 260
#DEFINE CREATE_FLAG 32768 

* Delcare the API functions
DECLARE LONG SHGetSpecialFolderLocation IN shell32 ;
	LONG Hwnd, LONG lnFolder, LONG @pPidl
DECLARE LONG SHGetPathFromIDList IN shell32 ;
	LONG pPidl, STRING @pszPath
DECLARE CoTaskMemFree IN ole32 LONG pVoid

lcPath = SPACE(MAX_PATH)
lnPidl = 0

* If .T. is passed as second param, we want to create the 
* folder if it doesn't already exist.
IF tlCreate
	tnFolder = tnFolder + CREATE_FLAG
ENDIF 
	
* Get the PIDL
lnPidlOK = SHGetSpecialFolderLocation(0, tnFolder, @lnPidl)

IF lnPidlOK = 0
  * Pidl found OK; get the folder
  lnFolderOK = SHGetPathFromIDList(lnPidl, @lcPath)
  IF lnFolderOK = 1
    * Folder found OK; trim the string at the null terminator
    lcPath = LEFT(lcPath, AT(CHR(0), lcPath) - 1)
  ENDIF 
ENDIF 

* Free the ID List
CoTaskMemFree(lnPidl)

RETURN ALLTRIM(lcPath)
 
Hi Ernesto,

Two problems:

First, in this line: lnCount = [tt]ADIR(laFiles,lcDesktop + "*.Ink")[/tt], you might need to add a backslash to the end of the path in lcDesktop. Change it to:

[tt]lnCount = ADIR(laFiles,ADDBS(lcDesktop) + "*.Ink")[/tt]

Secondly, [tt]*.Ink[/tt] is wrong. It should be [tt]*.lnk[/tt]. The first letter is a lower-case L, not a capital I.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top