IUrlHistoryStg2 :: ClearHistory()无法通过服务运行吗? [英] IUrlHistoryStg2::ClearHistory() does not work from a service?
问题描述
IUrlHistoryStg2 :: ClearHistory()方法被记录为按用户。
The IUrlHistoryStg2::ClearHistory() method is documented as Per-User.
http://msdn.microsoft.com/zh-cn/library/aa767715(VS.85).aspx
从以SYSTEM帐户运行的服务调用它时,我无法定位特定的登录用户。我已经通过WindowsIdentity.Impersonate()成功模拟了用户,但对ClearHistory()的调用始终返回0表示成功,但不会清除用户的历史记录。
When calling it from a service running under the SYSTEM account, I am unable to target particular logged-on users. I have successfully impersonated the users via WindowsIdentity.Impersonate() but the call to ClearHistory() always returns 0 for success but does not clear the history of the user.
这在XP和Win7上都适用,因此似乎不是会话隔离问题。
This applies on both XP and Win7 so appears to be not a session isolation issue.
也许是因为它是COM,所以有人在查看调用方的Process令牌,而不是其调用方
Perhaps because it is COM, something is looking at the Process token of the caller rather than its Thread token when impersonating?
我感到困惑的是,为什么模拟用户并不能简单地导致这种方法的成功?
I am confused why impersonating the user does not simply lead to success of this method?
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();
}
}
推荐答案
如果服务或应用程序冒充用户,则系统不会加载用户的个人资料。尝试先致电 LoadUserProfile 。
If a service or an application impersonates a user, the system does not load the user's profile. Try call LoadUserProfile first.
这篇关于IUrlHistoryStg2 :: ClearHistory()无法通过服务运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!