Solved

how to log off the interactive user from a service

Posted on 2001-07-02
3
206 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 100 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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