×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Systematically and safely deleting folder shortcuts seemingly to itself

Systematically and safely deleting folder shortcuts seemingly to itself

Systematically and safely deleting folder shortcuts seemingly to itself

(OP)
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:



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.

RE: Systematically and safely deleting folder shortcuts seemingly to itself

You could start by running this command from the Command window:

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

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

RE: Systematically and safely deleting folder shortcuts seemingly to itself

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

RE: Systematically and safely deleting folder shortcuts seemingly to itself

(OP)
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"?

RE: Systematically and safely deleting folder shortcuts seemingly to itself

Quote:

"where the shortcut name = the name of the containing folder"

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

Quote:

"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

RE: Systematically and safely deleting folder shortcuts seemingly to itself

(OP)
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. :-|

RE: Systematically and safely deleting folder shortcuts seemingly to itself

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close