LoadUserProfile Windows

Back ground:

We use WMI to do remote install. We create a process to start MSI installation. And it is set to impersonate the user specified.

But we get problem when user was log off.

We failed to do something to the CURRENT_USER node in the registry.

After reviewing the MSI log, we find out that the profile used is the default profile, not the profile for the user specified.

After some search, I find that only impersonate is not enough, we need to load the specific user profile.

It will be loaded when user logon.

It will be loaded if a windows service is running with the specific user.

So, we get the problem when the user is logoff.

 

Solution:

We need to load user profile by function LoadUserProfile.

BOOL WINAPI LoadUserProfile(

  __in     HANDLE hToken,

  __inout  LPPROFILEINFO lpProfileInfo

);

Token for the user, which is returned by the LogonUser, CreateRestrictedToken, DuplicateToken, OpenProcessToken, or OpenThreadToken function. The token must have TOKEN_QUERY, TOKEN_IMPERSONATE, and TOKEN_DUPLICATE access

 

 You may get token handle by function:

BOOL WINAPI OpenProcessToken(

  __in   HANDLE ProcessHandle,

  __in   DWORD DesiredAccess,

  __out  PHANDLE TokenHandle

);

 

You may get user sid by GetTokenInformation.

BOOL WINAPI GetTokenInformation(

  __in       HANDLE TokenHandle,

  __in       TOKEN_INFORMATION_CLASS TokenInformationClass,

  __out_opt  LPVOID TokenInformation,

  __in       DWORD TokenInformationLength,

  __out      PDWORD ReturnLength

);

 

Get User information by

BOOL WINAPI LookupAccountSid(

  __in_opt   LPCTSTR lpSystemName,

  __in       PSID lpSid,

  __out_opt  LPTSTR lpName,

  __inout    LPDWORD cchName,

  __out_opt  LPTSTR lpReferencedDomainName,

  __inout    LPDWORD cchReferencedDomainName,

  __out      PSID_NAME_USE peUse

);

 

And you may get usr profile path by function below in USER_INFO_4

NET_API_STATUS NetUserGetInfo(

  __in   LPCWSTR servername,

  __in   LPCWSTR username,

  __in   DWORD level,

  __out  LPBYTE *bufptr

);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值