?
Solved

how to log off the interactive user from a service

Posted on 2001-07-02
3
Medium Priority
?
208 Views
Last Modified: 2010-04-06
Hi there,

I have written a Windows NT service in delphi, which runs as the local SYSTEM account.

This service though, needs to know who the current logged on user is, and under certain circimstances, log off that user.

If I ask for the "CurrentUser" the answer I get is SYSTEM. I need to know who is loggued on as Interactive user (on the console) and again, log off that user.

My sservice was created with Delphi 5 Ent. and runs on Windows 2000 Professional.

Best regards,

Luis
0
Comment
Question by:elkavayo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:elkavayo
ID: 6246504
I don't know if I made myself clear:

1.- The service runs under the local SYSTEM account.

2.- I need to get the username of the user that's loggued onto the computer (whoever user sits in front of the computer and logs in)

3.- Log off that user if for example, its logon time expires (let's say every user is granted 15 minutes of computer time, it's just an example)
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 400 total points
ID: 6246525
As long as the service is able to interact with the desktop yoy can use this to get the current logged-in user:


function GetCurrentUser: String;
var h: HWND;
    dwProcessId: DWORD;
    hProcess, hToken: THandle;
    a: array[0..255] of Char;
    s: Cardinal;
begin
  h := FindWindow('Progman', nil);
  GetWindowThreadProcessId(h, @dwProcessId);
  hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
  OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, hToken);
  ImpersonateLoggedOnUser(hToken);
  s := sizeof(a);
  GetUserName(a, s);
  Result := a;
  RevertToSelf;
  CloseHandle(hToken);
  CloseHandle(hProcess);
end;


It's just a rough example (no error checking).

To log the user off try ExitWindows or ExitWindowsEx.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6246532
Like this:

ExitWindowsEx(EWX_FORCE or EWX_LOGOFF, 0);
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question