【发布时间】:2021-07-10 23:04:22
【问题描述】:
我正在关注这个msdn 文档。我想创建一个具有两个属性AppUserModelId 和ToastActivatorCLSID 的快捷方式。如何使用 powershell 实现这一点。
基本上我想通过powershell脚本转换以下代码并创建快捷方式。
_Use_decl_annotations_
HRESULT DesktopToastsApp::InstallShortcut(PCWSTR shortcutPath, PCWSTR exePath)
{
ComPtr<IShellLink> shellLink;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
if (SUCCEEDED(hr))
{
hr = shellLink->SetPath(exePath);
if (SUCCEEDED(hr))
{
ComPtr<IPropertyStore> propertyStore;
hr = shellLink.As(&propertyStore);
if (SUCCEEDED(hr))
{
PROPVARIANT propVar;
propVar.vt = VT_LPWSTR;
propVar.pwszVal = const_cast<PWSTR>(AppId); // for _In_ scenarios, we don't need a copy
hr = propertyStore->SetValue(PKEY_AppUserModel_ID, propVar);
if (SUCCEEDED(hr))
{
propVar.vt = VT_CLSID;
propVar.puuid = const_cast<CLSID*>(&__uuidof(NotificationActivator));
hr = propertyStore->SetValue(PKEY_AppUserModel_ToastActivatorCLSID, propVar);
if (SUCCEEDED(hr))
{
hr = propertyStore->Commit();
if (SUCCEEDED(hr))
{
ComPtr<IPersistFile> persistFile;
hr = shellLink.As(&persistFile);
if (SUCCEEDED(hr))
{
hr = persistFile->Save(shortcutPath, TRUE);
}
}
}
}
}
}
}
return hr;
}
我写了一个简单的脚本来创建一个快捷方式,但不知道如何标记上述两个道具
function set-shortcut {
param ( [string]$SourceLnk, [string]$DestinationPath )
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($SourceLnk)
$Shortcut.TargetPath = $DestinationPath
$Shortcut.Save()
}
【问题讨论】:
标签: windows powershell powershell-4.0