irish
irish

Reputation: 197

How to make my VB script overwrite the existing Shortcut file instead of creating a duplicate

I am using the following VB Script to update the target location & add arguments to it.

Set wsc = WScript.CreateObject("WScript.Shell") 
Set lnk = wsc.CreateShortcut(wsc.SpecialFolders("desktop") & "\Soft.LNK") 

lnk.targetpath = "C:\Soft\bin\Soft.exe" 
lnk.Arguments = "-user:App -passwd:App1" 
lnk.save

The script works fine only that it creates another (duplicate) shortcut file instead of just updating the existing file.

I call this vb script from another batch file

Any ideas?

Cheers

Upvotes: 0

Views: 908

Answers (1)

MC ND
MC ND

Reputation: 70933

The elements you see in the desktop are stored in different folders.

Assuming that there are two shortcuts with the same name, i will bet each shortcut is placed in a different folder. The one you are creating with your code will be placed in the desktop folder of the current user and the previous one in a shared folder.

You can not overwrite the existing shortcut if the path used to open it point to another folder. Check in the properties of the shortcut, inside the "General" tab, where the shortcuts are stored.

The most probable solution is

Set lnk = wsc.CreateShortcut(wsc.SpecialFolders("AllUsersDesktop") & "\Soft.LNK") 

Upvotes: 1

Related Questions