Hallo Achim,

ich habe von einem Bekannten einmal eine solche Funktion bekommen, die ich Dir gerne weitergebe.

Sub WindowsGoHome()
  #if TargetWin32 then
    Const TOKEN_ADJUST_PRIVILEGES = 32
    Const TOKEN_QUERY = 8
    Const SE_PRIVILEGE_ENABLED = 2
    Const EWX_LOGOFF = 0
    Const EWX_SHUTDOWN = 1
    Const EWX_REBOOT = 2
    Const EWX_FORCE = 4
    Const EWX_POWEROFF = 8

    Dim Dummy As integer
    Dim hdlProcessHandle As Integer
    Dim hdlTokenHandle As MemoryBlock
    Dim hdlTokenH As Integer
    Dim lBufferNeeded As MemoryBlock
    Dim tkp As MemoryBlock
    Dim tkpNewButIgnored As MemoryBlock
    Dim TmpLUID As MemoryBlock
    Dim SysName As MemoryBlock
    Dim Name As MemoryBlock
    Dim Erg As Integer

    SysName=newMemoryBlock(256)
    Name=newMemoryBlock(256)
    hdlTokenHandle=newMemoryBlock(4)
    lBufferNeeded=newMemoryBlock(4)
    SysName.CString(0)=""+chr(0)
    Name.CString(0)="SeShutdownPrivilege"+chr(0)

    tkp=newMemoryBlock(16)
    tkpNewButIgnored=newMemoryBlock(16)
    TmpLUID=newMemoryBlock(12)


    Declare Function GetCurrentProcess Lib "kernel32.dll" () As integer
Declare Function OpenProcessToken Lib "advapi32.dll" ( ByVal ProcessHandle As integer, ByVal DesiredAccess As integer, TokenHandle As Ptr) As integer

Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" ( lpSystemName As Ptr, lpName As Ptr, lpLuid As Ptr) As integer

Declare Function AdjustTokenPrivileges Lib "advapi32.dll" ( ByVal TokenHandle As Integer, ByVal DisableAllPrivileges As integer, NewState As Ptr, ByVal BufferLength As Integer, PreviousState As Ptr, ReturnLength As Ptr) As integer

Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As integer, ByVal dwReserved As integer) As integer

    hdlProcessHandle=GetCurrentProcess()
    //msgBox "Prozesshandle: "+str(hdlProcessHandle)
    Dummy=Bitwise.Bitor(TOKEN_ADJUST_PRIVILEGES,TOKEN_QUERY)
    Dummy=OpenProcessToken(hdlProcessHandle,Dummy,hdlTokenHandle)
    //msgBox "Prozess geöffnet: (<>0)"+str(Dummy)
    Erg=LookupPrivilegeValue(SysName,Name,TmpLUID)
    //msgBox "Privileg setzen: (<>0)"+str(Erg)
    TmpLUID.Long(8)=SE_PRIVILEGE_ENABLED
    tkp.Long(0)=1
    tkp.Long(4)=TmpLUID.Long(0)
    tkp.Long(8)=TmpLUID.Long(4)
    tkp.Long(12)=TmpLUID.Long(8)
    hdlTokenH=hdlTokenHandle.Long(0)
Erg=AdjustTokenPrivileges(hdlTokenH,0,tkp,16,tkpNewButIgnored,lBufferNee ded)
    //msgBox "Ich darf jetzt runterfahren: (<>0)"+str(Erg)
Erg=ExitWindowsEx(Bitwise.Bitor(Bitwise.Bitor(EWX_SHUTDOWN,EWX_POWEROFF) ,EWX_FORCE),0)
    //msgBox "Kill alle Prozesse und Schluss: (<>0)"+str(Erg)
    //msgBox "und Tschüss!"
  #endif
End Sub

Gruß
Rudi

Am 10.04.2006 um 07:26 schrieb Achim Kredteck:



...vielleicht hat ja jemand noch einen Codeschnipsel irgendwo ??

Danke und schönen Tag noch
Achim


Antwort per Email an