Computer Hope
Microsoft => Microsoft DOS => Topic started 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
-
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
-
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.
-
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.
-
Is there ic CMD any code can delete the shortcuts which don't have targets ?
Not that I'm aware of.
C:\Documents and Settings\Bill Richardson\Desktop>del Awk.url
Shortcuts have .lnk extensions, not .url
You can write a VBScript:
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)
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.
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
-
"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.
-
if it's named "a", then you can delete it like this
del a.lnk
-
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.
-
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.
-
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.