Verfasst: 28.07.2006 09:52
Ah ok es klappt schonmal. Aber wo geb ich denn ein ob ich zb. Neustarten will oder Herunterfahren will?
Das deutsche PureBasic-Forum
https://www.purebasic.fr/german/
...nicht nur Copy-Paste, sondern verstehen:Joel hat geschrieben:Ah ok es klappt schonmal. Aber wo geb ich denn ein ob ich zb. Neustarten will oder Herunterfahren will?
Code: Alles auswählen
#EWX_FORCE=4
#EWX_LOGOFF=0
#EWX_REBOOT=2
#EWX_SHUTDOWN=1
Code: Alles auswählen
#EWX_LOGOFF = 0
#EWX_SHUTDOWN = 1
#EWX_REBOOT = 2
#EWX_FORCE = 4
#EWX_POWEROFF = 8
Code: Alles auswählen
#EWX_LOGOFF = 0
#EWX_SHUTDOWN = 1
#EWX_REBOOT = 2
#EWX_FORCE = 4
#EWX_POWEROFF = 8
#TOKEN_ADJUST_PRIVILEGES = 32
#TOKEN_QUERY = 8
#SE_PRIVILEGE_ENABLED = 2
#ANYSIZE_ARRAY = 1
#VER_PLATFORM_WIN32_NT = 2
#SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Structure MyLUID
LowPart.l
HighPart.l
Attributes.l
EndStructure
Structure MyTOKEN
PrivilegeCount.l
LowPart.l
HighPart.l
Attributes.l
EndStructure
Global hdlProcessHandle.l
Global hdlTokenHandle.l
Global tmpLuid.MyLUID
Global tkp.MyToken
Global tkpNewButIgnored.MyToken
Global lBufferNeeded.l
hdlProcessHandle = GetCurrentProcess_()
OpenProcessToken_(hdlProcessHandle, #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)
; Get the LUID for shutdown privilege
SysName.s = "" + Chr(0)
Name.s = "SeShutdownPrivilege" + Chr(0)
Erg.l = LookupPrivilegeValue_(SysName, Name, @tmpLuid)
tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
tkp\PrivilegeCount = 1
tkp\LowPart = tmpLuid\LowPart
tkp\HighPart = tmpLuid\HighPart
tkp\Attributes = tmpLuid\Attributes
; Enable the shutdown privilege in the access token of this process
Erg.l = AdjustTokenPrivileges_(hdlTokenHandle, 0, @tkp, SizeOf(MyTOKEN), @tkpNewButIgnored, @lblBufferNeeded)
Erg.l = ExitWindowsEx_((#EWX_LOGOFF), 0)
Code: Alles auswählen
;
; ------------------------------------------------------------
;
; Mein kleiner Client
;
;
;
; ------------------------------------------------------------
;
Procedure Privilegien()
#EWX_LOGOFF = 0
#EWX_SHUTDOWN = 1
#EWX_REBOOT = 2
#EWX_FORCE = 4
#EWX_POWEROFF = 8
#TOKEN_ADJUST_PRIVILEGES = 32
#TOKEN_QUERY = 8
#SE_PRIVILEGE_ENABLED = 2
#ANYSIZE_ARRAY = 1
#VER_PLATFORM_WIN32_NT = 2
#SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
Structure MyLUID
LowPart.l
HighPart.l
Attributes.l
EndStructure
Structure MyTOKEN
PrivilegeCount.l
LowPart.l
HighPart.l
Attributes.l
EndStructure
Global hdlProcessHandle.l
Global hdlTokenHandle.l
Global tmpLuid.MyLUID
Global tkp.MyToken
Global tkpNewButIgnored.MyToken
Global lBufferNeeded.l
hdlProcessHandle = GetCurrentProcess_()
OpenProcessToken_(hdlProcessHandle, #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)
; Get the LUID for shutdown privilege
SysName.s = "" + Chr(0)
Name.s = "SeShutdownPrivilege" + Chr(0)
Erg.l = LookupPrivilegeValue_(SysName, Name, @tmpLuid)
tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
tkp\PrivilegeCount = 1
tkp\LowPart = tmpLuid\LowPart
tkp\HighPart = tmpLuid\HighPart
tkp\Attributes = tmpLuid\Attributes
; Enable the shutdown privilege in the access token of this process
Erg.l = AdjustTokenPrivileges_(hdlTokenHandle, 0, @tkp, SizeOf(MyTOKEN), @tkpNewButIgnored, @lblBufferNeeded)
EndProcedure
Procedure Herunterfahren()
If ExitWindowsEx_((#EWX_POWEROFF), 8)
EndIf
EndProcedure
Procedure Neustart()
If ExitWindowsEx_((#EWX_REBOOT), 2)
EndIf
EndProcedure
Procedure Abmelden()
If ExitWindowsEx_((#EWX_LOGOFF), 0)
EndIf
EndProcedure
Procedure Force()
If ExitWindowsEx_((#EWX_FORCE), 4)
EndIf
EndProcedure
;-Vorbereiten der Netzwerk-Einstellungen
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
Port = 7000
;-Schleife zur Verbindungs-Herstellung
Repeat
ConnectionID = OpenNetworkConnection("joel2.dyndns.org", Port)
If ConnectionID
EndIf
Delay(10)
Until ConnectionID <> 0
;-Daten-empfang-Schleife
Repeat
ServerID = NetworkClientEvent(ConnectionID)
Select ServerID
Case 3
Privilegien()
Herunterfahren()
Case 4
End
EndSelect
Until Quit = 1
CloseNetworkConnection(ConnectionID)
End