|
|
|
date: Wed, 27 Aug 2008 10:53:43 +0530,
group: microsoft.public.platformsdk.security
back
Re: Check if a process is running under the current user (not by using the user names)
If you are checking for your own process than the better way is, use
CreateMutex to create a named mutex with Local\\... and use GetLastError. If
mutex already exist, the return value by GetLastError will be
ERROR_ALREADY_EXISTS
for SID, in ATL you can use CAccessToken class and GetUser member to get the
SID or simply have a look at CSid class.
Regards,
Manish Agarwal
"Ashutosh" <smbs-msdn@nospam.nospam> wrote in message
news:OIVU8SACJHA.4316@TK2MSFTNGP05.phx.gbl...
> Hi,
> I am trying to check if a process is running under the same
> credential/user as my application. I can do that by getting the user names
> for both the process, but I am looking for more efficient way by comparing
> the user tokens/SID.
>
> Using GetTokenInformation & LookupAccountSid, I can get the SID of the
> user for the target process I want to check (which requires PTOKEN_USER).
>
> How do I get the PTOKEN_USER / SID for the current user? I couldn't find
> any API for this. I am planning to compare the SID of both to check for
> the process existence.
>
> Also, is there any more efficient way to do this?
>
> Regards,
> Ashutosh
date: Wed, 27 Aug 2008 12:11:57 +0530
author: Manish Agarwal
Re: Check if a process is running under the current user (not by
using the user names)
Hi Manish,
The process for which my application needs to perform the check is not
my process. So, the CreateMutex method won't work.
Also, class CAccessToken or CSid doesn't have any method to get the
token/SID of the user under which the code is running.
Regards,
Ashutosh
Manish Agarwal wrote:
> If you are checking for your own process than the better way is, use
> CreateMutex to create a named mutex with Local\\... and use GetLastError. If
> mutex already exist, the return value by GetLastError will be
> ERROR_ALREADY_EXISTS
>
> for SID, in ATL you can use CAccessToken class and GetUser member to get the
> SID or simply have a look at CSid class.
>
> Regards,
> Manish Agarwal
>
> "Ashutosh" <smbs-msdn@nospam.nospam> wrote in message
> news:OIVU8SACJHA.4316@TK2MSFTNGP05.phx.gbl...
>
>> Hi,
>> I am trying to check if a process is running under the same
>> credential/user as my application. I can do that by getting the user names
>> for both the process, but I am looking for more efficient way by comparing
>> the user tokens/SID.
>>
>> Using GetTokenInformation & LookupAccountSid, I can get the SID of the
>> user for the target process I want to check (which requires PTOKEN_USER).
>>
>> How do I get the PTOKEN_USER / SID for the current user? I couldn't find
>> any API for this. I am planning to compare the SID of both to check for
>> the process existence.
>>
>> Also, is there any more efficient way to do this?
>>
>> Regards,
>> Ashutosh
>>
>
>
>
date: Wed, 27 Aug 2008 14:46:56 +0530
author: Ashutosh am
Re: Check if a process is running under the current user (not by
using the user names)
I found the solution myself. I opened the current process and used the
GetTokenInformation to get the SID of user running the currently
executing process....
Such a simple solution...Why didn't I do it at the first??
Anyways, thanks all of you.
Manish Agarwal wrote:
> If you are checking for your own process than the better way is, use
> CreateMutex to create a named mutex with Local\\... and use GetLastError. If
> mutex already exist, the return value by GetLastError will be
> ERROR_ALREADY_EXISTS
>
> for SID, in ATL you can use CAccessToken class and GetUser member to get the
> SID or simply have a look at CSid class.
>
> Regards,
> Manish Agarwal
>
> "Ashutosh" <smbs-msdn@nospam.nospam> wrote in message
> news:OIVU8SACJHA.4316@TK2MSFTNGP05.phx.gbl...
>
>> Hi,
>> I am trying to check if a process is running under the same
>> credential/user as my application. I can do that by getting the user names
>> for both the process, but I am looking for more efficient way by comparing
>> the user tokens/SID.
>>
>> Using GetTokenInformation & LookupAccountSid, I can get the SID of the
>> user for the target process I want to check (which requires PTOKEN_USER).
>>
>> How do I get the PTOKEN_USER / SID for the current user? I couldn't find
>> any API for this. I am planning to compare the SID of both to check for
>> the process existence.
>>
>> Also, is there any more efficient way to do this?
>>
>> Regards,
>> Ashutosh
>>
>
>
>
date: Wed, 27 Aug 2008 16:17:35 +0530
author: Ashutosh am
Re: Check if a process is running under the current user (not by using the user names)
Hi Ashutosh,
Yes, you should first use OpenProcess() to obtain a handle to your current
process, then use OpenProcessToken() to get a security token to the
process. Finally, you may use GetTokenInformation() to query token
information, such as user name.
Cavet: remember to request PROCESS_QUERY_INFORMATION permission in
OpenProcess() function call which is required for OpenProcessToken().
Another approach is calling GetUserNameEx() to get the user name of your
calling thread, which should be the account of your application. Then, you
may call LookupAccountName() to translate the user name into the SID for
comparison.
Both solutions should meet your need. Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Thu, 28 Aug 2008 03:20:47 GMT
author: (Jeffrey Tan[MSFT])
|
|