PDA

Click to See Complete Forum and Search --> : Creating shortcuts to the desktop


Rafael
Dec 13th, 1999, 04:15 AM
How can I create shortcut to the desktop to any program, I have tried with to ways, but they are not work.
How can I retrieve the \Desktop directory in Windows 95, Nt Workstation, Windows 2000, etc...

Please Help me

------------------

PietHein
Dec 13th, 1999, 05:51 PM
Isn't that

C:\windows\desktop for all OS?

Dec 13th, 1999, 06:37 PM
In Windows NT, there is for any User Profile a Desktop Folder. I think when you would place a LNK File in this Folder it should work.
C:\WINNT\Profiles\Username\Desktop

Serge
Dec 13th, 1999, 06:47 PM
To get the Desktop folder path, use this:


Private Const CSIDL_DESKTOP = &H0
Private Const MAX_PATH = 255
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long

Public Function GetDesktopFolderPath(ByVal pHwnd As Long) As String
Dim lReturn As Long
Dim lPidl As Long
Dim lPath As Long
Dim sPath As String

sPath = Space$(MAX_PATH)
lReturn = SHGetSpecialFolderLocation(pHwnd, CSIDL_DESKTOP, lPidl) ' Get lPidl for Id...
If lReturn = 0 Then ' If success is 0
lReturn = SHGetPathFromIDList(lPidl, sPath) ' Get Path from Item Id List
If lReturn = 1 Then ' If success is 1
sPath = Left(sPath, InStr(sPath, vbNullChar) - 1) ' Fix path string
GetDesktopFolderPath = sPath ' Return Favorite path
End If
End If
End Function



Then you can call this function to get the path of the desktop folder:


Dim strPath As String

strPath = GetDesktopFolderPath(Me.Hwnd)


strPath now holds the path to the Desktop.

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

HeSaidJoe
Dec 13th, 1999, 07:45 PM
'create a shortcut to a file and place it on desktop
'
Option Explicit
'
Private Declare Function SHGetSpecialFolderLocation Lib _
"Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, _
ppidl As Long) As Long

Private Declare Function SHGetPathFromIDList Lib "Shell32" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath _
As String) As Long

Private Const MAX_PATH = 260

Public Function GetDesktopFolderPath(ByVal pHwnd As Long) _
As String

Dim lReturn&
Dim lPidl&
Dim strPath$
strPath$ = Space(MAX_PATH)
lReturn& = SHGetSpecialFolderLocation(pHwnd, 0, lPidl)

' Get lPidl& for this Id...
If lReturn = 0 Then
lReturn = SHGetPathFromIDList(lPidl, strPath)
' Get Path from Item Id List
If lReturn = 1 Then 'If successeful
GetDesktopFolderPath = Left(strPath$, _
InStr(strPath$, vbNullChar) - 1)

End If
End If
End Function
'
'====================put his in form load =======================
'
Dim strDesktop$
strDesktop = GetDesktopFolderPath(Me.hWnd)
Dim strMyfile$
strMyfile = InputBox("Enter the path and name of file, & vbcrlf" _
& "you want to create a shortcut for.")
Dim strShortCutName$
strShortCutName$ = InputBox _
("Enter the name for the shortcut icon")

FileCopy strMyfile$, strDesktop$ & "\" & strShortCutName$

AaronC
Apr 17th, 2000, 05:08 AM
Check out http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=7349.
There is code from the VB6 Pro CD that creates shortcuts. (It is also in a lot easier to download format)

run2thesun
Jul 31st, 2001, 12:48 AM
Private Const CSIDL_DESKTOP = &H0

This constant is for the Desktop folder. Do you know the constant for the Startup group?