首页 > 解决方案 > Delphi 中的 Windows 10“固定启动”

问题描述

我正在尝试编写一个 delphi 应用程序,该应用程序自动将应用程序固定到开始菜单,因此它们在平板电脑模式下很容易看到。

我做了一些研究,发现的只是一个有效的 VBScript(见下面的代码)。

所以我尝试使用 Shell Execute 在我的 delphi 应用程序中打开 VBScript

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

但是,如果我尝试使用 shell 运行脚本执行,则没有“Pin to start”动词。否则,如果我直接从资源管理器中打开它,它就可以工作。

直接从 windows 资源管理器运行文件或从 delphi 运行文件与 shell 执行有什么区别?

或者您知道如何尝试仅使用 delphi 固定应用程序吗?

VB脚本:

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

标签: windowsshelldelphiexecute

解决方案


有一个用于固定开始菜单项的特殊文件夹,您只需在其中放置程序的快捷方式

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

所以不需要为此使用复杂的 scipts


推荐阅读