Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing an Icon through Batch file 2

Status
Not open for further replies.

AccessUser22

Technical User
Jan 23, 2003
168
US
I currently am using a shortcut to a batch file on my client desktops for the purpose of launching a database. It checks for updates, if necessary downloads what the update, and then launches the database. I have this installed on quite a few machines and we have just decided to change the icons we are using for the shortcut to the batch. I was wondering if there is a way to do this through the batch. I figured there is probably an easy one or two lines of code that I would need to insert in to make it change the icon rather than running around and having to fix this manually on people's machines. If anyone has any ideas, it would be greatly appreciated. Thanks.
 
You should be able to adapt the VBS script below to your needs.

Code:
Dim WSH, FSO, Link, DelShortcut
Set WSH = Wscript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Check for current shortcut and delete it
DelShortcut = "C:\Documents and Settings\All Users\Desktop\GroupWise 5 manual.lnk"
If FSO.FileExists (DelShortcut) Then FSO.DeleteFile DelShortcut,True

' Create a named shortcut object
Set Link = WSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\GroupWise 5 manual.lnk")

' Set the shortcut's properties and save it
Link.TargetPath="C:\Novell\GroupWise\gw55.pdf"
Link.WorkingDirectory = "C:\Novell\GroupWise"
Link.WindowStyle = 1
Link.IconLocation = "P:\" & name & "\installer.ico, 0"
Link.Save()

'Clear memory and finish up
Set WSH = Nothing
Set FSO = Nothing
WScript.Quit()

Save the code above as something like change-shortcut.vbs then open it in Notepad and change the details to reflect the batch file you want to run and the location of the icon.

Link.TargetPath = Filepath to the batch.

Link.WindowStyle = How you want it to launch. The WindowStyle property sets or retrieves how the application pointed to by the shortcut will be displayed when it is first launched. If WindowStyle is 1, then the application window will be set to its default location and size. If this property has a value of 3, the application will be launched in a maximized window, and if it has a value of 7 it will be launched in a minimized window.

If a value other than 1, 3, or 7 is assigned to this property, the shortcut will be launched in a window at the default location and of the default size.

Link.IconLocation = Filepath to the icon. The '0' following the icon filename (installer.ico) is the number of the icon to use, starting from 0 (not 1). The first embedded icon is number 0, the second is number 1, etc. For example, if you wanted to use the third embedded icon in shell32.dll then then the line would end as 'shell32.dll, 2'.

Hope this helps...
 
Nice one Rick

-----------------------------------------------------
"It's true, its damn true!"
-----------------------------------------------------
 
I have one more question for the above code. I was wondering if there was a way to trap the users login id through code so that instead of referencing the All Users folder, I could reference that particular users folder. It seems the original shortcut is in the users folder instead of the All Users folder. Any advice is appreciated. Thanks.
 
you can put this code before defining the path. instead of "all users" grab user name from an input box:

username = inputbox("enter user name")
and put the variable "username" between "\documents and settings" and "desk top" like this

username = inputbox("enter user name")
Set Link = WSH.CreateShortcut("C:\Documents and Settings\" & username & "\Desktop\GroupWise 5 manual.lnk")
 
Is there anyway to just trap the user's windows login name though? I don't want them to have to type it in otherwise they may get confused what user name they are entering, their windows login or their access database login. Even if I clarified it in the input box, I still would rather bypass the input box altogether to prevent any problems. Thanks.
 
user name can be found using regread command in the above code from the registry in this location:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top