Article View: borland.public.cppbuilder.nativeapi
Article #15769Re: How can the TService know the user is login or not
From: Remy Lebeau (TeamB)
Date: Wed, 18 Jun 2003 21:18
Date: Wed, 18 Jun 2003 21:18
30 lines
2262 bytes
2262 bytes
"Emmanuel" <emmanuel@erphk.com> wrote in message news:3ef0cb12@newsgroups.borland.com... > would you tell me how the TService can > know the user is login or not What you ask for is not trivial to accomplish. The overall Services architecture was not designed to support querying such information. It is possible, but it takes a lot of coding to accomplish. Basically, under XP, you have to use the WTSGetActiveConsoleSessionId() and WTSQuerySessionInformation() function. However, those functions are not available on pre-XP systems so when running under XP, you'll have to dynamically load the functions at runtime via LoadLibrary() and GetProcAddress() so that your executable will still run on pre-XP systems without producing a runtime error at startup. Under pre-XP systems, you have to instead enumerate all running processes looking for EXPLORER.EXE, the main OS shell that is executed whenever a user logs in. Once you find the process, you have to extract its access token and pass it to GetTokenInformation() to get the SID for the process, and then you can use LookupAccountSid() to get the username belonging to that SID. Either way, you'll know if a user is logged in or not by whether you can locate a valid username or not. Gambit
Technical Details
Message-ID:
<3ef0d62c$3@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ef0cb12@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,13df4f019ae645a7 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-18 14:23:18 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ef0cb12@newsgroups.borland.com> Subject: Re: How can the TService know the user is login or not Date: Wed, 18 Jun 2003 14:18:15 -0700 Lines: 32 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3ef0d62c$3@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1055970860 207.175.226.26 (18 Jun 2003 14:14:20 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail