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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Systematically and safely deleting folder shortcuts seemingly to itself 1

Status
Not open for further replies.

Shimmy613

Programmer
Feb 14, 2011
39
US
I had a "shortcut virus" which I believe I successfully removed. It placed shortcuts called "Downloads" and "Games" in folders all over my system. I was able to delete those using Windows search.

There is one issue that isn't "dangerous", just annoying. There are these shortcuts all over the place with the name of their containing folder, but they actually point to the System32 folder:

image_fzgajs.png


Is there a systematic way of finding and safely deleting them (meaning only those) but no "real" shortcuts and certainly not actual files or folders that may happen to have the same name as their containing folder? I was thinking of some kind of script that could first display every shortcut it was going to delete - and then modifying it slightly to have it actually do so.

Extra annoying: two of them are in the "System Volume Information" folders of two of my hard-drives and I don't have access to delete them.
 
You could start by running this command from the Command window:

[tt]dir c:\*.lnk /b /s > c:\shortcuts.txt[/tt]

where c: is the drive letter and c:\shortcuts.txt is the name and path of a text file to receive the results.

That will give you the fully-qualified filenames of all the shortcuts on the drive. But note that that will include many shortcuts that you want to retain, including all those in your start menu and on your desktop. So you will have a bit of manual sorting to do.

I can't off-hand think of an automatic way of deleting the shortcuts, except to write a program to do it. If this was me, I would write a quick program in my favourite programming language (which happens to be Visual FoxPro) to read the above text file and to delete each file in turn. No doubt other folk here in the forum will suggest something better.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Just to follow up my previous post ...

The command I suggested would find all LNK files. These are the actual shortcuts, not the file or folder to which they point. So deleting the LNK will not delete the target file or folder.

On that basis, you could take the text file that the command creates (shortcuts.txt in my example); manually remove the shortcuts that you want to keep (admittedly not a trivial chore); place a DEL command at the front of each line; change the extension to .BAT; and run it as a batch fie.

To place the DEL command at the front of each line, you could open the file in a text editor and use its find-and-replace function to insert DEL plus a space after each end-of-line character (assuming the editor allows you to do that); or you could open it in Word and write a macro to do the job (and remember to save it as a plain text file afterwards).

Obviously you would need to test this carefully, to avoid deleting anything that you want to keep.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you, Mike.

Is there a way to add "where the shortcut name = the name of the containing folder" or at least "where target = C:\Windows\system32"?
 
"where the shortcut name = the name of the containing folder"

Can't think of any easy way of dealing with that.

"where target = C:\Windows\system32"?

No, that's not possible, because the DIR command gives you the shortcut's filename. It knows noting about the target of the shortcut.

Shimmy, can I ask you what programming languages you are familiar with? The reason I ask is that languages that support COM can use the Windows Scripting Host to acess shortcuts, including the ability to find the target file and folder. I have done this myself in Visual Foxpro, and it's also possible in VBA, Javascript and other languages.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I was a C# programmer which I know would handle this easily. But since I've moved into project/management, I haven't coded at all and I'm way too rusty. :-|
 
Well, if you fancy having a go at writing the program, here is some pseudo-code that might give you a start. Sorry I don't know C# well enough to give you some actual code.

Code:
Run "dir c:\*.lnk /b /s" from DOS; send results to a text file

Open the text file for input
Create new output file
oShell = CREATEOBJECT("wscript.shell")

FOR each line in the input file:
    Read the line into a variable (cPath); this will contain
    the path and filename of one shortcut
    IF PATH(cPath) contains filename(cPath)
        oShort = oShell.CreateShortcut(cPath)
        IF oShort.TargetPath contains "C:\Windows\system32"
           Write "DEL " + cPath to output file
        ENDIF
    ENDIF
ENDFOR

Close the output file

Now manually review the output file, making sure you are happy
with all the deletions.

Then run the output file as a BAT file from DOS.

There might well be some simpler way of approaching the problem, perhaps using one of those Windows scripting tools like AutoIt, but that's outside my area.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

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

Part and Inventory Search

Sponsor

Back
Top