我做了一个C程序来改变Chrome快捷方式的目标属性,以加载它与我所做的扩展。代码工作,如果我使用char newTargetPath[200] = ""C:\Program Files\Google\Chrome\Application\chrome.exe"";
它不工作,如果我使用char newTargetPath[200] = ""C:\Program Files\Google\Chrome\Application\chrome.exe" --load-extension=C:\path\to\extension";
我怎么能成功地执行这个代码与--load-extension
标志?这是我的代码:
#include <Windows.h>
#include <ShObjIdl.h>
#include <ShlGuid.h>
#include <ObjBase.h>
#include <combaseapi.h>
#include <stdio.h>
int main()
{
HRESULT hr;
CoInitialize(NULL);
// Replace with the path of your shortcut file
char shortcutPath[200] = "C:\Users\name\Desktop\chrome.lnk";
// Replace with the path of the new target file
char newTargetPath[200] = ""C:\Program Files\Google\Chrome\Application\chrome.exe" --load-extension=C:\path\to\extension";
// Create an instance of the IShellLink interface
IShellLink* shellLink;
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&shellLink);
if (SUCCEEDED(hr))
{
// Create an instance of the IPersistFile interface
IPersistFile* persistFile;
hr = shellLink->QueryInterface(IID_IPersistFile, (void**)&persistFile);
if (SUCCEEDED(hr))
{
// Convert the shortcut path to Unicode
wchar_t shortcutPathW[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, shortcutPath, -1, shortcutPathW, MAX_PATH);
// Load the existing shortcut file
hr = persistFile->Load(shortcutPathW, STGM_READ);
if (SUCCEEDED(hr))
{
// Set the new target file path
wchar_t newTargetPathW[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, newTargetPath, -1, newTargetPathW, MAX_PATH);
hr = shellLink->SetPath(newTargetPathW);
if (SUCCEEDED(hr))
{
// Save the modified shortcut file
hr = persistFile->Save(shortcutPathW, TRUE);
if (SUCCEEDED(hr))
{
printf("Shortcut target modified successfully.n");
}
else
{
printf("Error saving modified shortcut file. HRESULT: 0x%xn", hr);
}
}
else
{
printf("Error setting shortcut target. HRESULT: 0x%xn", hr);
}
}
else
{
printf("Error loading shortcut file. HRESULT: 0x%xn", hr);
}
persistFile->Release();
}
else
{
printf("Error querying IPersistFile interface. HRESULT: 0x%xn", hr);
}
shellLink->Release();
}
else
{
printf("Error creating IShellLink instance. HRESULT: 0x%xn", hr);
}
CoUninitialize();
return 0;
}
不能在SetPath
中使用程序参数。路径就是路径,不是命令。使用SetArguments
方法设置程序参数