0

i am trying to write a delphi application that automatically pins apps to the start menu, so they are easily visible in tablet mode.

I did some research and all i found was a VBScript that worked (see the code below).

So i tried to open the VBScript in my delphi application with Shell Execute

ShellExecute(Handle, 'open', Pchar('C:\tmp\VBScript.vbs'), 'C:\WINDOWS\system32\ notepad.exe', nil, SW_NORMAL);

But if i try to run the script with shell execute there is no "Pin to start" verb. Otherwise it works if i open it directly from the explorer.

Whats the difference between running the file directly from the windows explorer or from delphi with shell execute?

Or do you have an idea how i could try to pin apps only with delphi?

VBScript:

Dim Argumente
Dim File, objFSO
Dim strFolder, strExecutable

Set objShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
arg0 = wscript.arguments.unnamed.item("0")
arg1 = wscript.arguments.unnamed.item("1")

File = arg0&arg1

If (objFSO.FileExists(File )) Then 
Else
WScript.Echo "File " & File & " gibt es nicht. Script fehlgeschlagen"
WScript.Quit(2)
End If

strFolder = arg0
strExecutable = arg1

WScript.Echo "Folder:" & strFolder & ""
WScript.Echo "File:" & strExecutable & ""

Set objFolder = objShell.Namespace(strFolder)
Set objFolderItem = objFolder.ParseName(strExecutable)

Set colVerbs = objFolderItem.Verbs

'uncomment this section to display the available verbs
 For Each objVerb In colVerbs
    If objVerb <> "" Then
       WScript.Echo objVerb
    End If
 Next

'Loop through the verbs and if PIN is found then 'DoIt' (execute)
blnOptionFound = False
For Each objVerb In colVerbs
   If Replace(objVerb.name, "&", "") = "Pin to Start" Then
      objVerb.DoIt
      blnOptionFound = True
      WScript.Echo "The application '" & strExecutable & "' was just Pinned to the Start Menu."
      WScript.Quit(0)   
End If
Next

if blnOptionFound = false then
   WScript.Echo "The application '" & strExecutable & "' was already pinned to the Start Menu."
   WScript.Quit(1)   
end if
  • The script is basically the equivalent of querying a file's `IContextMenu` interface, retrieving its popup menu, looping through it, and invoking a specific item – Remy Lebeau Feb 20 '19 at 15:51
  • yes, but why are there different items when i try to run the script with shellexecute in my delphi application? – Shiinix Feb 20 '19 at 15:58
  • Different execution environments, different contexts, different options available. Also, because your script has an error in it - `If (objFSO.FileExists(File )) Then` should be `If not objFSO.FileExists(File) Then` – Remy Lebeau Feb 20 '19 at 17:21
  • If your program is so great then the user might choose to pin it. But isn't it the user's choice. I'd hate a program that took this decision for me. – David Heffernan Feb 21 '19 at 06:30
  • @DavidHeffernan it is for work, so it isn't the user's choice to install it...And it isn't that easy for the average users to navigate to C:\programfiles\.... in tablet mode to pin it. – Shiinix Feb 21 '19 at 07:37
  • A normal install program will add it to the list of programs on the start menu, so the user should be able to get to it easily and pin from there. If it is an in-house compile with no install, maybe your question needs to be how to add it to the program list. – Dsm Feb 21 '19 at 09:58
  • i was able to solve my problem. I am using a 32bit application on a 64bit windows and so there was no "pin to start" verb in the 32bit application. After compiling a 64bit application it worked! – Shiinix Feb 21 '19 at 10:53

1 Answers1

1

There is a special folder for pinned start menu items into which you just place a shortcut to your program

https://superuser.com/a/171129/442240

So no need to use complex scipts for this

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
  • Hello SilverWarrior, thanks for you answer, but there are no shortcuts in this folder in Win10 1709 – Shiinix Feb 20 '19 at 15:58
  • 3
    See the various comments in that post. Microsoft changed things in Windows 10. Microsoft doesn't want people pinning things programmably, pinning is supposed to be a user-only operation. – Remy Lebeau Feb 20 '19 at 17:22