neelyjer
asked on
VBScript to change shortcut properties
Hello Experts,
I have 120 shorcuts that all include the same ip address in the target field under shorcut properties. I need to change the ip address all shorcuts to HomePC. I'm sure there's a way to do it programtically with VBScript rather than by hand, I'm just not sure how to do that. I do have some experience with VBScript, just not enough to risk screwing up all of the shortcuts. Below is an example of what I am looking for:
Original Target Value --
C:\Sim\Sim.exe C:\Sim\SimTrack\MyTrack.si m -sa 192.168.0.10:15700 -rs y -sn C:\Sim\SimTrack\MyTrack.ss f
Updated Value --
C:\Sim\Sim.exe C:\Sim\SimTrack\MyTrack.si m -sa HomePC:15700 -rs y -sn C:\Sim\SimTrack\MyTrack.ss f
All shorcuts are slightly different except for the IP address. The ip addess is the only thing I'd like to change.
Can anyone suggest how to do this?
Thanks Experts!!
I have 120 shorcuts that all include the same ip address in the target field under shorcut properties. I need to change the ip address all shorcuts to HomePC. I'm sure there's a way to do it programtically with VBScript rather than by hand, I'm just not sure how to do that. I do have some experience with VBScript, just not enough to risk screwing up all of the shortcuts. Below is an example of what I am looking for:
Original Target Value --
C:\Sim\Sim.exe C:\Sim\SimTrack\MyTrack.si
Updated Value --
C:\Sim\Sim.exe C:\Sim\SimTrack\MyTrack.si
All shorcuts are slightly different except for the IP address. The ip addess is the only thing I'd like to change.
Can anyone suggest how to do this?
Thanks Experts!!
no exactly your question but theres a program 'shortcut doctor'...http://www.funduc.com/shortcut_doctor.htm. but i was using it to change to path to executable,rarther than the parameters
Make some kind of file iteration and for each file use this functions:
Set oWS = WScript.CreateObject("WScr ipt.Shell" )
sLinkFile = "C:\program.lnk"
Set oLink = oWS.CreateShortcut(sLinkFi le)
oldpath=oLink.TargetPath
newpath="C:\windows\notepa d.exe"
oLink.TargetPath=newpath
oLink.Save
Set oWS = WScript.CreateObject("WScr
sLinkFile = "C:\program.lnk"
Set oLink = oWS.CreateShortcut(sLinkFi
oldpath=oLink.TargetPath
newpath="C:\windows\notepa
oLink.TargetPath=newpath
oLink.Save
https://www.experts-exchange.com/questions/21814142/VBScript-Modify-a-shortcut-NOT-CREATE-ANOTHER-ONE.html shows the way. with http://www.ss64.com/nt/shortcut.html
CreateShortCut is used for both create & modify...
Set oWS = WScript.CreateObject("WScr ipt.Shell" )
'search for all link files
' for each one found .. modify
ModifyLink lnkfilename
'next link
Wscript.quit
Sub ModifyLink (sLinkFile)
' sLinkFile = "C:\MyShortcut.LNK"
Set oLink = oWS.CreateShortcut(sLinkFi le)
oLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
' oLink.Arguments = ""
' oLink.Description = "MyProgram"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
' oLink.WindowStyle = "1"
' oLink.WorkingDirectory = "C:\Program Files\MyApp"
oLink.Save
Exit Sub
CreateShortCut is used for both create & modify...
Set oWS = WScript.CreateObject("WScr
'search for all link files
' for each one found .. modify
ModifyLink lnkfilename
'next link
Wscript.quit
Sub ModifyLink (sLinkFile)
' sLinkFile = "C:\MyShortcut.LNK"
Set oLink = oWS.CreateShortcut(sLinkFi
oLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
' oLink.Arguments = ""
' oLink.Description = "MyProgram"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE,
' oLink.WindowStyle = "1"
' oLink.WorkingDirectory = "C:\Program Files\MyApp"
oLink.Save
Exit Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
@ robberbaron
I haven't tried your code yet but, can you breakdown what the code is doing for my future reference?
Thanks
Jeremy
I haven't tried your code yet but, can you breakdown what the code is doing for my future reference?
Thanks
Jeremy
it's hardly 'my code' as it is copied from the links.
1. Set link = Osw.createshortcut(sLinkFi le)
this is creating the shortcut object and opening the EXISTING shortcut defined by sLinkfile. It could also create a new shortcut if sLinkFile does not exist.
2. The shortcut object has properties. Such as target path , arguments, description, working directory. Just the same as those you see when viewing properties of an existing shortcut from the right-click menu.
3. the script allows editting of these.
for the arguments, we are searching for the string defined by sFind (=192.168.0.10) using InStr.
we then replace the found substring with a new one by adding the string before the found location , the new string and then the bit of original from after the found substring
hope that helps.
1. Set link = Osw.createshortcut(sLinkFi
this is creating the shortcut object and opening the EXISTING shortcut defined by sLinkfile. It could also create a new shortcut if sLinkFile does not exist.
2. The shortcut object has properties. Such as target path , arguments, description, working directory. Just the same as those you see when viewing properties of an existing shortcut from the right-click menu.
3. the script allows editting of these.
for the arguments, we are searching for the string defined by sFind (=192.168.0.10) using InStr.
we then replace the found substring with a new one by adding the string before the found location , the new string and then the bit of original from after the found substring
hope that helps.
ASKER
Using the follwoing...
Set oWS = WScript.CreateObject("WScr ipt.Shell" )
ModifyLink lnkfilename
Wscript.quit
Sub ModifyLink (sLinkFile)
'sLinkFile = "C:\Documents and Settings\jneel00\Desktop\S im++ Stuff\SIM SPs\TEst\"
Set oLink = oWS.CreateShortcut(sLinkFi le)
sFind = "192.175.0.10"
sReplace = "HomePC"
ix = instr(oLink.Arguments, sFind)
if ix > 0 then
oLink.Arguments = left(oLink.Arguments,ix-1) & sReplace & mid(oLink.Arguments,ix+len (sFind))
oLink.Save
end if
Exit Sub
End Sub
I am receiving an error on the following:
Set oLink = oWS.CreateShortcut(sLinkFi le)
The error says that the pathname must end in .lnk or .url. I am trying to use this code to update the 120 links I have in this directory. Am I missing something?
Set oWS = WScript.CreateObject("WScr
ModifyLink lnkfilename
Wscript.quit
Sub ModifyLink (sLinkFile)
'sLinkFile = "C:\Documents and Settings\jneel00\Desktop\S
Set oLink = oWS.CreateShortcut(sLinkFi
sFind = "192.175.0.10"
sReplace = "HomePC"
ix = instr(oLink.Arguments, sFind)
if ix > 0 then
oLink.Arguments = left(oLink.Arguments,ix-1)
oLink.Save
end if
Exit Sub
End Sub
I am receiving an error on the following:
Set oLink = oWS.CreateShortcut(sLinkFi
The error says that the pathname must end in .lnk or .url. I am trying to use this code to update the 120 links I have in this directory. Am I missing something?
ASKER
BTW...
The code works great when I specify a specific link to be modified.
The code works great when I specify a specific link to be modified.