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

Creating a desktop shortcut 1

Status
Not open for further replies.

llmclaughlin

Programmer
Aug 20, 2004
140
US
Not sure what I need to include to make this work. WshShell.SpecialFolders has the blue line under it stating "Reference to a non-shared member requires an object reference. I added a reference to Microsoft Scripting to the project and I Import IWshRuntimeLibrary.


Dim DesktopDir As String = _
CType(WshShell.SpecialFolders.Item("Desktop"), String)
Dim shortCut As IWshRuntimeLibrary.IWshShortcut

' short cut files have a .lnk extension
shortCut = CType(WshShell.CreateShortcut(DesktopDir & _
"\QPMSOffice.lnk"), _
IWshRuntimeLibrary.IWshShortcut)

Any help appreciated

Louie
 
Before you get any further with this, do you realise that if you get this working it will only create a shortcut on the web server, not the clients computer?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
No, didn't think about that, I've seen it done on other sites. The one's I've seen say Copy shortcut to desktop, when you click them it does that. I guess this is not the same thing huh?

Know of an example I can reference to do this?


Louie
 
ASP.NET is a server side language and stands for Active Server Pages.NET so any ASP.NET code you write will run on the server.

If you want to do something on the client, you'll have to use a client side language such as javascript.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here's a function I created that adds a shortcut to the desktop:
Code:
Function CreateShortCutOnDeskTop(strLnk, strTargetPath, strArguments, strIconLocation)

    Dim strTarget

'****************************************************
'*  If the shortcut already exists, then delete it  *
'****************************************************

    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(strFolder & strLnk) Then fso.GetFile(strFolder & strLnk).Delete
    Set fso = Nothing

'*********************
'*  Create shortcut  *
'*********************

    set oShell = CreateObject("WScript.Shell") 
    sDesktop = oShell.SpecialFolders("AllUsersDesktop") 

    set oSLink = oShell.CreateShortcut(sDesktop & "\" & strLnk)
    oSLink.TargetPath = strTargetPath
    oSlink.Arguments = strArguments & " //nologo"
    oSlink.IconLOcation = strIconLocation

    oSLink.Save

end function

This is how I call the function (i.e. via the onclick event of a command button or whatever) Note that you will need to change the items in red.

Dim oShell
Dim strArguments
Dim strIconLocation
Dim strTargetPath

On error resume next

set oShell = CreateObject("WScript.Shell")
strTargetPath = """" & oShell.ExpandEnvironmentStrings("%windir%") & "\system32\wscript.exe"""
strArguments = """\\path\MyLaunch.vbs"""
strIconLocation = "\\path\MyIcon.ico"

CreateShortCutOnDeskTop "MyName.lnk",strTargetPath, strArguments, strIconLocation

if (err.number = 0) then msgbox "A shortcut has been added to your desktop.",vbinformation,"Shortcut Created"
else
...
err.clear
end if


 
I'm guessing that the above is vbscript in which case you are limiting your audience to IE only (any users using another browser won't be able to use it).

I'd go with a javascript method if that is possible.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm,

You're right. My function was created for our intranet site which is IE only.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top