CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Apr 2007
Posts
4

Is there a way to add a short cut to the "Pinned" area of the Start Menu in XP through VB?

2. ## Re: Pin to Start Menu

You can script it.

Code:
Set objShell = CreateObject("Shell.Application")
Set theFolder = objShell.Namespace("C:\path\to\application")
Set theApplication = theFolder.ParseName("application_name.exe")
theApplication.InvokeVerb("P&in to Start Menu")
EDIT: Or if you want, you can edit the binary string named Favorites in the registry.

Code:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage
Last edited by PeejAvery; April 13th, 2007 at 05:13 PM.

3. ## Re: Pin to Start Menu

EDIT: Or if you want, you can edit the binary string named Favorites in the registry.
I would avoid direct edits of the registry for a number of reasons. Not the least are:

1) Registry formats are subject to change without notice
2) Edits such as the one shown do not properly maintain ACL's (which is why you should use regedt32.exe rather than regedit on most operating systems where there is a choice)

4. Junior Member
Join Date
Apr 2007
Posts
4

## Re: Pin to Start Menu

Thats brilliant!

Is there a way to rename the title once it's pinnned as it just comes up the EXE name on the start menu.

5. ## Re: Pin to Start Menu

To my knowledge...not without editing the registry. You can create a shortcut placed in the same folder as the executable. And then pin that shortcut to the desktop.

6. Junior Member
Join Date
Apr 2007
Posts
4

## Re: Pin to Start Menu

ok thats cool, what about pinning a link to a html page... cant seem to get it to work...

7. ## Re: Pin to Start Menu

I might be mistaken, but I think only executables can be pinned to the start menu.

8. Junior Member
Join Date
Apr 2007
Posts
4

## Re: Pin to Start Menu

Originally Posted by PeejAvery
I might be mistaken, but I think only executables can be pinned to the start menu.
hmm I guess for the purpose, I could always make a small EXE that executes the html page externally then closes...

9. ## Re: Pin to Start Menu

Well, first try creating a shortcut to a webpage and then drag it to the pin area. If it lets you, then we can probably find a solution.

10. ## Re: Pin to Start Menu

The script posted in this thread doesn't seem to work on Vista.

This script works on both XP and Vista.
A reference to
"Windows script host object model"

Code:
    Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Declare Function apiGetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long

Dim pinned As Boolean
If pinned = True Then
MsgBox "Pinned to the start menu"
Else
MsgBox "Not pinned to the start menu"
End If
End Sub

End Sub

Private Function PinToStartMenu(ByVal fName As String, Optional ByVal pMenu As Boolean = True) As Boolean
On Error Resume Next
Call CreateShortCut(App.Path & "\" & App.EXEName & ".exe", App.Path, App.EXEName)
End Function

Private Function CreateShortCut(ByVal filePathOrigin As String, ByVal folderPathDestination As String, ByRef linkName As String) As Boolean
On Error Resume Next
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
CreateShortCut = True
End Function

Private Function DoVerb(ByVal fName As String, ByVal sVerb As String) As Boolean
On Error Resume Next
Dim objShell As Object
Dim objFolder As Object
Dim objFolderItem As Object
Dim objVerb As Object
Dim objVerbs As Object
Dim osv As String
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(CurDir)
If objFolder Is Nothing Then GoTo Release
Set objFolderItem = objFolder.ParseName(fName & ".lnk")
If objFolderItem Is Nothing Then GoTo Release
osv = GetOSVersion
If osv = "5.0" Or osv = "5.1" Then
objFolderItem.InvokeVerb (sVerb)
DoVerb = True 'Did it, or at least tried to do it
ElseIf Mid(osv, 1, 1) = "6" Or Mid(osv, 1, 1) = "7" Then
Set objVerbs = objFolderItem.verbs
For Each objVerb In objVerbs
If objVerb.Name = sVerb Then
objVerb.DoIt
DoVerb = True 'Did it, or at least tried to do it
End If
Next
End If
Release:
objShell = Nothing: objFolder = Nothing: objFolderItem = Nothing: objFolderItemVerb = Nothing: objFolderItemVerbs = Nothing
End Function

Private Function GetOSVersion() As String
On Error Resume Next
Dim OSInfo As OSVERSIONINFO
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
Call apiGetVersionEx(OSInfo)
GetOSVersion = CStr(OSInfo.dwMajorVersion) & "." & LTrim(CStr(OSInfo.dwMinorVersion))
GetOSVersion = Trim(GetOSVersion)
End Function
You should not always pin executables directly to the start menu, because not all of them will load correctly for some unknown reason.
The solution is to make a shortcut to the executable, and then pin that file(.lnk) to the start menu.
You may want to hide the shortcuts somewhere though, in the case the user deletes the shortcut.
Last edited by TT(n); December 9th, 2008 at 04:38 PM. Reason: Solution

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.30793318152427673, "perplexity": 19723.40178153094}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2013-48/segments/1386163046801/warc/CC-MAIN-20131204131726-00034-ip-10-33-133-15.ec2.internal.warc.gz"}