• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 15573
  • Last Modified:

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.sim -sa 192.168.0.10:15700 -rs y -sn C:\Sim\SimTrack\MyTrack.ssf

Updated Value --
C:\Sim\Sim.exe C:\Sim\SimTrack\MyTrack.sim -sa HomePC:15700 -rs y -sn C:\Sim\SimTrack\MyTrack.ssf

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!!
0
neelyjer
Asked:
neelyjer
  • 4
  • 3
1 Solution
 
Robberbaron (robr)Commented:
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
0
 
MikkkCommented:
Make some kind of file iteration and for each file use this functions:

Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\program.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oldpath=oLink.TargetPath
newpath="C:\windows\notepad.exe"
oLink.TargetPath=newpath
oLink.Save
0
 
Robberbaron (robr)Commented:
http://www.experts-exchange.com/Programming/Misc/Q_21814142.html shows the way.  with http://www.ss64.com/nt/shortcut.html

CreateShortCut is used for both create & modify...


   Set oWS = WScript.CreateObject("WScript.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(sLinkFile)
   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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Robberbaron (robr)Commented:
  Set oLink = oWS.CreateShortcut(sLinkFile)
   sFind = "192.168.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.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
   end if
0
 
neelyjerAuthor Commented:
@ robberbaron

     I haven't tried your code yet but, can you breakdown what the code is doing for my future reference?

Thanks

Jeremy
0
 
Robberbaron (robr)Commented:
it's hardly 'my code' as it is copied from the links.

1. Set link = Osw.createshortcut(sLinkFile)
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.
0
 
neelyjerAuthor Commented:
Using the follwoing...

Set oWS = WScript.CreateObject("WScript.Shell")
ModifyLink lnkfilename
Wscript.quit
Sub ModifyLink (sLinkFile)
'sLinkFile = "C:\Documents and Settings\jneel00\Desktop\Sim++ Stuff\SIM SPs\TEst\"
Set oLink = oWS.CreateShortcut(sLinkFile)
   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(sLinkFile)

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?
0
 
neelyjerAuthor Commented:
BTW...

The code works great when I specify a specific link to be modified.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now