vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
sevDataGrid - Gönnen Sie Ihrem SQL-Kommando diesen krönenden Abschluß!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Re: Windows ohne nachfragen ("Sofort beenden" Aufruf) herunterfahren Net 
Autor: Urot
Datum: 19.07.05 20:38

ok ich poste mal meine shutdown klasse hier für alle des wurde schon öfter ohne richtige lösung gefragt..

Imports System.Runtime.InteropServices
 
Public Class Shutdown
 
#Region " Privilegs "
 
    ' Constants
    Private Const SE_PRIVILEGE_ENABLED As Integer = &H2
    Private Const TOKEN_QUERY As Integer = &H8
    Private Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
    Private Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"
 
    <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    Private Structure Luid ' locally unique identifier 
        Public Count As Integer
        Public Luid As Long
        Public Attr As Integer
    End Structure
 
    <DllImport("kernel32.dll", ExactSpelling:=True)> _
   Private Shared Function GetCurrentProcess() As IntPtr
    End Function ' get process handle ...
 
    <DllImport("advapi32.dll", SetLastError:=True)> _
  Private Shared Function OpenProcessToken(ByVal h As IntPtr, ByVal acc As _
  Integer, ByRef phtok As IntPtr) As Boolean
    End Function ' open process token
 
    <DllImport("advapi32.dll", SetLastError:=True)> _
   Private Shared Function LookupPrivilegeValue(ByVal host As String, ByVal _
   name As String, ByRef pluid As Long) As Boolean
    End Function ' luid privileg verpassen
 
    <DllImport("advapi32.dll", ExactSpelling:=True, SetLastError:=True)> _
   Private Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr, ByVal _
   disall As Boolean, ByRef newst As Luid, ByVal len As Integer, ByVal prev As _
   IntPtr, ByVal relen As IntPtr) As Boolean
    End Function ' token anpassen
 
    ' assigns shutdownprivileges to the running process 
    Public Shared Sub getShutdownPrivileges()
        Dim tp As Luid
        Dim hproc As IntPtr = GetCurrentProcess()
        Dim htok As IntPtr = IntPtr.Zero
        'Get a token for this process. 
        OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, htok)
        tp.Count = 1
        tp.Luid = 0
        tp.Attr = SE_PRIVILEGE_ENABLED
        ' get a valid luid for shutdown
        LookupPrivilegeValue(Nothing, SE_SHUTDOWN_NAME, tp.Luid)
        'adjust the shutdown luid to the token
        AdjustTokenPrivileges(htok, False, tp, 0, IntPtr.Zero, IntPtr.Zero)
    End Sub
 
#End Region
 
#Region " ExitWindowsEx "
 
    ' ExitWindows Constants
    Public Const EWX_LOGOFF As Integer = &H0 ' logoff
    Public Const EWX_SHUTDOWN As Integer = &H1 ' shutdown
    Public Const EWX_REBOOT As Integer = &H2 ' reboot
    Public Const EWX_FORCE As Integer = &H4 ' force apps to be closed
    Public Const EWX_POWEROFF As Integer = &H8 ' turn off
    Public Const EWX_FORCEIFHUNG As Integer = &H10 ' force if hung
 
    ' Exit Windows
    <DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> _
    Public Shared Function ExitWindowsEx(ByVal flg As Integer, ByVal rea As _
    Integer) As Boolean
    End Function
 
#End Region
 
#Region " ShutdownFunctions "
 
    <DllImport("advapi32.dll", SetLastError:=True)> _
    Public Shared Function AbortSystemShutdown(ByVal lpMachineName As String) _
    As Boolean
    End Function
 
    <DllImport("advapi32.dll", SetLastError:=True)> _
    Public Shared Function InitiateSystemShutdown(ByVal lpMachineName As _
    String, _
    ByVal lpMessage As String, _
    ByVal dwTimeout As Integer, _
    ByVal bForceAppsClosed As Boolean, _
    ByVal bRebootAfterShutdown As Boolean) As Boolean
    End Function
 
    <DllImport("advapi32.dll", SetLastError:=True)> _
      Public Shared Function InitiateSystemShutdownEx(ByVal lpMachineName As _
      String, _
      ByVal lpMessage As String, _
      ByVal dwTimeout As Integer, _
      ByVal bForceAppsClosed As Boolean, _
      ByVal bRebootAfterShutdown As Boolean, _
      ByVal dwReason As Integer) As Boolean ' u can create your own reasons ! 
      ' see msdn
    End Function
 
#End Region
 
End Class
nun hast du die auswahl aus mehreren shutdown methoden
als erstes musst du die Shutdown.getShutdownPrivileges() methode aufrufen.
danach hat dein process shutdown rechte
dann kannst du folgendes machen :

Const NULL As String = ""
Shutdown.getShutdownPrivileges() 
Shutdown.InitiateSystemShutdown(NULL, "Shutdown", 0, True, True)
wenn du den parameter bForceAppsClosed auf true setzt kommen keine nachfragen
das etwas gespeichert werden soll ...
bRebootAfterShutdown sagt aus ob gerebooted werden soll ...

njoy
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Windows ohne nachfragen ("Sofort beenden" Aufruf) ...2.063spiderboy19.07.05 19:07
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...2.191Urot19.07.05 20:38
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.518spiderboy19.07.05 20:52
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.513Urot19.07.05 20:54
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.419spiderboy19.07.05 21:14
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.510Urot19.07.05 23:37
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.444spiderboy20.07.05 13:45
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.516Urot20.07.05 14:43
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.562spiderboy20.07.05 14:59
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.489Urot20.07.05 15:27
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.552spiderboy20.07.05 19:00
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.537Urot20.07.05 19:32
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.497Urot20.07.05 19:36
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.460spiderboy20.07.05 20:05
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.501Urot20.07.05 20:41
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.509spiderboy20.07.05 21:04
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.502spiderboy20.07.05 21:20
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.427Urot21.07.05 00:02
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.605spiderboy21.07.05 14:48
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.472Urot21.07.05 15:19
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.494spiderboy21.07.05 15:55
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.423Urot21.07.05 15:57
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.441spiderboy21.07.05 16:25
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.470Silver24.07.05 11:34
Re: Windows ohne nachfragen ("Sofort beenden" Aufruf) herunt...1.500spiderboy31.07.05 11:29
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.601Urot31.07.05 12:07
Re: Windows ohne nachfragen ("Sofort beenden" Aufruf) herunt...1.461spiderboy31.07.05 22:46
Re: Windows ohne nachfragen ("Sofort beenden" Aufr...1.779The_Hammer29.09.05 11:40

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel