/build/static/layout/Breadcrumb_cap_w.png

Issue with my VBscript need some assistance

Hi , 


I am having an issue with my VBscript and need your assistance. The main intention of this script is to check the existence of a shortcut file in %userprofile%\desktop\ location.

I created the script but when i execute it it says complaint all time even if the file exists or not exists. Could any one  please help to correct y script ?


Set objFSO = CreateObject("Scripting.FileSystemObject")


If objFSO.FileExists("%Userprofile%\desktop\test 1.lnk") Then


Wscript.Echo "NonCompliantt"


Else

    Wscript.Echo "Compliant"

End If


Even if the test 1.lnk is present or not present the script writes compliant which is not right . 

If the shortcut file is present it should say compliant else non compliant. 


Thanks in advance. 





0 Comments   [ + ] Show comments

Answers (1)

Posted by: anonymous_9363 5 years ago
Red Belt
2

You can't reference environment variables directly like that from VBS. You need to access the Shell object and retrieve it that way. Bear in mind, though, that the variable's existence will depend on the context in which the finalised script will run. For example, if you run it under the local System account, the shortcut's existence will be checked only for that user.

You could either loop through the profile list in the registry - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList - and get the data from the 'ProfilePath' value or, more simply, you could loop through 'c:\users'. There are many good examples of recursive folder-searching, which will save you from reinventing the wheel. You may even find some ready-rolled code to do exactly what you want in full.


Comments:
  • HI , Thank you ,. I am not that good at the VB scripting , could you please share the reference link so that i can try to use the same if any available ? - lgovindprakash 5 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ