Il faut bien entendu connaitre un compte / mot de passe d'un administrateur
Le code suivant permet de lancer une appli en tant qu'un autre utilisateur
Code : Tout sélectionner
ProcedureDLL Runas(Username.s,Domain.s,Password.s,CommandLine.s,Argument.s)
FlagErreur=1
*lpUserName = AllocateMemory(1000)
*lpDomainName = AllocateMemory(1000)
*lpPassword = AllocateMemory(1000)
*lpApplication = AllocateMemory(1000)
*lpCommandLine = AllocateMemory(1000)
lpProcessInfo.PROCESS_INFORMATION
lpStartUpInfo.STARTUPINFO
;convert ansi strings to unicode
; UserName
MultiByteToWideChar_(#CP_ACP, 0, Username, -1, *lpUserName, 1000)
; DomainOrLocalMachine
MultiByteToWideChar_(#CP_ACP, 0, Domain, -1, *lpDomainName, 1000)
; Password
MultiByteToWideChar_(#CP_ACP, 0, Password, -1, *lpPassword, 1000)
; Application a lancer
MultiByteToWideChar_(#CP_ACP, 0, CommandLine, -1, *lpApplication, 1000)
; Arguments
If Argument<>"" And Left(Argument,1)<>" " : Argument=" "+Argument:EndIf ; ajout espace
MultiByteToWideChar_(#CP_ACP, 0, Argument, -1, *lpCommandLine, 1000)
If OpenLibrary(0, "ADVAPI32.DLL")
*F = IsFunction(0, "CreateProcessWithLogonW")
If *F
If CallFunctionFast(*F, *lpUserName, *lpDomainName, *lpPassword, 0, *lpApplication,*lpCommandLine,0,0,0,@lpStartUpInfo,@lpProcessInfo) = 0
FlagErreur=0
EndIf
Else
FlagErreur=0
EndIf
CloseLibrary(0)
EndIf
ProcedureReturn FlagErreur
EndProcedure
Je voudrais faire la même chose en changeant de compte utilisateur le thread associé à l'exe .