/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Issue with my VBscript need some assistance

11/18/2019 151 views

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

Comments


All Answers

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.

Answered 11/18/2019 by: VBScab
Red Belt

  • 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 ?
    • This content is currently hidden from public view.

Don't be a Stranger!

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

Sign up! or login

Share