IUrlHistoryStg2::ClearHistory()无法从服务中工作?

IUrlHistoryStg2::ClearHistory()无法从服务中工作?,url,com,browser-history,Url,Com,Browser History,IUrlHistoryStg2::ClearHistory()方法按用户记录 当从系统帐户下运行的服务调用它时,我无法针对特定的登录用户。我已通过WindowsIdentity.Impersonate()成功模拟了用户,但对ClearHistory()的调用始终返回0表示成功,但未清除用户的历史记录 这适用于XP和Win7,因此似乎不是会话隔离问题 可能是因为它是COM,所以在模拟时,某些东西正在查看调用者的进程令牌,而不是其线程令牌 我很困惑为什么模仿用户并不能简单地导致这种方法的成功 us

IUrlHistoryStg2::ClearHistory()方法按用户记录

当从系统帐户下运行的服务调用它时,我无法针对特定的登录用户。我已通过WindowsIdentity.Impersonate()成功模拟了用户,但对ClearHistory()的调用始终返回0表示成功,但未清除用户的历史记录

这适用于XP和Win7,因此似乎不是会话隔离问题

可能是因为它是COM,所以在模拟时,某些东西正在查看调用者的进程令牌,而不是其线程令牌

我很困惑为什么模仿用户并不能简单地导致这种方法的成功

using System;
using System.Runtime.InteropServices;

/**
* wrapper for IUrlHistory
*/
public struct STATURL
{
    public static uint SIZEOF_STATURL = (uint)Marshal.SizeOf( typeof(STATURL) );
    public uint cbSize;
    [MarshalAs(UnmanagedType.LPWStr)] public string pwcsUrl;
    [MarshalAs(UnmanagedType.LPWStr)] public string pwcsTitle;
    public System.Runtime.InteropServices.ComTypes.FILETIME
                ftLastVisited,
                ftLastUpdated,
                ftExpires;
    public uint dwFlags;
}

[ComImport, Guid("3C374A42-BAE4-11CF-BF7D-00AA006946EE"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEnumSTATURL
{
    [PreserveSig]
    uint Next(uint celt, out STATURL rgelt, out uint pceltFetched);
    void Skip(uint celt);
    void Reset();
    void Clone(out IEnumSTATURL ppenum);
    void SetFilter(
        [MarshalAs(UnmanagedType.LPWStr)] string poszFilter,
        uint dwFlags);
}

[ComImport, Guid("AFA0DC11-C313-11d0-831A-00C04FD5AE38"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IUrlHistoryStg2
{
    #region IUrlHistoryStg methods
    void AddUrl(
        [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
        [MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,
        uint dwFlags);

    void DeleteUrl(
        [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
        uint dwFlags);

    void QueryUrl(
        [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
        uint dwFlags,
        ref STATURL lpSTATURL);

    void BindToObject(
        [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
        ref Guid riid,
        [MarshalAs(UnmanagedType.IUnknown)] out object ppvOut);

    IEnumSTATURL EnumUrls();

    #endregion

    void AddUrlAndNotify(
        [MarshalAs(UnmanagedType.LPWStr)] string pocsUrl,
        [MarshalAs(UnmanagedType.LPWStr)] string pocsTitle,
        uint dwFlags,
        [MarshalAs(UnmanagedType.Bool)] bool fWriteHistory,
        [MarshalAs(UnmanagedType.IUnknown)] object /*IOleCommandTarget*/
        poctNotify,
        [MarshalAs(UnmanagedType.IUnknown)] object punkISFolder);

    void ClearHistory();
}

[ComImport, Guid("3C374A40-BAE4-11CF-BF7D-00AA006946EE")]
public class UrlHistory /* : IUrlHistoryStg[2] */ {}


public class test
{
    static void Main()
    {
        IUrlHistoryStg2 stg = (IUrlHistoryStg2) new UrlHistory();
        stg.ClearHistory();
    }
}

如果服务或应用程序模拟用户,则系统不会加载该用户的配置文件。请先尝试呼叫。

如果服务或应用程序模拟用户,则系统不会加载用户的配置文件。首先尝试调用。

最终使用Wininet API,如

Microsoft文档说明:

与WinINet API的所有其他方面一样,此函数不能 从DllMain或构造函数和析构函数中安全调用 全局对象的定义。注意:WinINet不支持服务器 实现。此外,不应从服务中使用它。 对于服务器实现或服务,请使用Microsoft Windows HTTP 服务(WinHTTP)

我颠倒了那些API,发现了他们检查过的问题

  • 模仿
  • 从服务运行
如果其中一个为真,则API存在,错误代码为0x80070078

因此,幸运的是,您试图通过服务实现的目标是不可能的,您必须使用

最终使用Wininet API,如

Microsoft文档说明:

与WinINet API的所有其他方面一样,此函数不能 从DllMain或构造函数和析构函数中安全调用 全局对象的定义。注意:WinINet不支持服务器 实现。此外,不应从服务中使用它。 对于服务器实现或服务,请使用Microsoft Windows HTTP 服务(WinHTTP)

我颠倒了那些API,发现了他们检查过的问题

  • 模仿
  • 从服务运行
如果其中一个为真,则API存在,错误代码为0x80070078

所以,幸运的是,您试图通过服务实现的目标是不可能的,您必须使用