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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use vbscript to create desktop icon?

Status
Not open for further replies.

adonet

MIS
May 4, 2004
312
US
I want to create desktop shortcut for " and use c:\cnn.ico file. How to write a script?
 
Hello adonet,

To set icon to url link, you have to do a bit more.
Code:
'Four parameters surlshortcutname, stargetpath, iconindex, iconfile

surlshortcutname="cnn"	'without extension
stargetpath="[URL unfurl="true"]http://www.cnn.com"[/URL]

'To use default, set these 2 variables to null (either one will do)
'If use existing setting, set them to empty string or comment them out (either one will do)

iconindex=0
iconfile="c:\cnn.ico"

set wshshell=createobject("wscript.shell")
sDesktop=wshshell.specialfolders("Desktop")
set ourllink=wshshell.createshortcut(sDesktop & "\" & surlshortcutname & ".url")
ourllink.targetpath=stargetpath
ourllink.save

surllinkfile=ourllink.fullname
set ourllink=nothing : set wshshell=nothing

if isempty(iconindex) or isempty(iconfile) then
    wscript.quit (0)	'existing urllink, if any, settings, are preserved
end if

set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(surllinkfile)
set ots=f.openastextstream(1)
contents=""
do while not ots.atEndofstream
    line=ots.readline
    if instr(1,line,"IconIndex",1)=0 and instr(1,line,"IconFile",1)=0 then
        contents=contents & line & vbcrlf
    end if
loop
ots.close

if not (isnull(iconindex) or isnull(iconfile)) then
    if not (isempty(iconindex) or isempty(iconfile)) then
        contents=contents &"IconIndex=" & cstr(iconindex) & vbcrlf
        contents=contents & "IconFile=" & iconfile
    end if
end if
set ots=f.openastextstream(2)
ots.write contents
ots.close
set ots=nothing : set f=nothing : set fso=nothing
regards - tsuji
 
I have been looking for something EXACTLY LIKE THIS for quite a while now. [medal] [2thumbsup]

Thank You, Thank You , Thank You!!!!!!!!!!!!!

Thank You,

Roger Truss
A+, Network+
Workstation Customer Support Analyst
rtruss@mercmarine.com
Mercury Marine
 
question please from "just learning pete"

I want to be able to put this script on a shared drive and have users click on script to put a shortcut on there desktop.

In testing, the script is placed on any desktop and goes to the web site ok but the icon file i want is not there. Instead it uses default image. Im not sure how to tell the script the icon i want is in the same directory as the script, use it. Tried a few different ways, no luck.
Now its off to the rum and coke .....thanks pete


 
pete01,

Nearly forgot I'd involved in this thread. For a shared folder, the script should still work, for instance:
[tt] iconfile="\\a0b1c2\sharename\cnn.ico"[/tt]
But if you lost momentarily the share, then it can be guaranteed.

regards - tsuji
 
tsuji

Gave it a quick try but still the default icon is placed on the desktop instead of my icon.

I'll play around some more, check permisson, naming etc. and see what happens.

thanks....pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top