K1000 Scripting: Changing icon of shortcut via script
I am brand new to scripting. I can create the Kace script to put a URL shortcut on all users desktops, but I need to give it an icon so it isn't just a blank page. I have googled and tried vbs and batch scripts to get it to work and am having zero results. any clues or help?
2 Comments
[ + ] Show comments
Answers (1)
Answer Summary:
Please log in to answer
Posted by:
drose23
11 years ago
YMMV - but here is a script I've used to accomplish this task.
Option Explicit
On Error Resume Next
Dim objShell
Dim objDesktop
Dim objLink
Dim strAppPath
Dim strWorkDir
Dim strIconPath
strWorkDir ="C:\windows"
strAppPath = "%PATH TO EXE OR TARGET%"
strIconPath = "%PATH TO .ICO OR SIMILAR FILE%"
Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("AllUsersDesktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Shortcut.lnk") 'change here To your shortcut name
objLink.Description = "Description" 'replaec with your description
objLink.IconLocation = strIconPath
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save
Comments:
-
This is a vb script correct? So, do you have the first step unzip the icon file and the second step run this script? - lmland 11 years ago
-
What is YMMV? - lmland 11 years ago
-
Your Mileage May Vary. Just stating it's worked well for me. - drose23 11 years ago
-
Yes - this script assumes the .ico file already exists at the path. We do our deployments with WISE Scripting, so the file copy would occur outside of the .vbs itself - drose23 11 years ago
-
Can't say how that would work with a K1000, however. - drose23 11 years ago
-
I cannot get this to work. I've used both methods in this article to call a vb script: http://www.kace.com/support/resources/kb/article/how-to-call-a-visual-basic-script and neither one puts a shortcut on the desktop. Here's the order for the script:
1. Verify that the file “C:\Users\Public\Desktop\Waco ISD Help Desk.lnk†exists.
2. Remediation: Unzip “$(KACE_DEPENDENCY_DIR)\helpdesk.zip†to “C:\Users\Public\Desktopâ€. (This is the icon file.)
3. Run script either as batch file launching cscript.exe or launch program to run the above script modified for my purposes to:
Option Explicit
On Error Resume Next
Dim objShell
Dim objDesktop
Dim objLink
Dim strAppPath
Dim strWorkDir
Dim strIconPath
strWorkDir ="C:\windows"
strAppPath = "https://helpdesk.wacoisd.org"
strIconPath = "C:\Users\Public\Desktop\helpdesk.ico"
Set objShell = CreateObject("WScript.Shell")
objDesktop = objShell.SpecialFolders("AllUsersDesktop")
Set objLink = objShell.CreateShortcut(objDesktop & "\Waco ISD Help Desk.lnk")
objLink.Description = "Waco ISD Help Desk"
objLink.IconLocation = strIconPath
objLink.TargetPath = strAppPath
objLink.WindowStyle = 3
objLink.WorkingDirectory = strWorkDir
objLink.Save
Anyone see what I'm doing wrong? icon file shows up on desktop, but that's it. - lmland 11 years ago -
Again not knowing KACE - what happens when you run that VBscript outside of KACE, assuming all pre-requisites exist? Does the icon get created successfully?
The script itself looks fine to me - drose23 11 years ago-
Although I'd suggest placing the .ico file somewhere besides the desktop. - drose23 11 years ago
-
script works perfect outside of kace. - lmland 11 years ago
-
OK, unfortunately my ability to assist ends here then. Good luck - drose23 11 years ago
-
Figured it out. Needed to run the vb script in the same task as unzipping the icon. Works like a charm now. Still not sure how to do this with a managed install as others suggested. Scripting seems simpler. - lmland 11 years ago
-
I added how to use it with scripting in the comments. You can do it though MI, but scripting is better for this. With MIs you would need to create a custom inventory rule, and all of that. - dugullett 11 years ago
-
Ok, next question... does anyone know how to set a script to run as a specific user (i.e. administrator)? - lmland 11 years ago
-
General fora etiquette - not just here - is to not add supplementary questions to a solved problem but rather to create a new thread. That is for your benefit, of course. How will anyone know you asked this new question unless they happen to be reading what is essentially an unrelated question? - anonymous_9363 11 years ago
-
You're right. Apologies. I will start a new thread. - lmland 11 years ago
I am trying to run it as a script. How would I do it as a MI? I need to create a software asset for the shortcut first? Zip the shortcut and icon file together? Help! - lmland 11 years ago
Verify: A File Exists
Directory: c:\users\Public\desktop
File: shorcut.lnk
Remediation: Unzip a file
Directory: $(KACE_DEPENDENCY_DIR)
File: Name_of_zip.ZIP
Target: c:\users\Public\desktop - dugullett 11 years ago