[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Desktop shortcuts in Win7 64 bit

Norm

8/24/2011 3:35:00 AM

Hi,

I had asked this question before and thought I had it solved. :-(, but
apparently not. I have a program that lists the desktop shortcuts and
lets you click on them to run them. This program works fine in the 32
bit version of Win7 and earlier OS's, but does not work in Win7 64 bit.
I know it must have something to do with the virtualization that
Windows does, but have not been able to figure out what to do. If I
make a desktop shortcut on the taskbar all the shortcuts work just
fine, but through my program trying to run the .lnk does not work for
any of the shortcuts. If I resolve the path to the executable and run
it that way some of them work, but not all of them.

I am using ShellExecute to start the .lnk's and get a return of 42,
which should mean no error, but the programs do not start or if they do
shutdown before they show up in the task manager.

Below is the code I am using:

Dim i As Long
Dim ExPath As String
Dim mnuPath As String
Dim lRet As Long

mnuPath = CP.Caption(ItemNumber)
If mnuPath = "Close Menu" Then Exit Sub

For i = 0 To lstDeskPath.ListCount - 1
If InStr(1, lstDeskPath.List(i), mnuPath, vbTextCompare) > 0 Then
'Get target path from shortcut
ExPath = ResolveLink(lstDeskPath.List(i))
ExPath = """" & ExPath & """"
Debug.Print ExPath
Debug.Print lstDeskPath.List(i)
'Shell out the target path
lRet = ShellExecute(Me.hwnd, "Open", lstDeskPath.List(i),
vbNullString, vbNullString, 1)
Debug.Print lRet
'If error display message box
If lRet < 32 Then
SingleButtonMsg "Unable To Open The File" & vbCrLf &
vbCrLf & _
ExPath, Me.hwnd, 5
Exit Sub
End If
'If Right$(ExPath, 4) = ".exe" Then 'Right$(ExPath,
Len(ExPath) - (Len(ExPath) - 4)) = ".exe" Then
'Shell ExPath, vbNormalFocus
'Else
'lRet = ShellExecute(Me.hwnd, "Open", ExPath, "", "",
1)
'End If
'MsgBox "ShellExecute failed, lret = " & lRet & ",
LastDllError = " & Err.LastDllError
Exit For
End If
Next i


21 Answers

Abhishek

8/24/2011 4:32:00 AM

0

something to do with admin rights UAC?


"Norm Fowler" <NormF4@Spoof.com> wrote in message
news:j312uh$7rr$1@dont-email.me...
| Hi,
|
| I had asked this question before and thought I had it solved. :-(, but


Norm

8/24/2011 5:18:00 AM

0

Abhishek presented the following explanation :
> something to do with admin rights UAC?
>
>
> "Norm Fowler" <NormF4@Spoof.com> wrote in message
> news:j312uh$7rr$1@dont-email.me...
>> Hi,
>>
>> I had asked this question before and thought I had it solved. :-(, but

No, I have that turned off and run the same on both the 32 bit and 64
bit version of Win7. I only have the problem on the 64 bit version. I
am assuming it has something to do with the (x86) program files.

Norm


Abhishek

8/24/2011 5:50:00 AM

0

> I know it must have something to do with the virtualization that
Windows does

Virtualization is only turned On for application only if UAC is also On, if
you turn off UAC then virtualization is disabled, it is for redirecting
application accessing files and registry to a new location like writing to
program files folder etc. I think its related to shell see this for example,
under 64-bit 32-bits application cannot make a context menu
http://www.gasanov.net/WOW...


"Norm Fowler" <NormF4@Spoof.com> wrote in message
news:j321io$ch8$1@dont-email.me...
| Abhishek presented the following explanation :
| > something to do with admin rights UAC?
| >
| >
| > "Norm Fowler" <NormF4@Spoof.com> wrote in message
| > news:j312uh$7rr$1@dont-email.me...
| >> Hi,
| >>
| >> I had asked this question before and thought I had it solved. :-(, but
|
| No, I have that turned off and run the same on both the 32 bit and 64
| bit version of Win7. I only have the problem on the 64 bit version. I
| am assuming it has something to do with the (x86) program files.
|
| Norm
|
|


(nobody)

8/24/2011 12:03:00 PM

0

"Norm Fowler" <NormF4@Spoof.com> wrote in message
news:j312uh$7rr$1@dont-email.me...
> Hi,
>
> I had asked this question before and thought I had it solved. :-(, but
> apparently not. I have a program that lists the desktop shortcuts and lets
> you click on them to run them. This program works fine in the 32 bit
> version of Win7 and earlier OS's, but does not work in Win7 64 bit. I know
> it must have something to do with the virtualization that Windows does,
> but have not been able to figure out what to do. If I make a desktop
> shortcut on the taskbar all the shortcuts work just fine, but through my
> program trying to run the .lnk does not work for any of the shortcuts. If
> I resolve the path to the executable and run it that way some of them
> work, but not all of them.

How are you getting the desktop folder and other system folders? My guess is
that you are using SHGetFolderPath() and similar functions, which can be
virtualized. You need to add a requestedExecutionLevel=asInvoker. From the
link below:

Virtualization is disabled for:

- 64 bit processes
- Non-interactive processes
- Processes that impersonate
- Kernel mode callers
- Executables that have a requestedExecutionLevel

http://msdn.microsoft.com/en-us/library/bb7...

> If I resolve the path to the executable and run it that way some of them
> work, but not all of them.

You need to call ExpandEnvironmentStrings() just in case the path include
things like %HOMEDRIVE%, and if you are getting values from the registry
that has the type REG_EXPAND_SZ.

> 'If Right$(ExPath, 4) = ".exe" Then 'Right$(ExPath,
> Len(ExPath) - (Len(ExPath) - 4)) = ".exe" Then
> 'Shell ExPath, vbNormalFocus
> 'Else
> 'lRet = ShellExecute(Me.hwnd, "Open", ExPath, "", "", 1)
> 'End If

I know that you have this code commented out, but just in case the shortcut
contain parameters, try using PathFindExtension(). Also use "Locate" in MSDN
Library to find other functions that manipulate or extract information from
a path.


Norm

8/24/2011 6:25:00 PM

0

Answers in line below:

Nobody wrote :
> "Norm Fowler" <NormF4@Spoof.com> wrote in message
> news:j312uh$7rr$1@dont-email.me...
>> Hi,
>>
>> I had asked this question before and thought I had it solved. :-(, but
>> apparently not. I have a program that lists the desktop shortcuts and lets
>> you click on them to run them. This program works fine in the 32 bit
>> version of Win7 and earlier OS's, but does not work in Win7 64 bit. I know
>> it must have something to do with the virtualization that Windows does, but
>> have not been able to figure out what to do. If I make a desktop shortcut
>> on the taskbar all the shortcuts work just fine, but through my program
>> trying to run the .lnk does not work for any of the shortcuts. If I resolve
>> the path to the executable and run it that way some of them work, but not
>> all of them.
>
> How are you getting the desktop folder and other system folders? My guess is
> that you are using SHGetFolderPath() and similar functions, which can be
> virtualized. You need to add a requestedExecutionLevel=asInvoker. From the
> link below:
>
> Virtualization is disabled for:
>
> - 64 bit processes
> - Non-interactive processes
> - Processes that impersonate
> - Kernel mode callers
> - Executables that have a requestedExecutionLevel
>
> http://msdn.microsoft.com/en-us/library/bb7...
>
Yes I am using SHGetFolderPath with the following Constants

Public Const FOLDERID_PublicDesktop =
"{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}"

Public Const FOLDERID_Desktop =
"{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}"

I also am using a manifest with the requestedExecutionLevel=asInvoker
and tried it with highest level available and also embedding the
manifest in the executable.

>> If I resolve the path to the executable and run it that way some of them
>> work, but not all of them.
>
> You need to call ExpandEnvironmentStrings() just in case the path include
> things like %HOMEDRIVE%, and if you are getting values from the registry that
> has the type REG_EXPAND_SZ.
>
>> 'If Right$(ExPath, 4) = ".exe" Then 'Right$(ExPath, Len(ExPath)
>> - (Len(ExPath) - 4)) = ".exe" Then
>> 'Shell ExPath, vbNormalFocus
>> 'Else
>> 'lRet = ShellExecute(Me.hwnd, "Open", ExPath, "", "", 1)
>> 'End If
>
> I know that you have this code commented out, but just in case the shortcut
> contain parameters, try using PathFindExtension(). Also use "Locate" in MSDN
> Library to find other functions that manipulate or extract information from a
> path.

This is what I am using to resolve the link, but will take a look at
ExpandEnvironmentStrings() just in case.


Function ResolveLink(LnkPathName As String) As String
Dim SH As New Shell
Dim f As Folder
Dim fi As FolderItem
Dim slo As ShellLinkObject

On Error Resume Next
Set f = SH.NameSpace(ssfDESKTOP)
Set fi = f.ParseName(LnkPathName)

If fi.IsLink Then
Set slo = fi.GetLink
ResolveLink = slo.Path
Else
ResolveLink = ""
End If

End Function

Norm


Norm

8/24/2011 6:37:00 PM

0

Further information that might be helpful, but I am at a loss to
explain. When I try to run the game Age of Empires by starting the exe
through me program I get an error message

Could not initialize graphics system. Make sure your video driver and
card are compatible with DirectDraw. Clicking directly on the shortcut
on the desktop I do not get this error and the program starts normally.

Norm


Karl E. Peterson

8/24/2011 10:32:00 PM

0

Norm Fowler explained on 8/24/2011 :
> Yes I am using SHGetFolderPath with the following Constants
>
> Public Const FOLDERID_PublicDesktop =
> "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}"
>
> Public Const FOLDERID_Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}"

What are those? (He says with mock horror!)

What about the CSIDL constants?

CSIDL_DESKTOP = &H0
CSIDL_DESKTOPDIRECTORY = &H10
CSIDL_COMMON_DESKTOPDIRECTORY = &H19

With those, and SHGetFolderPath I get:

?getfolder(CSIDL_COMMON_DESKTOPDIRECTORY)
C:\Users\Public\Desktop
?getfolder(CSIDL_DESKTOP)
C:\Users\Karl\Desktop
?getfolder(CSIDL_DESKTOPDIRECTORY)
C:\Users\Karl\Desktop

Well, actually, that's using my wrapper class, which you can snag at
http://vb.mvps.org/samples/...

> This is what I am using to resolve the link, but will take a look at
> ExpandEnvironmentStrings() just in case.
>
> Function ResolveLink(LnkPathName As String) As String
> Dim SH As New Shell
> Dim f As Folder
> Dim fi As FolderItem
> Dim slo As ShellLinkObject
>
> On Error Resume Next
> Set f = SH.NameSpace(ssfDESKTOP)
> Set fi = f.ParseName(LnkPathName)
>
> If fi.IsLink Then
> Set slo = fi.GetLink
> ResolveLink = slo.Path
> Else
> ResolveLink = ""
> End If
>
> End Function

Are you getting the results you expect from that? A few things that
might be missing from that approach are the start-up folder,
application parameters, windowstate, etc. Maybe this class would also
be helpful?

http://vb.mvps.org/samples/raw/CShellLi...

It requires the ShellLnk.tlb that shipped with VB5.

--
..NET: It's About Trust!
http://vfre...


Norm

8/24/2011 11:24:00 PM

0

Hi Karl, answers in line.

Karl E. Peterson brought next idea :
> Norm Fowler explained on 8/24/2011 :
>> Yes I am using SHGetFolderPath with the following Constants
>>
>> Public Const FOLDERID_PublicDesktop =
>> "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}"
>>
>> Public Const FOLDERID_Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}"
>
> What are those? (He says with mock horror!)
>
> What about the CSIDL constants?
>
> CSIDL_DESKTOP = &H0
> CSIDL_DESKTOPDIRECTORY = &H10
> CSIDL_COMMON_DESKTOPDIRECTORY = &H19
>
> With those, and SHGetFolderPath I get:
>
> ?getfolder(CSIDL_COMMON_DESKTOPDIRECTORY)
> C:\Users\Public\Desktop
> ?getfolder(CSIDL_DESKTOP)
> C:\Users\Karl\Desktop
> ?getfolder(CSIDL_DESKTOPDIRECTORY)
> C:\Users\Karl\Desktop
>
> Well, actually, that's using my wrapper class, which you can snag at
> http://vb.mvps.org/samples/...

Actually I was thinking those constants came from you :') But since I
have a lot of senior moments I don't really remember, they only work
for XP and above, however. I do get the same paths that you do with the
constants above.

>> This is what I am using to resolve the link, but will take a look at
>> ExpandEnvironmentStrings() just in case.
>>
>> Function ResolveLink(LnkPathName As String) As String
>> Dim SH As New Shell
>> Dim f As Folder
>> Dim fi As FolderItem
>> Dim slo As ShellLinkObject
>>
>> On Error Resume Next
>> Set f = SH.NameSpace(ssfDESKTOP)
>> Set fi = f.ParseName(LnkPathName)
>>
>> If fi.IsLink Then
>> Set slo = fi.GetLink
>> ResolveLink = slo.Path
>> Else
>> ResolveLink = ""
>> End If
>>
>> End Function
>
> Are you getting the results you expect from that? A few things that might be
> missing from that approach are the start-up folder, application parameters,
> windowstate, etc. Maybe this class would also be helpful?
>
> http://vb.mvps.org/samples/raw/CShellLi...
>
> It requires the ShellLnk.tlb that shipped with VB5.

All the paths I checked using that routine appeared to be the correct
path to the executable, but what was a surprise is that using the
obtained path and running it with ShellExecute all of the programs,
except one would run. This is what started this whole exercise in
frustration, trying to figure out why just that one program would not
run. One suggestion was to just shell the shortcut and let windows
figure it out, but when I do that it works great in 32 bit, but the
only shortcuts that will run on the 64 bit version are to the web and
one that opens a folder. I will take a look at your CShellLink.cls and
see if that makes any difference.

Norm


Karl E. Peterson

8/25/2011 12:26:00 AM

0

on 8/24/2011, Norm Fowler supposed :
> Hi Karl, answers in line.
>
> Karl E. Peterson brought next idea :
>> Norm Fowler explained on 8/24/2011 :
>>> Yes I am using SHGetFolderPath with the following Constants
>>>
>>> Public Const FOLDERID_PublicDesktop =
>>> "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}"
>>>
>>> Public Const FOLDERID_Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}"
>>
>> What are those? (He says with mock horror!)
>>
>> What about the CSIDL constants?
>>
>> CSIDL_DESKTOP = &H0
>> CSIDL_DESKTOPDIRECTORY = &H10
>> CSIDL_COMMON_DESKTOPDIRECTORY = &H19
>>
>> With those, and SHGetFolderPath I get:
>>
>> ?getfolder(CSIDL_COMMON_DESKTOPDIRECTORY)
>> C:\Users\Public\Desktop
>> ?getfolder(CSIDL_DESKTOP)
>> C:\Users\Karl\Desktop
>> ?getfolder(CSIDL_DESKTOPDIRECTORY)
>> C:\Users\Karl\Desktop
>>
>> Well, actually, that's using my wrapper class, which you can snag at
>> http://vb.mvps.org/samples/...
>
> Actually I was thinking those constants came from you :')

Oh lord, I hope not. <g>

> But since I have a
> lot of senior moments I don't really remember, they only work for XP and
> above, however. I do get the same paths that you do with the constants above.

Well, ya gotta admit, the CSIDL_* constants seem easier to maintain?
<g>

>>> This is what I am using to resolve the link, but will take a look at
>>> ExpandEnvironmentStrings() just in case.
>>>
>>> Function ResolveLink(LnkPathName As String) As String
>>> Dim SH As New Shell
>>> Dim f As Folder
>>> Dim fi As FolderItem
>>> Dim slo As ShellLinkObject
>>>
>>> On Error Resume Next
>>> Set f = SH.NameSpace(ssfDESKTOP)
>>> Set fi = f.ParseName(LnkPathName)
>>>
>>> If fi.IsLink Then
>>> Set slo = fi.GetLink
>>> ResolveLink = slo.Path
>>> Else
>>> ResolveLink = ""
>>> End If
>>>
>>> End Function
>>
>> Are you getting the results you expect from that? A few things that might
>> be missing from that approach are the start-up folder, application
>> parameters, windowstate, etc. Maybe this class would also be helpful?
>>
>> http://vb.mvps.org/samples/raw/CShellLi...
>>
>> It requires the ShellLnk.tlb that shipped with VB5.
>
> All the paths I checked using that routine appeared to be the correct path to
> the executable, but what was a surprise is that using the obtained path and
> running it with ShellExecute all of the programs, except one would run. This
> is what started this whole exercise in frustration, trying to figure out why
> just that one program would not run. One suggestion was to just shell the
> shortcut and let windows figure it out, but when I do that it works great in
> 32 bit, but the only shortcuts that will run on the 64 bit version are to the
> web and one that opens a folder. I will take a look at your CShellLink.cls
> and see if that makes any difference.

Seems you need to figure out what's unique about that one problem case.
Without knowing what it is... hard to say from here. Maybe it simply
expects a distinct start-up path, or something like that?

--
..NET: It's About Trust!
http://vfre...


Norm

8/25/2011 12:45:00 AM

0

Still playing with it and sometimes you try so many different things
you forget what did and did not work. ^^

Extracting the path to the executable and then using shell to run it
works fine. Using ShellExecute does not work with the same path for
that one program. I don't understand that one. :-? Of course shell will
not run the web shortcuts.

It just seems strange that in Win7 64 bit the same routine that works
to run the desktop shortcuts in Win 7 32 bit will not work. If I had
the 64 bit version of WinXP I would try it there and see if it worked.
There has to be something strange going on with the path in the 64 bit
version.

Norm