Bri*_*ost 8 scripting installer inno-setup startmenu windows-7
我正在使用优秀的Inno安装程序安装程序,我注意到一些应用程序(通常来自Microsoft)已安装,其启动图标已在开始菜单(在Windows 7中)高度可见('固定?').我完全依赖于最近使用的算法,我的图标在开始菜单中是"大",或者有没有办法从安装程序推广我的应用程序?
可以固定程序,但不能正式.根据发布的代码this thread(使用与@Mark Redman链接的文章中描述的相同方式),我写了以下内容:
[Code]
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
const
// these constants are not defined in Windows
SHELL32_STRING_ID_PIN_TO_TASKBAR = 5386;
SHELL32_STRING_ID_PIN_TO_STARTMENU = 5381;
SHELL32_STRING_ID_UNPIN_FROM_TASKBAR = 5387;
SHELL32_STRING_ID_UNPIN_FROM_STARTMENU = 5382;
type
HINSTANCE = THandle;
HMODULE = HINSTANCE;
TPinDest = (
pdTaskbar,
pdStartMenu
);
function LoadLibrary(lpFileName: string): HMODULE;
external 'LoadLibrary{#AW}@kernel32.dll stdcall';
function FreeLibrary(hModule: HMODULE): BOOL;
external 'FreeLibrary@kernel32.dll stdcall';
function LoadString(hInstance: HINSTANCE; uID: UINT;
lpBuffer: string; nBufferMax: Integer): Integer;
external 'LoadString{#AW}@user32.dll stdcall';
function TryGetVerbName(ID: UINT; out VerbName: string): Boolean;
var
Buffer: string;
BufLen: Integer;
Handle: HMODULE;
begin
Result := False;
Handle := LoadLibrary(ExpandConstant('{sys}\Shell32.dll'));
if Handle <> 0 then
try
SetLength(Buffer, 255);
BufLen := LoadString(Handle, ID, Buffer, Length(Buffer));
if BufLen <> 0 then
begin
Result := True;
VerbName := Copy(Buffer, 1, BufLen);
end;
finally
FreeLibrary(Handle);
end;
end;
function ExecVerb(const FileName, VerbName: string): Boolean;
var
I: Integer;
Shell: Variant;
Folder: Variant;
FolderItem: Variant;
begin
Result := False;
Shell := CreateOleObject('Shell.Application');
Folder := Shell.NameSpace(ExtractFilePath(FileName));
FolderItem := Folder.ParseName(ExtractFileName(FileName));
for I := 1 to FolderItem.Verbs.Count do
begin
if FolderItem.Verbs.Item(I).Name = VerbName then
begin
FolderItem.Verbs.Item(I).DoIt;
Result := True;
Exit;
end;
end;
end;
function PinAppTo(const FileName: string; PinDest: TPinDest): Boolean;
var
ResStrID: UINT;
VerbName: string;
begin
case PinDest of
pdTaskbar: ResStrID := SHELL32_STRING_ID_PIN_TO_TASKBAR;
pdStartMenu: ResStrID := SHELL32_STRING_ID_PIN_TO_STARTMENU;
end;
Result := TryGetVerbName(ResStrID, VerbName) and ExecVerb(FileName, VerbName);
end;
function UnpinAppFrom(const FileName: string; PinDest: TPinDest): Boolean;
var
ResStrID: UINT;
VerbName: string;
begin
case PinDest of
pdTaskbar: ResStrID := SHELL32_STRING_ID_UNPIN_FROM_TASKBAR;
pdStartMenu: ResStrID := SHELL32_STRING_ID_UNPIN_FROM_STARTMENU;
end;
Result := TryGetVerbName(ResStrID, VerbName) and ExecVerb(FileName, VerbName);
end;
Run Code Online (Sandbox Code Playgroud)
上面的代码首先读取菜单项的标题,用于从Shell32.dll库的字符串表中固定或取消固定应用程序.然后连接到Windows Shell和目标应用程序.path创建Folder对象,然后获取FolderItem对象,并在此对象上迭代所有可用的动词,并检查它们的名称是否与从Shell32.dll库字符串表中读取的名称匹配.如果是这样,它通过调用DoIt方法调用动词项操作并退出迭代.
以下是上述代码的可能用法,用于固定:
if PinAppTo(ExpandConstant('{sys}\calc.exe'), pdTaskbar) then
MsgBox('Calc has been pinned to the taskbar.', mbInformation, MB_OK);
if PinAppTo(ExpandConstant('{sys}\calc.exe'), pdStartMenu) then
MsgBox('Calc has been pinned to the start menu.', mbInformation, MB_OK);
Run Code Online (Sandbox Code Playgroud)
并取消固定:
if UnpinAppFrom(ExpandConstant('{sys}\calc.exe'), pdTaskbar) then
MsgBox('Calc is not pinned to the taskbar anymore.', mbInformation, MB_OK);
if UnpinAppFrom(ExpandConstant('{sys}\calc.exe'), pdStartMenu) then
MsgBox('Calc is not pinned to the start menu anymore.', mbInformation, MB_OK);
Run Code Online (Sandbox Code Playgroud)
请注意,即使此代码适用于Windows 7(以及任务栏也在我测试过的Windows 8.1上固定),它实际上很简陋,因为没有正式的方法以编程方式将程序固定到任务栏,也无法启动菜单.这就是用户应该根据自己的选择做的事情.
有一个原因是没有编程方式将任务固定到任务栏/开始菜单.根据我的经验,我看到开始菜单突出显示了新创建的快捷方式,而这些快捷方式旨在处理这种情况.当您看到开始菜单上显示新安装的程序时,可能是因为该算法,而不是因为安装程序将其放在那里.
这就是说,如果一个新的快捷方式并没有突出显示,这可能是因为安装程序提取预先存在的快捷方式,并在其上保留一个老时间戳,而不是使用API函数来创建在开始菜单的快捷方式.
| 归档时间: |
|
| 查看次数: |
5010 次 |
| 最近记录: |