Computer Hope

Microsoft => Microsoft DOS => Topic started by: feras on February 12, 2010, 01:16:55 AM

Title: shortcuts
Post by: feras on February 12, 2010, 01:16:55 AM
Hello everybody :)

Is there ic CMD any code can delete the shortcuts which don't have targets ?

thanks
Title: Re: shortcuts
Post by: BillRichardson on February 12, 2010, 06:43:15 AM

C:\Documents and Settings\Bill Richardson\Desktop>dir  awk*
 Volume in drive C has no label.
 Volume Serial Number is F4A3-D6B3

 Directory of C:\Documents and Settings\Bill Richardson\Desktop

12/17/2009  07:47 PM               186 Awk.url
               1 File(s)            186 bytes
               0 Dir(s)  299,962,126,336 bytes free

C:\Documents and Settings\Bill Richardson\Desktop>del Awk.url
Title: Re: shortcuts
Post by: Helpmeh on February 12, 2010, 07:03:20 AM
C:\Documents and Settings\Bill Richardson\Desktop>dir  awk*
 Volume in drive C has no label.
 Volume Serial Number is F4A3-D6B3

 Directory of C:\Documents and Settings\Bill Richardson\Desktop

12/17/2009  07:47 PM               186 Awk.url
               1 File(s)            186 bytes
               0 Dir(s)  299,962,126,336 bytes free

C:\Documents and Settings\Bill Richardson\Desktop>del Awk.url
I think the OP wants to CHECK whether or not shortcuts works and then delete them if they don't.
Title: Re: shortcuts
Post by: BillRichardson on February 12, 2010, 08:05:45 AM
I think the OP wants to CHECK whether or not shortcuts works and then delete them if they don't.

So please write the batch code that checks if the shortcut works.
Title: Re: shortcuts
Post by: Sidewinder on February 12, 2010, 02:58:18 PM
Quote
Is there ic CMD any code can delete the shortcuts which don't have targets ?
Not that I'm aware of.

Quote
C:\Documents and Settings\Bill Richardson\Desktop>del Awk.url
Shortcuts have .lnk extensions, not .url

You can write a VBScript:
Code: [Select]
strComputer = "."

Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Extension = 'lnk'")

For Each objFile in colFiles
Set objFile = fso.GetFile(objFile.Name)
If Not objFile.Attributes And 2 Then
  Set objShortcut = WshShell.CreateShortcut(objFile.Path)
strTarget = objShortcut.TargetPath
  If Not fso.FileExists(strTarget) Then
  WScript.Echo "Target File: " & strTarget & " does not exist for shortcut: " & objFile.Path
  End If
  End If 
Next

The snippet will search the entire data store of files, irregardless of what drive they are on. Expect a lengthy run time. Save the script with a vbs extension and run from the command prompt as cscript scriptname.vbs.

The snippet will list all the shortcuts with invalid target paths. When you are completely satisfied, replace the WScript.Echo line with fso.DeleteFile objFile.Path, True

Good luck.  8)

Quote
I think the OP wants to CHECK whether or not shortcuts works and then delete them if they don't.
Quote
So please write the batch code that checks if the shortcut works.

Sounds like a throwdown to me. How about a gun duel at 20 paces? The winner gets to write the batch file, the loser gets buried nine edge down  ;D
Title: Re: shortcuts
Post by: BillRichardson on February 12, 2010, 03:56:43 PM
"Shortcuts have .lnk extensions, not .url"

http://msdn.microsoft.com/en-us/library/3eahbt2c(VS.85).aspx

The shortcut pathname must end with .lnk or .url

http://msdn.microsoft.com/en-us/library/3eahbt2c(VS.85).aspx

 
The shortcut pathname must end with .lnk or .url

When you named your shortcut, either you did not give it a file extension

or you gave it an extension other than *.lnk, nor *.url.

When using the CreateShortcut method, the file extension is incorrect
 
or missing.

To correct this error
Check that the file extension for the shortcut ends

with .lnk for a Windows shortcut or with .url for an Internet shortcut.

Title: Re: shortcuts
Post by: Prince_ on February 16, 2010, 06:24:29 PM
if it's named "a", then you can delete it like this
Code: [Select]
del a.lnk
Title: Re: shortcuts
Post by: Helpmeh on February 16, 2010, 07:26:00 PM
Not everyone has deleted the registry keys which disable the viewing of certain extensions (including .lnk), and if those registry keys are in affect, the command prompt will not see those extensions, nor will the Windows GUI. The registry keys were NeverShowExt if I am not mistaken, but before any registry modification should be made (one should really avoid doing them anyway unless you know EXACTLY what you are doing and how it will affect your computer), always, ALWAYS, preform a backup of your registry.
Title: Re: shortcuts
Post by: BC_Programmer on February 17, 2010, 03:11:27 AM
Not everyone has deleted the registry keys which disable the viewing of certain extensions (including .lnk), and if those registry keys are in affect, the command prompt will not see those extensions, nor will the Windows GUI. The registry keys were NeverShowExt if I am not mistaken, but before any registry modification should be made (one should really avoid doing them anyway unless you know EXACTLY what you are doing and how it will affect your computer), always, ALWAYS, preform a backup of your registry.

the command line can always see the "lnk" extension. and I imagine the url extension too.

the URL extension is of course completely irrelevant here since you cannot check if a URL exists easily.
Title: Re: shortcuts
Post by: Helpmeh on February 17, 2010, 06:21:30 AM
the command line can always see the "lnk" extension. and I imagine the url extension too.

the URL extension is of course completely irrelevant here since you cannot check if a URL exists easily.
Not for me. I had to delete the registry keys to be able to view them in GUI and in the command prompt.