-
[RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Hello,
I'm a newbie here, but have been kicking around in VB for more years than I like to remember.
My question: we distribute a VB6 app that creates a desktop shortcut. At least it did so reliably on all OSs prior to Vista. No luck in Vista. The installer is a customized version of the "Setup1" program provided with the VB6 P&D Wizard.
If this is old news, my apologies. I've searched around but could not find a thread covering it.
Thanks in advance for any suggestions,
M2
-
Re: Install VB6 App to Vista, desktop shortcut missing
Welcome here
The P & D wizard frequently fail in new windows versions , so it is rarely used now , search download.com for inno or setup2go or Windows installer.
-
Re: Install VB6 App to Vista, desktop shortcut missing
Moved to applications deployment
-
Re: Install VB6 App to Vista, desktop shortcut missing
Mohammed,
Thanks much. I am aware of more up-to-date installers, but the one we're using for this app (based on Setup1.exe from the P&D Wizard) works just fine with the exception of ... missing desktop shortcut when installing to Vista. I'd like to avoid creating a new installer for this app if at all possible.
Is there some coding required to create the desktop icon when installing to Vista that was not required in prior OSs ?
Thanks again,
M2
-
Re: Install VB6 App to Vista, desktop shortcut missing
What code are you currently using to create the desktop shortcut when installing to XP?
The user profiles are in a different location for Vista so if its looking in the old location it will fail.
-
Re: Install VB6 App to Vista, desktop shortcut missing
Yoda,
Here's the code. I think I'm getting a glimmer of where we're going. No hands on experience with Vista yet on my part.
Dim lRet As Long
Dim sFolderName As String
Dim sLinkName As String
Dim sLinkPath As String
Dim sLinkArgs As String
Dim fPrivate As Boolean
Dim sParent As String
sLinkName = "MyProgram"
sLinkPath = gsDest.strAppDir & "MyProgram.exe"
'gsDest.strAppDir, set elsewhere by user, is the folder we install to
sLinkArgs = ""
sParent = "$(Programs)"
sFolderName = "..\..\desktop"
fPrivate = True
'observed: this works on OSs thru Win XP
lRet = OSfCreateShellLink(sFolderName, sLinkName, sLinkPath, sLinkArgs, fPrivate, sParent)
Thanks
M2
-
Re: Install VB6 App to Vista, desktop shortcut missing
I use the same code & I remember that I faced a bug in this line once
VB Code:
sFolderName = "..\..\desktop"
but I don't remember how I resolved it.
-
Re: Install VB6 App to Vista, desktop shortcut missing
Yes, thats the problem but transversing the folder path will not work either as the Desktop folders are in completely different locations then it was under XP.
'Private desktop...
C:\Users\VB-Guru\Desktop
'All users desktop...
C:\Users\Public\Desktop
-
Re: Install VB6 App to Vista, desktop shortcut missing
I see.
have I got this right? If I substitute in my code (for Vista installs) ...
sFolderName = "C:\Users\Public\Desktop"
Then we should generate a desktop shortcut visible to all users?
(Or we could use the installing user's identifier to make a private shortcut.)
Thanks again,
M2
-
Re: Install VB6 App to Vista, desktop shortcut missing
Only if your user is installing the app under an Administrator profile or the Run As... with similar credentials.
-
Re: Install VB6 App to Vista, desktop shortcut missing
OK, I understand that part.
Now if I can just find the button to mark this thread as resolved, I'm good to go.
Thanks very much for the help.
M2
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
You must use APIs first to get the desktop path not just using a static path , a user may install Vista on his D:\ drive ;)
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Yes, that is correct and best to use APIs vs environment variables. In Vista there is none shown for profile path.
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Just tested it on my Vista system with vb 6 code that should be simple to convert to vb.net.
VB Code:
Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" ( _
ByVal hwnd As Long, ByVal pszPath As String, ByVal csidl As Long, ByVal fCreate As Long) As Long
Private Const CSIDL_COMMON_DESKTOPDIRECTORY As Long = &H19
Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10
Private Sub Form_Load()
Dim strPath As String * 255
'All users desktop path
SHGetSpecialFolderPath Me.hwnd, strPath, CSIDL_COMMON_DESKTOPDIRECTORY, 0
MsgBox strPath 'C:\Users\Public\Desktop
strPath = vbNullString
'Private user desktop path
SHGetSpecialFolderPath Me.hwnd, strPath, CSIDL_DESKTOPDIRECTORY, 0
MsgBox strPath 'C:\Users\VB-Guru\Desktop
End Sub
Edit: Woot! 36,000 posts! :thumb:
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Great. Tested and works on XP Home Edition, SP2 with VB6 also.
Returns ...
C:\Documents and Settings\All Users\Desktop
C:\Documents and Settings\user name\Desktop
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Looks like I was premature with the "resolved" tag.
The SHGetSpecialFolderPath call does indeed return the full path to either the public or private desktop.
But ... taking that path and inserting it as "sFolderName" in the following ...
lRet = OSfCreateShellLink(sFolderName, sLinkName, sLinkPath, sLinkArgs, fPrivate, sParent)
fails to create a desktop icon on my XP machine.
The same call works on my XP machine if I set ...
sFolderName = "..\..\desktop"
but that construct, it seems, does not work on a Vista machine.
I'm stumped.
M2
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Can you debug it to see what does the SHGetSpecialFolderPath return ?
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
SHGetSpecialFolderPath returns either
C:\Documents and Settings\All Users\Desktop
or
C:\Documents and Settings\user name\Desktop
depending on whether public or private path is called for (on my XP machine).
These seem just right, but do not work when inserted in the OSfCreateShellLink call.
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Perhaps wrapping the returned path with an extra set of double quotes will help since it will contain spaces which usually gives an error/headache.
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
I read somewhere that the OSfShellLink API does not like values as arguments, only variables. My testing seems to bear that out.
So, in making the call ...
lRet = OSfCreateShellLink(sFolderName, sLinkName, sLinkPath, sLinkArgs, fPrivate, sParent)
I use only variables, not string values like "xxx". The variable sFolderName has previously been set to...
"..\..\desktop" (this works)
or (for public desktop)
"C:\Documents and Settings\All Users\Desktop" (this fails).
I tried the double-qoute approach, but no luck.
(BTW, any way to remove the "resolved" tag from a thread??)
Thanks,
M2
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
I guess you can edit the first post to remove the Resolved mark.
-
Re: Install VB6 App to Vista, desktop shortcut missing
Thanks. I did so, but the check mark (indicating "resolved") preceding the thread title is still there.
-
Re: Install VB6 App to Vista, desktop shortcut missing
Change the subject icon on the first post.
Try passing the variables as ByValue instead.
-
Re: Install VB6 App to Vista, desktop shortcut missing
Byval has no effect; failed call still fails, successful call still succeeds.
Maybe I should try this another way:
Does anyone know of any VB6/API code which will place a program shortcut on a Windows Vista desktop?
I have code that works for every Windows version except Vista, and I am already testing for Vista in Setup1.exe anyway.
Thanks,
M2
-
Re: Install VB6 App to Vista, desktop shortcut missing
I have a CodeBank thread that deals with shortcut links etc.
Maybe it will help or guide you to creating one.
http://vbforums.com/showthread.php?t=322799
-
Re: Install VB6 App to Vista, desktop shortcut missing
Thanks, but I don't see the makings of a solution there.
If anyone can post some code to do this job, I'd very much appreciate it.
M2
-
Re: Install VB6 App to Vista, desktop shortcut missing
The following is reported by our users to create Public or Private desktop shortcuts on Windows XP and Vista. Have not tried it with any earlier OSs at this point.
Getting the paths to the public and private desktop folders via "WScript.Shell" should have worked, but had trouble there so used API calls for that piece.
Thanks to all for their suggestions.
--------------------------------------------------------------
Private Sub CreateDesktopShortcut(ByVal TargetPath As String, ByVal PrivateFlag As Boolean, ByVal ShortcutName As String)
'first, get DESKTOP paths (public/private)
'WScript.Shell not used for this piece ... seems always to return public path ??
Const CSIDL_COMMON_DESKTOPDIRECTORY As Long = &H19
Const CSIDL_DESKTOPDIRECTORY As Long = &H10
Dim NullChar As String
NullChar = Chr$(0)
Dim i As Integer
Dim PaddedDesktopPath As String * 255
Dim FullDesktopPath As String
'these calls return long strings with trailing null characters
If Not PrivateFlag Then
'get Public desktop path
SHGetSpecialFolderPath Me.hwnd, PaddedDesktopPath, CSIDL_COMMON_DESKTOPDIRECTORY, 0
Else
'get Private user desktop path
SHGetSpecialFolderPath Me.hwnd, PaddedDesktopPath, CSIDL_DESKTOPDIRECTORY, 0
End If
'get rid of null characters
i = InStr(PaddedDesktopPath, NullChar)
If i > 1 Then FullDesktopPath = Left(PaddedDesktopPath, i - 1)
'for testing
''''''MsgBox Len(FullDesktopPath) & " " & FullDesktopPath
'we have full path to the desktop ... public or private
'use it to create shortcut using WScript.shell
Dim VbsObj As Object
Dim MyShortcut As Object
Set VbsObj = CreateObject("WScript.Shell")
Set MyShortcut = VbsObj.CreateShortCut(FullDesktopPath & "\" & ShortcutName & ".lnk")
MyShortcut.TargetPath = TargetPath
MyShortcut.save
End Sub
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Glad to see that using some of my codebank code worked. :)
-
Re: [RESOLVED] Install VB6 App to Vista, desktop shortcut missing
Quote:
Originally Posted by Mark II
Hello,
I'm a newbie here, but have been kicking around in VB for more years than I like to remember.
My question: we distribute a VB6 app that creates a desktop shortcut. At least it did so reliably on all OSs prior to Vista. No luck in Vista. The installer is a customized version of the "Setup1" program provided with the VB6 P&D Wizard.
If this is old news, my apologies. I've searched around but could not find a thread covering it.
Thanks in advance for any suggestions,
M2
To answer your question, I presume that your customized installer implements what is in this article: "Make P&D Wizard create Desktop shortcuts".
The following updates are intended to fix two issues with this excellent code example:
A) Internationalization. The article assumes that the name of the Windows desktop folder is "Desktop". The shortcut creation will fail in most non-US Windows because this is not the case.
B) Windows Vista. The article assumes that the location of the user's Windows desktop is "{CSIDL_PROGRAMS}\..\..\Desktop". This assumption is true under (US) XP where {CSIDL_PROGRAMS} = "%SYSTEMDRIVE%\Documents and Settings\<user>\Start Menu\Programs" and {CSIDL_DESKTOP} = "%SYSTEMDRIVE%\Documents and Settings\<user>\Desktop", but is NOT true for Vista where {CSIDL_PROGRAMS} = "%SYSTEMDRIVE%\Users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu" and CSIDL_DESKTOP = "%SYSTEMDRIVE\Users\<user>\Desktop". This update fixes this issue as well.
Here are the updates to "http://www.freevbcode.com/ShowCode.asp?ID=3650" that fix these issues. In basSetup1's 'CreateIcons' Sub, add the Declarations below to the existing declarations within this sub. Next, replace the entire If-Then-End If section given in the mentioned article ("If UCase(strGroup) = "DESKTOP" Then...") with the Code snippet below.
Declarations:
Dim intCommonDepth As Integer
Dim DesktopPathArr As Variant
Dim ProgramsMenuPathArr As Variant
Code:
If UCase(strGroup) = "DESKTOP" Then
DesktopPathArr = Split(GetSpecialFolder(frmSetup1.hwnd, CSIDL_DESKTOP), "\")
'Get programs path, used in the function below
ProgramsMenuPathArr = Split(GetSpecialFolder(frmSetup1.hwnd, CSIDL_PROGRAMS), "\")
intCommonDepth = -1
Do While ((intCommonDepth + 1) < UBound(DesktopPathArr)) And ((intCommonDepth + 1) < UBound(ProgramsMenuPathArr))
If DesktopPathArr(intCommonDepth + 1) <> ProgramsMenuPathArr(intCommonDepth + 1) Then Exit Do
intCommonDepth = intCommonDepth + 1
Loop
strGroup = ""
For intIdx2 = intCommonDepth + 1 To UBound(ProgramsMenuPathArr)
strGroup = strGroup & "..\"
Next intIdx2
For intIdx2 = intCommonDepth + 1 To UBound(DesktopPathArr)
strGroup = strGroup & DesktopPathArr(intIdx2)
If intIdx2 < UBound(DesktopPathArr) Then strGroup = strGroup & "\"
Next intIdx2
End If