Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,

I just want to know how can I check for a shortcut if it exists (say if MyProgram.lnk is exits on a desktop or not )in VBS Script .

Regards ,
Pradeep
Posted

Here is some vbs that looks for a specific shortcut
VB
Dim fso, msg
Dim filesearch

filesearch = "C:\Program Files\Bonjour\About Bonjour.lnk"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(filesearch) Then
   msg = filesearch + " exists."
Else
   msg = filesearch + " doesn't exist."
End If
wscript.echo msg

Taken essentially from this M$ article[^]

If you want to find the Desktop folder for current user try this
VB
Dim oNetW, sUName
Set oNetW = CreateObject("Wscript.Network")
Wscript.echo "User : " & oNetW.UserName
Wscript.echo "Desktop folder : " & "C:\Users\" & oNetW.UserName & "\Desktop"
 
Share this answer
 
This batch script can extract the target path of any link with those extensions .lnk or .url
@echo off
Title Extracting target from shortcut (*.url) and (*.lnk) by Hackoo 2017
Mode con cols=62 lines=3 & color 9E
Set "Log=%~dp0TARGET_LINK_PATHS.txt"
Set "TmpVbs=%Tmp%\%~n0.vbs"
::************************************************************************
(
	echo set Ws = CreateObject("WScript.Shell"^)
	echo set Lnk = Ws.Createshortcut(WScript.Arguments(0^)^)
	echo WScript.echo Chr(34^) ^& Lnk.TargetPath ^& Chr(34^)
)>"%Tmpvbs%"
::************************************************************************
Set "Links=url lnk"
Set "Folders=%UserProfile%\Desktop %Public%\Desktop %AllUsersprofile%"
For %%i in (%Links%) Do (
	For %%F in (%Folders%) Do (
		Cls
		Echo *****************************************************************
		Echo "%%F" for "*.%%i" Links
		(echo. & echo     Scanning "%%F" for "*.%%i" Links ...)>CON
		Echo *****************************************************************
		Echo;
			For /f "delims=" %%L in ('Dir /b /s "%%F\*.%%i"') do (
	 			echo "%%L" & Call:ExtractTarget "%%L"
	 			echo  --------------------------------------------------------
			)
	)		
)>>"%Log%"
Start "" /MAX "%Log%"
If Exist "%Tmpvbs%" Del "%Tmpvbs%"
Exit
::*************************************************************************
:ExtractTarget <Link>
cscript //nologo "%Tmpvbs%" "%~1"
Exit /b
::*************************************************************************
 
Share this answer
 
Comments
OriginalGriff 16-Dec-19 4:16am    
While I applaud your urge to help people, it's a good idea to stick to new questions, rather than 5 year old ones. After that amount of time, it's unlikely that the original poster is at all interested in the problem any more!
Answering old questions can be seen as rep-point hunting, which is a form of site abuse. The more trigger happy amongst us will start the process of banning you from the site if you aren't careful. Stick to new questions and you'll be fine.
Hackoo 16-Dec-19 4:53am    
@OriginalGriff Ok,Thank you for your reply, so my aim is just helping people, next time i will take care about what did you say to me in your comment !
Have a nice day sir !
OriginalGriff 16-Dec-19 5:02am    
No problem!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900