Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Use wildcard in VBScript to rename desktop shortcut

Posted on 2009-05-08
4
1,773 Views
Last Modified: 2012-05-06
Hi,
I have script that I'm using to change some IBM Client Access session names.  As a part of that I'd like to have the desktop shortcuts named in a specific way:  The name of the telnet session followed by the computer name.  My issue is that I want to reuse the script for existing computers but the desktop shortcuts can start with several different naming conventions and I need to use a wildcard to select the correct shortcut.  What I can't figure out is how to use a wildcard properly in renaming a file.  Can anyone help?

Assume that the selection will only return one filename.  Thanks in advance.

B7-SYSB {ComputerName}

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject( "WScript.Shell" )
ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")
'Notice the * in Shortcut to b7-image* below.
objFSO.MoveFile "C:\Documents and Settings\All Users\Desktop\Shortcut to b7-image*" , "C:\Documents and Settings\All Users\Desktop\B7-SYSB " & ComputerName & ".lnk"

Open in new window

0
Comment
Question by:touch0ph_
  • 2
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 450 total points
ID: 24335729
How about the following?
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject( "WScript.Shell" )
ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")
'Notice the * in Shortcut to b7-image* below.
 
Dim shortcut
Set folder = objFSO.GetFolder("C:\Documents and Settings\All Users\Desktop")
Set files = folder.Files
 
For Each file in files
    If Mid(file.name, 1, 20) = "Shortcut to b7-image" Then
        shortcut = file.Path
    End If
Next
 
If short <> Empty Then
    objFSO.MoveFile shortcut, "C:\Documents and Settings\All Users\Desktop\B7-SYSB " & ComputerName & ".lnk"
End If

Open in new window

0
 

Accepted Solution

by:
touch0ph_ earned 0 total points
ID: 24336493
Works pretty well.  I modified line 16 (see below).

I ran into an issue though.  If the shortcut name on the desktop is a different case than what's defined in the IF statement on line 11, the shortcut get's ignored - see below in modified line 11.  I included an OR to handle icons that may have slightly different names.  I can't catch them all of course but using these values I can get most.

What can we do about the case sensitivity?  Thanks!
'Modify line 16
If shortcut <> Empty Then
   objFSO.MoveFile shortcut, "C:\Documents and Settings\All Users\Desktop\B7-SYSB " & ComputerName & ".lnk"
End If
 
 
 
'Modfied line 11
For Each file in files
    If Mid(file.name, 1, 19) = "shortcut to a2-sysa" or Mid(file.name, 1, 7) = "A2-SYSA"  Then
        shortcut = file.Path
    End If

Open in new window

0
 
LVL 17

Assisted Solution

by:Jared Luker
Jared Luker earned 50 total points
ID: 24336648
You can use ucase or lcase in order to set the variable to upper or lower case.  That way, you can code for one case only and not have to worry about missing things because of a case problem.

http://www.devguru.com/Technologies/vbscript/quickref/lcase.html
http://www.devguru.com/Technologies/vbscript/quickref/ucase.html
0
 
LVL 17

Assisted Solution

by:Jared Luker
Jared Luker earned 50 total points
ID: 24336663
So Line 11 would look something like

If LCase(Mid(file.name, 1, 20)) = "shortcut to b7-image" Then
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question