Relevance substitution Error when trying to create a vbscript for shortcut

Hi All,
Good day. basically i’m replacing certain user desktop shortcuts to open with chrome and i want to use Bigfix to read the shortcut arguments of the existing shortcut which will be used to create a vbscript, before deleting the shortcut. the shortcuts are located in the desktop folder of the current user.

The script works if i provide the shortcut parameters like name, argument, path and icon path. however, we have had some situations where the shortcut arguments have been customised due to specific user requirements which is why i would like to use the approach of BigFix inspecting the existing shortcut, creating the vbscript and then deleting the old shortcut.

Providing the shorcut arguments as parameters, works, however when trying to use Bigfix relevance to extract the shortcut argument from the previous shortcut, i get a relevance substitution error which i need help fixing.

N|B i get the error at the appendfile olink.arguments section.

Please see section of code below

// set dynamic parameters
action parameter query "SCTarget" with description "Enter 'Current' for Current User or 'All' for All Users." with default value "Current"
action parameter query "SCName" with description "Enter the name for the icon." with default value "Purolator"
action parameter query "SCpath" with description "Enter the path to file" with default value "C:\Program Files (x86)\Google\Chrome\Application"
action parameter query "SCprog" with description "Enter enter the name of the executable in the target path"
action parameter query "SCdesc" with description "Enter enter the shortcut description"
action parameter query "SChotkey" with description "Enter enter the shortcut hotkey"

// set static parameters
parameter "STPIN" = "C:\PortableApps\Shortcuts"
parameter "Startup" = "C:\users\{name of current user}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
parameter "STtask" = "C:\users\{name of current user}\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"

if {name of operating system = "Win7"}
	parameter "Startmenu" = "C:\users\{name of current user}\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
	delete "C:\Users\{name of current user}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Internet Explorer.lnk"
	delete {parameter "Startmenu"}\{parameter "SCName"}.lnk
elseif {name of operating system = "Win10"}
	parameter "Startmenu" = "C:\users\{name of current user}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Chrome Apps"
endif

delete {parameter "Startmenu"}\{parameter "SCName"}.lnk

//Select Current User or All Users
if {parameter "SCTarget" of action = "All"}
    parameter "Desktop" = "c:\users\Public\Desktop"
else
    parameter "Desktop" = "c:\users\{name of current user}\Desktop"
endif

	
delete __appendfile
delete C:\Temp\replaceshortcut.vbs
appendfile   Set oWS = WScript.CreateObject("WScript.Shell")
appendfile   sLinkFile = "{parameter "Desktop"}\{parameter "SCName"}.lnk" 
appendfile   Set oLink = oWS.CreateShortcut(sLinkFile)
appendfile   oLink.TargetPath ="{parameter "SCpath"}" & "\{parameter "SCprog"}"
appendfile   oLink.Arguments = "{Argument string of shortcut of file "c:\users\" & "(name of current user)" & "\Desktop\" & "(parameter "SCName").lnk" }"
appendfile   oLink.Description = "{parameter "SCdesc"}"
appendfile   oLink.HotKey = "{parameter "SChotkey"}"
appendfile   oLink.IconLocation = "{icon pathname of shortcut of file "(parameter "SCName").lnk" of(folder "c:\users\" & (name of current user )& "\Desktop"))}"
appendfile   '    oLink.WindowStyle = "1"
appendfile   '    oLink.WorkingDirectory = ""
appendfile   oLink.Save
copy __appendfile "C:\Temp\replaceshortcut.vbs"

Sometimes you just need a second set of eyes… if it’s what I think, you were so very close but between all the quotes toggling between relevance and literal strings you missed one at the end of the line…

& "(parameter "SCName").lnk" }"

Should be

& (parameter "SCName") & ".lnk" }"

Hi Jason,

thanks for the feedback. i tried this and i still got a relevance substitution error. see section from the logs below

Command failed (Relevance substitution failed) appendfile oLink.Arguments = “{Argument string of shortcut of file “c:\users” & (name of current user) & “\Desktop” & (parameter “SCName”) & “.lnk” }”

the shortcut i’m trying to inspect is located in the desktop folder of the current user profile. the system has multiple users and the shortcut arguments are unique for each

It might be a forum thing, but there seem to be missing backslashes

and I think parentheses are needed to get the evaluation order correct

appendfile oLink.Arguments = “{Argument string of shortcut of file (“c:\users\” & (name of current user) & “\Desktop\” & (parameter “SCName”) & “.lnk” )}”

I see the Arguments line is the first time you actually reference the file - are you sure the file exists?

Try testing existence before you get into the ‘appendfile’ statements to see whether you’re actually finding the file, if it doesn’t exist you’ll need to handle it differently. Try

continue if {exists file "c:\users\" & (name of current user) & "\Desktop\" & (parameter "SCName") & ".lnk"}

It might also be useful to have the full pathname defined in a parameter earlier in the script, so the pathname you expect shows up in the client log. Maybe you have situations like username != profile path name ?

parameter "SCFilePath"="{"c:\users\" & (name of current user) & "\Desktop\" & (parameter "SCName") & ".lnk"}"

,and, as I was pasting that, I saw another spot where the quotes were wrong on the Arguments line… on & "(name of current user)" & there should not be any quotes, that should be & (name of current user) &

Hi Jason,

the file exists, something interesting to note, on the parameter SCfilepath, is able to resolve the relevance to the file name on the user desktop.

i got a relevance substitution error at the “continue if” which is almost the same relevance as the SCfilepath parameter. so i just commented out the “continue if” statement.

I used the SCFilePath parameter in the appendfile and it worked.

see sample code

parameter “SCFilePath”="{"c:\users" & (name of current user) & “\Desktop" & (parameter “SCName”) & “.lnk”}” - this works

continue if {exists file "c:\users" & (name of current user) & "\Desktop" & (parameter “SCName”) & “.lnk”} – this gives a relevance substitution error

continue if {exists file (parameter “SCFilePath”)} — this works, the file actually exists and it proceeds to the append file section

appendfile oLink.Arguments = “{Argument string of shortcut of file (parameter “SCFilePath”)}” – this works

not sure why the relevance does not work directly except through parameterizing it. perhaps there might have been an extra quotes somewhere that i accidentally included.

Thanks

Hi Trn,

i tried this method as well but still got a relevance substitution error.

Thanks.

This one fails because it doesn’t interpret the whole concatenation as the filename - it needs

continue if {exists file ("c:\users" & (name of current user) & "\Desktop" & (parameter "SCName") & ".lnk")}

But if I read correctly, you have it working now?

yes i do. thank you. it works using the parameter.