Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Wed, 27 Aug 2008 10:53:43 +0530,    group: microsoft.public.platformsdk.security        back       


Check if a process is running under the current user (not by using the user names)   
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 10:53:43 +0530   author:   Ashutosh am

Re: Check if a process is running under the current user (not by using the user names)   
Ashutosh schrieb:
> 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.

I do not understand your request. Are you comparing the users of two processes? 
Then you should be able to use the same method for both processes.

If not, what do you mean by "target process"? And what do you think is the 
"current user"? As far as I know, there is no such thing as a "current user" 
(except the user that owns the current process). On Windows XP, you can have 
many users logged in at the same time, and different processes can be run by 
different users.

There does exist something like a "logon session". Do you perhaps mean that? But 
I an nor sure if there is such a thinh as the "current" session, just the 
session from that your process was startet...

Norbert
date: Wed, 27 Aug 2008 08:38:02 +0200   author:   Norbert Unterberg am

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])

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us