2

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).

Community
  • 1
  • 1
Sparcx
  • 69
  • 12
  • Take a look at this ==> http://stackoverflow.com/questions/30920546/remove-the-google-chrome-pinned-icon-on-the-taskbar/30927312#30927312 – Hackoo Jul 05 '15 at 16:46

3 Answers3

0

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
Bk_
  • 99
  • 9
  • I cannot simply drop the `Opslag.lnk` file to the Start Menu folder to make it appear in the Start Menu. I can make it appear in "All Programs" under the Start Menu, by dropping the `Opslag.lnk` file to this folder: `C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs` – Sparcx Jul 05 '15 at 18:15
0

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.

Sparcx
  • 69
  • 12
0

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
Johan A.
  • 378
  • 3
  • 7