begin process at 2008 08 30 19:08:09
1 234 151 membres
184 nouveaux aujourd'hui
14 294 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : Enregistrement d'une dll sur windows xp avec un compte utilisateur n'ayant pas de droit [ Archives Visual Basic / Formulaire ] (vaneri2004)

Enregistrement d'une dll sur windows xp avec un compte utilisateur n'ayant pas de droit le 08/06/2005 15:48:21

vaneri2004

Bonjour tout le monde,

Je me creuse la tête depuis quelques temps pour trouver le moyen d'enregistrer une dll sur un chti Windows Xp avec un compte utilisateur sans droit (pour une mise à jour de programme).
Je n'arrive pas à trouver un code permettant de devenir temporairement Administrateur. Utilisation de runAs n'est pas tout à fait propre alors j'ai décider de trouver une API permettant de passer momentanément en mode administrateur. J'ai fini par trouver CreateProcessWithLogonW mais cette API ne me donne aucun résultat (enfin je n'arrive pas à la faire fonctionner kwoi ).
Est-ce que quelqu'un peut m'aider svp ... Je n'ai aucun code d'erreur mais cela ne fonctionne pas.

Merci d'avance
Vaneri


Option Explicit

Private Const LOGON_WITH_PROFILE            As Long = &H1&
Private Const LOGON_NETCREDENTIALS_ONLY     As Long = &H2&
Private Const CREATE_DEFAULT_ERROR_MODE     As Long = &H4000000
Private Const CREATE_NEW_CONSOLE            As Long = &H10&
Private Const CREATE_NEW_PROCESS_GROUP      As Long = &H200&
Private Const CREATE_SEPARATE_WOW_VDM       As Long = &H800&
Private Const CREATE_SUSPENDED              As Long = &H4&
Private Const CREATE_UNICODE_ENVIRONMENT    As Long = &H400&
Private Const ABOVE_NORMAL_PRIORITY_CLASS   As Long = &H8000&
Private Const BELOW_NORMAL_PRIORITY_CLASS   As Long = &H4000&
Private Const HIGH_PRIORITY_CLASS           As Long = &H80&
Private Const IDLE_PRIORITY_CLASS           As Long = &H40&
Private Const NORMAL_PRIORITY_CLASS         As Long = &H20&
Private Const REALTIME_PRIORITY_CLASS       As Long = &H100&
Private Const SLEEP_DELAY                   As Long = 100&
Private Const STATUS_PENDING                As Long = &H103&
Private Const STILL_ACTIVE                  As Long = STATUS_PENDING
Private Const API_TRUE                      As Long = &H1&
Private Const API_FALSE                     As Long = &H0&
Private Const API_NULL                      As Long = &H0&

Private Const API_FAILURE                   As Long = &H0&
Private Const STARTF_USESHOWWINDOW          As Long = &H1&
Private Const SW_HIDE                       As Long = 0&
Private Const SW_SHOW                       As Long = &H1&

Private Const DOMAIN_ALIAS_RID_ADMINS       As Long = &H220&
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 UserName As Long, _
    ByVal Domain As Long, _
    ByVal Password As Long, _
    ByVal dwLogonFlags As Long, _
    ByVal ApplicationName As Long, _
    ByVal strCommandLine As Long, _
    ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, _
    ByVal strCurrentDirectory As Long, _
    ByRef lpStartupInfo As STARTUPINFO, _
    ByRef lppiProcessInfo As PROCESS_INFORMATION) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
    ByVal hProcess As Long, _
    ByRef lpExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long) As Long

Private Declare Function Sleep Lib "kernel32" ( _
    ByVal dwMilliseconds As Long) As Long

Public Function CreateProcess( _
ByVal Domain As String, _
ByVal UserName As String, _
ByVal Password As String, ByVal ApplicationName As String, _
Optional ByVal ExecuteAsynch As Boolean = False, _
Optional ByVal Visible As Boolean = False) As Long


    'Define local variables
    Dim strCommandLine      As String
    Dim strCurrentDirectory As String
    Dim suiStartUpInfo      As STARTUPINFO
    Dim piProcessInfo       As PROCESS_INFORMATION
    Dim lngExitCode         As Long
    Dim lngReturnValue      As Long
    Dim strMessage          As String
    'Initialize local variables
    strCommandLine = vbNullString               'Make sure all of your parameters are part of the ApplicationName
    strCurrentDirectory = vbNullString      'Use the standard, default assignment
    With suiStartUpInfo
        .cb = LenB(suiStartUpInfo)              'Size of the structure
        .lpReserved = API_NULL                  'Reserved
        .cbReserved2 = API_NULL                 'Reserved
        .dwFlags = STARTF_USESHOWWINDOW         'Use the wShowWindow parameter
        .wShowWindow = IIf(Visible, SW_SHOW, SW_HIDE)  'Hide or show any window that might be shown
    End With
    'Create the new process with the credentials provided
    If CreateProcessWithLogon(StrPtr(UserName), StrPtr(Domain), StrPtr(Password), _
                                LOGON_WITH_PROFILE, StrPtr(ApplicationName), StrPtr(strCommandLine), _
                                CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, _
                                ByVal 0&, StrPtr(strCurrentDirectory), suiStartUpInfo, piProcessInfo) = API_FAILURE Then
        'There is no pointin moving on if this failed
        'Unable to launch the new process
        CreateProcess = 0
        Exit Function
    End If
    'Should we hang around till the new process ends?
    If Not ExecuteAsynch Then
        Do
            'This function returns STILL_ACTIVE if the process is still running
            lngReturnValue = GetExitCodeProcess(piProcessInfo.hProcess, lngExitCode)
            'Give up the processor
            Call Sleep(SLEEP_DELAY)
        'Loop while the process is running and there is no error
        Loop While (lngExitCode = STILL_ACTIVE) And Not (lngReturnValue = API_FAILURE)
        'The process was executed synchronously
        CreateProcess = lngExitCode
    Else
        'We arent going to stick around,
        'so don't return an exit code
        CreateProcess = 0
    End If
    'Close the handles to the thread & process, since we don't use them
    'NOTE: Closing the handles of the main thread and the process do not terminate the process
    Call CloseHandle(piProcessInfo.hThread)
    Call CloseHandle(piProcessInfo.hProcess)
End Function

Private Sub Form_Load()
  Call CreateProcess("Domain", "administrateur", "motdepasse", "regedit.exe", False, True)
End Sub


Re : Enregistrement d'une dll sur windows xp avec un compte utilisateur n'ayant pas de droit le 08/06/2005 15:56:50

vaneri2004
Réponse acceptée !

Il suffit que je poste un chti message pour que je trouve la solution ... lol
Tout bêtement regedit.exe... mettre le chemin complet ca marche mieux   =>
Private Sub Form_Load()
  Call CreateProcess("Domain", "administrateur", "motdepasse", "c:\windows\regedit.exe", False, True)
End Sub
Désolé de spammer ainsi le site


Re : Enregistrement d'une dll sur windows xp avec un compte utilisateur n'ayant pas de droit le 08/06/2005 16:24:18

_matthieu_
Salut ! Tu n´as pas besoin d´enregistrer le dll dans system32. Mets le dans le dossier source du programme. Bonne prog


Classé sous : long, process, private, const, api

Participer à cet échange

Pub



Appels d'offres

Recherche developpeur ...
Budget : 700€
SITE MARCHAND LOCATION...
Budget : 3 000€
SITE MARCHAND POUR HOTEL
Budget : 4 000€

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS