Autor Beitrag
csnoopy
Hält's aus hier
Beiträge: 4



BeitragVerfasst: So 25.07.10 11:12 
hallo leute,

bin im moment etwas verzweifelt. ich habe ein service geschrieben, welches aufgrund eines events an der seriellen schnittstelle einen logoff durchführen soll.

ich habe vorab das ganze in einer form getestet, wo auch alles super funktioniert hat.
jedoch als service funktioniert ein LOGOFF nicht (ein SHUTDOWN komischerweise schon)

ausblenden C#-Quelltext
1:
2:
3:
4:
[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int operationFlag, int operationReason);

ExitWindowsEx(00);  //(auch mit FORCE 4) ...


habe es auch mit dem Windows Controller von mentalis.org/soft/class.qpx?id=7 probiert.

ausblenden C#-Quelltext
1:
SHUTDOWN (ExitWindowsEx(80);) //funktioniert ein LOGOFF nicht.					


hat dafür jemand eine erklärung?

thx

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
Greenberet
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 339
Erhaltene Danke: 20

Win 10
C# (VS 2012), C++ (VS 2012/GCC), PAWN(Notepad++), Java(NetBeans)
BeitragVerfasst: So 25.07.10 16:22 
Überprüf mal warum es nicht gegangen ist mit GetLastError

msdn.microsoft.com/e...or%28v=VS.80%29.aspx
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19272
Erhaltene Danke: 1740

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 25.07.10 17:48 
Das kann auch nicht gehen. Der Benutzer "System", unter dem der Dienst läuft, kann nicht abgemeldet werden. Deshalb passiert nichts.
csnoopy Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: So 25.07.10 18:32 
wie könnte man das problem lösen?
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: So 25.07.10 18:36 
Gegenfrage: Was versprichst du dir überhaupt von einem Service?

_________________
>λ=
csnoopy Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: So 25.07.10 18:49 
wollte das ganze als service prgorammieren, da ich mir das ganze "hide form" spielchen ersparen wollte.

im hintergrund läuft microsoft "steady state" (kiosk-pc).

nunja, habe mittlerweile auch WTSDisconnectSession getestet. leider erfolgt hier scheinbar kein logoff sondern nur ein lock des pc´s.

hat noch jemand eine idee?
csnoopy Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: So 25.07.10 22:21 
habe eine funktionierende lösung gefunden - getestet mit windows xp

code für die nachwelt:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
[DllImport("wtsapi32.dll", SetLastError = true)]
static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait);

[DllImport("Kernel32.dll", SetLastError = true)]
static extern UInt32 WTSGetActiveConsoleSessionId();

=============================================================

UInt32 WTS_CURRENT_SESSION = UInt32.MaxValue;
IntPtr WTS_CURRENT_SERVER_HANDLE = new IntPtr();

int WTS_CURRENT_SESSION_DISCONNECT = (int)WTSGetActiveConsoleSessionId();
//eventLog1.WriteEntry(WTS_CURRENT_SESSION_DISCONNECT.ToString());
WTSLogoffSession(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION_DISCONNECT, false);



thx all!

Moderiert von user profile iconKha: C#-Tags hinzugefügt