vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
SEPA-Dateien erstellen inkl. IBAN-, BLZ-/Kontonummernprüfung  
 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 & Windows API
Re: Runas mit VB realisieren ??? 
Autor: Debus
Datum: 25.09.08 08:36

Hey, hier mal mein Versuch! Ich krieg aber immer eine Fehlermeldung die lautet:

Constans, fixed-length strings array, user-defined types and Declare statements not allowed as Public members of object modules.

Der Fehler tritt in folgender Zeile auf
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Hier nun noch die komplette Source
'Run as Constants
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&
'Process type lib
Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type
'start up type lib
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
'API call for Run As
Private Declare Function CreateProcessWithLogonW Lib "Advapi32" (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
'API call for closing a handle
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
  Long
 
'local variable(s) to hold property value(s)
'and for use in internal methods
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName _
  As String, ByVal lpWindowName As String) As Long
 
 
 
 
Private mvarsUserName As String 'local
Private mvarsPassword As String 'local
Private mvarsCommand As String 'local
Private mvarsDomain As String 'local
 
 
Sub runas(Username As String, Password As String, Prog As String, startdir As _
  String)
 
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 = Username
         ' lpDomain = mvarsDomain
         lpDomain = vbNullString
         lpPassword = Password
         lpApplicationName = vbNullString
         lpCommandLine = Prog
         lpCurrentDirectory = startdir 'use standard directory
         StartInfo.cb = LenB(StartInfo) 'initialize structure
         StartInfo.dwFlags = 0&
         CreateProcessWithLogonW 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
    '     CreateProcessWithLogonW StrPtr(lpUsername), StrPtr(lpDomain), StrPtr( 
    ' lpPassword), LOGON_NETCREDENTIALS_ONLY, StrPtr(lpApplicationName), StrPtr( 
    ' lpCommandLine), CREATE_DEFAULT_ERROR_MODE, 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
 
End Sub
 
 
 
 
Private Sub Command1_Click()
runas "Username", "Passwort", "120.reg", "c:\Temp"
End Sub
Username und Passwort sind natürlich in der Source dann richtig benannt.

Hat jemand eine Idee
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Runas mit VB realisieren ???9.432otto-mueller09.06.05 14:24
Re: Runas mit VB realisieren ???6.967ModeratorMartoeng09.06.05 16:14
Re: Runas mit VB realisieren ???3.172Debus24.09.08 14:45
Re: Runas mit VB realisieren ???3.081ModeratorMartoeng24.09.08 15:21
Re: Runas mit VB realisieren ???2.875Debus24.09.08 16:16
Re: Runas mit VB realisieren ???2.808ModeratorMartoeng24.09.08 16:28
Re: Runas mit VB realisieren ???2.628Debus24.09.08 16:58
Re: Runas mit VB realisieren ???2.712ModeratorMartoeng24.09.08 17:17
Re: Runas mit VB realisieren ???2.558Debus25.09.08 08:09
Re: Runas mit VB realisieren ???2.862Debus25.09.08 08:36
Re: Runas mit VB realisieren ???2.755ModeratorDieter25.09.08 08:59
Re: Runas mit VB realisieren ???2.583Debus25.09.08 09:26
Re: Runas mit VB realisieren ???2.740Debus26.09.08 21:18
Re: Runas mit VB realisieren ???2.953Debus01.10.08 10:34
Re: Runas mit VB realisieren ???2.868effeff06.10.08 12:56
Re: Runas mit VB realisieren ???2.716effeff10.10.08 12:16

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