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-2024
 
zurück

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

Fortgeschrittene Programmierung
Re: Windows Service aus VB6 steuern 
Autor: effeff
Datum: 08.07.09 11:15

Mir ist keine direkte Methode bekannt, einem Benutzer Rechte zu erteilen, Dienste zu starten und zu stoppen. Was du machen kannst, ist eine API zu verwenden, um dein Programm unter einem administrativen Account zu starten. Du könntest also z. B. den folgenden Code (Beispiel vom KPD-Team) verwenden, um eine Exe zu erstellen, die deine Exe wiederum mit Admin-Rechten ausführt. Du musst den fetten Teil auf deine Bedürfnisse dazu anpassen:

Private Const LOGON_WITH_PROFILE = &H1&
Private Const LOGON_NETCREDENTIALS_ONLY = &H2&
Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_NEW_PROCESS_GROUP = &H200&
Private Const CREATE_SEPARATE_WOW_VDM = &H800&
Private Const CREATE_SUSPENDED = &H4&
Private Const CREATE_UNICODE_ENVIRONMENT = &H400&
Private Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000&
Private Const BELOW_NORMAL_PRIORITY_CLASS = &H4000&
Private Const HIGH_PRIORITY_CLASS = &H80&
Private Const IDLE_PRIORITY_CLASS = &H40&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const REALTIME_PRIORITY_CLASS = &H100&
Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type
Private Type STARTUPINFO
    cb As Long
    lpReserved As Long
    lpDesktop As Long
    lpTitle As Long
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Byte
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type
Private Declare Function CreateProcessWithLogon Lib "Advapi32" Alias _
  "CreateProcessWithLogonW" (ByVal lpUsername As Long, ByVal lpDomain As Long, _
  ByVal lpPassword As Long, ByVal dwLogonFlags As Long, ByVal lpApplicationName _
  As Long, ByVal lpCommandLine As Long, ByVal dwCreationFlags As Long, ByVal _
  lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As _
  STARTUPINFO, lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
Long
Private Sub Form_Load()
    Dim lpUsername As String, lpDomain As String, lpPassword As String, _
      lpApplicationName As String
    Dim lpCommandLine As String, lpCurrentDirectory As String
    Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
    lpUsername = "OtherUser"
    lpDomain = ""
    lpPassword = "other_user_password"
    lpApplicationName = "C:\WINNT\NOTEPAD.EXE"
    lpCommandLine = vbNullString 'use the same as lpApplicationName
    lpCurrentDirectory = vbNullString 'use standard directory
    StartInfo.cb = LenB(StartInfo) 'initialize structure
    StartInfo.dwFlags = 0&
    CreateProcessWithLogon StrPtr(lpUsername), StrPtr(lpDomain), StrPtr( _
      lpPassword), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), StrPtr( _
      lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or _
      CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), _
      StartInfo, ProcessInfo
    CloseHandle ProcessInfo.hThread 'close the handle to the main thread, since 
    ' we don't use it
    CloseHandle ProcessInfo.hProcess 'close the handle to the process, since we 
    ' don't use it
    'note that closing the handles of the main thread and the process do not 
    ' terminate the process
    'unload this application
    Unload Me
End Sub

EALA FREYA FRESENA

Beitrag wurde zuletzt am 08.07.09 um 11:16:26 editiert.

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Windows Service aus VB6 steuern1.040reini6902.07.09 10:55
Re: Windows Service aus VB6 steuern711effeff06.07.09 22:49
Re: Windows Service aus VB6 steuern597reini6907.07.09 07:48
Re: Windows Service aus VB6 steuern658reini6908.07.09 09:45
Re: Windows Service aus VB6 steuern594effeff08.07.09 11:15

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-2024 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