Winapi Windows 7-任务栏-锁定或取消锁定程序链接

Winapi Windows 7-任务栏-锁定或取消锁定程序链接,winapi,windows-7,Winapi,Windows 7,如标题所示,是否有任何Win32 API可以执行此操作?此文件夹包含固定应用程序的快捷方式 C:\Users\Your User Name\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User pinted\TaskBar不要这样做 我99%确定没有官方的API,原因与没有完全相同 简而言之,大多数用户不希望程序将垃圾放入他们的收藏夹、快速启动、任务栏等中。因此Windows不支持您这样做。我发现没有官方API可以做到这一点,

如标题所示,是否有任何Win32 API可以执行此操作?

此文件夹包含固定应用程序的快捷方式

C:\Users\Your User Name\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User pinted\TaskBar

不要这样做

我99%确定没有官方的API,原因与没有完全相同


简而言之,大多数用户不希望程序将垃圾放入他们的收藏夹、快速启动、任务栏等中。因此Windows不支持您这样做。

我发现没有官方API可以做到这一点,但有人通过VBScript做到了这一点。 谢谢。

在a的评论中说,您只需在文件夹“C:\Users\Username\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User pinted\TaskBar”中创建一个符号链接即可


但是,正如这里的其他评论所指出的那样,这通常是不合群的做法。

您可以通过Windows Shell动词锁定/取消锁定应用程序:

对于API,有一个脚本友好的COM库用于使用Shell:

下面是一个用JScript编写的示例:

// Warning: untested and probably needs correction
var appFolder = "FOLDER CONTAINING THE APP/SHORTCUT";
var appToPin = "FILENAME OF APP/SHORTCUT";
var shell = new ActiveXObject("Shell.Application");
var folder = shell.NameSpace(appFolder);
var folderItem = folder.ParseName(appToPin);
var itemVerbs = folderItem.Verbs;
for(var i = 0; i < itemVerbs.Count; i++)
{
    // You have to find the verb by name,
    //  so if you want to support multiple cultures,
    //  you have to match against the verb text for each culture.
    if(itemVerbs[i].name.Replace(/&/, "") == "Pin to Start Menu")
    {
        itemVerbs[i].DoIt();
    }
}
//警告:未测试,可能需要更正
var appFolder=“包含应用程序/快捷方式的文件夹”;
var appToPin=“应用程序/快捷方式的文件名”;
var shell=新的ActiveXObject(“shell.Application”);
var folder=shell.NameSpace(appFolder);
var folderItem=folder.ParseName(appToPin);
var itemVerbs=folderItem.Verbs;
for(var i=0;i
只需在信息上添加一些链接,因为microsoft现在在“”上提供了官方文档:

固定了一小部分应用程序 默认情况下,用于新安装。 除此之外,只有用户可以 针进一步应用编程 应用程序的钉住不正确 允许。

所以凯文·蒙特罗斯的答案是正确的:不要这样做。

我正在尝试实现一个插件,允许我将不同的按钮固定到不同的虚拟桌面上。完全有理由使用这个

已找到固定/取消固定的方法:

下面的代码片段取自,几乎没有变化,另请参见

bool TaskbarPinShortcutLink(常量wchar\u t*快捷方式){
int result=reinterpret_cast(ShellExecute(NULL,L“taskbarpin”),快捷方式,
空,空,0);
返回结果>32;
}
bool TaskbarUnpinShortcutLink(常量wchar\u t*快捷方式){
int result=reinterpret_cast(shell执行(NULL,L“taskbarunpin”),
快捷方式,NULL,NULL,0);
返回结果>32;
}    
//版权所有(c)2012 Chromium作者。版权所有。
//此源代码的使用受BSD样式许可证的约束,该许可证可以
//在许可证文件中找到。

如果你知道捷径的话,看起来很简单。对我来说,虽然这还不够,但我还需要迭代现有按钮,并在不同的桌面上取消绑定和重新绑定它们。

它可以工作,但并非适用于所有操作系统,例如Windows 10:

    [DllImport("kernel32.dll")]
    private static extern IntPtr LoadLibrary(string dllName);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);

    private static void PinUnpinTaskBar(string filePath, bool pin)
    {
        if (!File.Exists(filePath))
            throw new FileNotFoundException(filePath + " not exists!");

        int MAX_PATH = 255;
        var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
        StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
        IntPtr hShell32 = LoadLibrary("Shell32.dll");
        LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
        string localizedVerb = szPinToStartLocalized.ToString();

        // create the shell application object
        dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));

        string path = Path.GetDirectoryName(filePath);
        string fileName = Path.GetFileName(filePath);

        dynamic directory = shellApplication.NameSpace(path);
        dynamic link = directory.ParseName(fileName);

        dynamic verbs = link.Verbs();
        for (int i = 0; i < verbs.Count(); i++)
        {
            dynamic verb = verbs.Item(i);

            if ((pin && verb.Name.Equals(localizedVerb)) || (!pin && verb.Name.Contains(localizedVerb)))
            {
                verb.DoIt();
                break;
            }
        }
    }
[DllImport(“kernel32.dll”)]
私有静态外部IntPtr加载库(字符串dllName);
[DllImport(“user32.dll”,CharSet=CharSet.Auto)]
静态外部int LoadString(IntPtr hInstance、uint uID、StringBuilder lpBuffer、int nBufferMax);
私有静态void PinUnpinTaskBar(字符串文件路径,bool pin)
{
如果(!File.Exists(filePath))
抛出新的FileNotFoundException(filePath+“不存在!”);
int MAX_PATH=255;
var actionIndex=pin?5386:5387;//5386是“pin to Tas&kbar”的DLL索引,参考。http://www.win7dll.info/shell32_dll.html
StringBuilder szPinToStartLocalized=新StringBuilder(最大路径);
IntPtr hShell32=LoadLibrary(“Shell32.dll”);
加载字符串(hShell32,(uint)actionIndex,szPinToStartLocalized,MAX_路径);
字符串localizedVerb=szPinToStartLocalized.ToString();
//创建shell应用程序对象
dynamic shellApplication=Activator.CreateInstance(Type.GetTypeFromProgID(“Shell.Application”));
string path=path.GetDirectoryName(filePath);
字符串fileName=Path.GetFileName(filePath);
动态目录=shellApplication.NameSpace(路径);
动态链接=directory.ParseName(文件名);
动态动词=link.verbs();
for(int i=0;i
钉住或取消钉住不意味着由用户完成吗?为什么程序要为他们这么做?我的客户需要我们的安装程序在默认情况下在任务栏上锁定/取消锁定应用程序。谢谢。我相信这个功能,就像XP/Vista中的Pin-to-Start菜单一样,是故意不公开的,这样程序就不能覆盖用户关于程序是否值得宝贵的任务栏空间的决定。否则,每一个垃圾邮件程序都会认为自己是如此重要,以至于不管用户同意,它都会把它自己钉在任务栏上。看到许多雷蒙德·陈的文章,吴一刚:你的客户是政府吗?如果不知道,那么我希望他们有一个很好的理由来推翻用户的偏好。通常情况下,人们在这里回答他们认为不知道的问题(如itowlson),然后其他不知道的人也会投票支持这个错误的评论。Ciantic在下面给出了正确答案。“用户的决定……”这是胡说八道。如果我编写了一个安装程序,询问我的用户是否需要任务栏中的快捷方式,则用户决定我的安装程序将链接写入任务栏。为什么我们要这么做
    [DllImport("kernel32.dll")]
    private static extern IntPtr LoadLibrary(string dllName);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);

    private static void PinUnpinTaskBar(string filePath, bool pin)
    {
        if (!File.Exists(filePath))
            throw new FileNotFoundException(filePath + " not exists!");

        int MAX_PATH = 255;
        var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
        StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
        IntPtr hShell32 = LoadLibrary("Shell32.dll");
        LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
        string localizedVerb = szPinToStartLocalized.ToString();

        // create the shell application object
        dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));

        string path = Path.GetDirectoryName(filePath);
        string fileName = Path.GetFileName(filePath);

        dynamic directory = shellApplication.NameSpace(path);
        dynamic link = directory.ParseName(fileName);

        dynamic verbs = link.Verbs();
        for (int i = 0; i < verbs.Count(); i++)
        {
            dynamic verb = verbs.Item(i);

            if ((pin && verb.Name.Equals(localizedVerb)) || (!pin && verb.Name.Contains(localizedVerb)))
            {
                verb.DoIt();
                break;
            }
        }
    }