Pin shortcut (.lnk) to start menu
I'm currently making an installation script by using a .cmd file. Here is my code:
IF EXIST "%USERPROFILE%\Desktop\Opslag\Opslag.hta" ( START "" "%USERPROFILE%\Desktop\Opslag\Opslag.lnk" /secondary /minimized MSG "%USERNAME%" The program is already installed. EXIT ) ELSE ( XCOPY %SOURCE% %DESTINATION% /D /E /C /R /I /K /Y START "" "%USERPROFILE%\Desktop\Opslag\Opslag.lnk" /secondary /minimized MSG "%USERNAME%" Setup is complete! EXIT )
The %SOURCE% and %DESTINATION% are set earlier in the script.
When the folder has been copied I want the file %USERPROFILE%\Desktop\Opslag\Opslag.lnk to be added to the Start Menu.
I have seen earlier posts like: How to pin to start menu using PowerShell, but I cannot make it work.
I'm currently testing it on my home laptop which runs Windows 7 with danish language. The machine where I need to do this runs Windows 7 with english language. Therefore I think the $verb is different from the scripts I've found, but I haven't tested on my work station.
Furthermore my work station has a very limited UAC, and therefore I do not have Administrator rights. And please do not comment on how this should not be done by users, but only Administrators/IT, as I know what I'm doing.
I hope someone can help me pin the Opslag.lnk to the Start Menu, preferably on both languages (danish and english).
Find the location of the Start Menu folder:
For /f "tokens=3*" %%G in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Start Menu" ^|Find "REG_"') do Call Set _startmenu=%%H echo %_startmenu% pause
In another search I stumbled across a very usefull VBScript: http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx:
Const CSIDL_COMMON_PROGRAMS = &H17 Const CSIDL_PROGRAMS = &H2 Set objShell = CreateObject("Shell.Application") Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS) strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories") Set objFolderItem = objFolder.ParseName("Calculator.lnk") Set colVerbs = objFolderItem.Verbs For Each objVerb in colVerbs Wscript.Echo objVerb Next
The script lists alle the verbs for the specifik program, in this case the Calculator. Unfortunately the verb "Pin to Start Menu" in my Opslag.lnk is not listed, and therefore I do not think this can be done with verbs. Hope some one else has other ideas.
I used a .vbs to do this in the current profile (and used the registry, runonce to launch the .vbs on all (new)userprofiles). We are working with both Dutch and English devices in our company so you will see that it will try both languages. The problem is that it did not work on a .lnk but you can always create an exe referring to your desired destination.
Dim strFolder, strExecutable Set objShell = CreateObject("Shell.Application") strFolder = "C:\Tools" strExecutable = "Tool.exe" Set objFolder = objShell.Namespace(strFolder) Set objFolderItem = objFolder.ParseName(strExecutable) Set colVerbs = objFolderItem.Verbs 'Loop through the verbs and if PIN is found then 'DoIt' (execute) blnOptionFound = False For Each objVerb In colVerbs If Replace(objVerb.name, "&", "") = "Aan het menu Start vastmaken" Then objVerb.DoIt blnOptionFound = True End If Next For Each objVerb In colVerbs If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt blnOptionFound = True End If Next