Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if the shortcut exists or Not?
#1
Solved: 10 Years, 9 Months, 2 Weeks ago
I have two shortcuts for an application in a folder. note:They are not files but SHORTCUTS.

I want to know if these shortcuts exists or not.
i dont know but i used fso.fileexists which it doesnot take at all.
when i look at the properties window of this shortcut it showed.

type- application
how can i find out if the shortcuts exists in a particular folder. This could sound silly but i really dont know.

Thank you for your help.
Reply
#2
Solved: 10 Years, 9 Months, 2 Weeks ago
All you need to do is - write a WMI query that includes the path of the folder you want to check as well as the file extension for shortcuts i.e 'lnk'
e.g this script checks if Quick Test Professional shortcut exist in folder "C:\Test\Shortcuts"
Code:
strComputer = "."
strFolder = "\\Test\\Shortcuts\\"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery ("Select * From Cim_DataFile Where Path = '" & strFolder & "' AND Drive = 'C:' And Extension = 'lnk'")

For Each objItem in colItems
If objItem.FileName = "QuickTest Professional" Then
msgbox "Shortcut Exists"
End If
Next

Reply
#3
Solved: 10 Years, 9 Months, 2 Weeks ago
thank u saket. But can you explain me. I did not understand.

Moreover i want to let you know. my application shows

type of file: Application
target: ending with some switch to the exe file.
ex: aaa\xxx.exe\AUTOSAVE.. something like this
now how will i be able to identify this thing? becoz i need to capture the text in the target and find out if it has some AUTOSAVE.. on it.

thanks
Reply
#4
Solved: 10 Years, 9 Months, 2 Weeks ago
use objItem.Target to get the target and then search for the string you need to check.

for explanation on WMI refer All About Windows Management Instrumentation (WMI) in QTP

Reply
#5
Solved: 10 Years, 9 Months, 2 Weeks ago
I dont know for whatever reason. this shows invalid arguement or precedure error
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

I was searching a winzip shorcut which is in
C:\Documents and Settings\All Users\Start Menu

what could be the problem?
Reply
#6
Solved: 10 Years, 9 Months, 2 Weeks ago
try using special folder for start menu -
Code:
set objShell = createobject("Wscript.Shell")
strFolder = objShell..SpecialFolders("startmenu")

if you still face the issue, paste your code so that we can get a better idea.

Reply
#7
Solved: 10 Years, 9 Months, 2 Weeks ago
hi Saket,

i am still in confusion.
This is my code. Let me know where i am going wrong.


Code:
Dim objItem, strComputer,objWMIService,ColItems
strComputer="."
strFolder="C:\Documents and Settings\All Users\Start Menu"
[b]Set objWMIService = GetObject("winmgmts:\\" &strComputer&" \root\cimv2")[/b]
Set ColItems= ObjWMIService.ExecQuery(" Select * from Cim_DataFile Where Path ='"&strFolder&"' AND Name='Winzip'")

For Each objItem in ColItems
    If objitem.FileName = "WinZip" then
        msgbox "Shortcut Exists"
        end if
Next

it always shows General run error.. or something else sometimes.. on the
Set objEMIService.. or else i get error @ for each line..

This is very important as i am stuck with work.
moreover Start Menu is just a folder. what if there is a filefolder and in that a shortcut exists and i need to look for that shortcut? how can i find out.

This there any other way to search and just need to confirm that the file exists. This is 1 small requirement to check if the shortcut exists.

thanks
Reply
#8
Solved: 10 Years, 9 Months, 2 Weeks ago
This works fine at my side, but I doubt in your query. if you are searching in startmenu winzip shortcut must be in 'startmenu\programs\winzip'

may be you can try replacing "." with the exact computer name, see if it works,

I just noticed that we are going on a longer and bit complex raod, however it can be done in a very simple way.
see the code below
Code:
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
If objFSO1.FileExists("C:\Documents and Settings\All Users\Start Menu\Programs\WinZip\WinZip.lnk") Then
msgbox true
End If

let me know if this helps.

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Report Viewer showing hundreds of WebElement.Exists? themoon 1 2,228 03-09-2016, 02:43 PM
Last Post: vinod123
  How to check whether data exists in excel.. venkatesh9032 1 2,925 03-06-2014, 04:37 PM
Last Post: supputuri
  Object does not exists shwetasharma 4 8,771 03-01-2013, 01:05 PM
Last Post: shwetasharma
  Verifying the value exists and if not, wait up to 5min HeZma 3 3,855 02-25-2012, 12:21 PM
Last Post: rajpes
  How to prove if an object exists? lucster 3 4,655 07-07-2011, 10:24 PM
Last Post: rajpes

Forum Jump:


Users browsing this thread: 1 Guest(s)