Problème avec LogonUser

cs_Corwin01 Messages postés 7 Date d'inscription jeudi 18 mars 2004 Statut Membre Dernière intervention 29 juin 2004 - 29 juin 2004 à 11:36
cs_Corwin01 Messages postés 7 Date d'inscription jeudi 18 mars 2004 Statut Membre Dernière intervention 29 juin 2004 - 29 juin 2004 à 11:39
Voila je ne sais plus comment faire , ca fait une matinée complète que je perd je n'arrive pas à lancer un exe sous un profile different , aidez moi svp...

ZeroMemory(&StartInfos,sizeof(STARTUPINFO));
StartInfos.cb = sizeof(STARTUPINFO);
StartInfos.lpReserved = NULL;
StartInfos.lpReserved2 = NULL;
StartInfos.cbReserved2 = 0;
StartInfos.lpDesktop = NULL;
StartInfos.wShowWindow = SW_SHOW;
char SysDir[256];
GetSystemDirectory(SysDir,256);
StartInfos.dwFlags = 0;
StartInfos.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;

StartInfos.wShowWindow = SW_SHOW;

int ilogon= LogonUser("administrateur",".","dede",LOGON32_LOGON_BATCH,LOGON32_PROVIDER_DEFAULT,&Token);
DWORD dwErr;
SECURITY_ATTRIBUTES aqqa;
aqqa.bInheritHandle=false;

int iDuplica=DuplicateToken(Token,MAXIMUM_ALLOWED, NULL, SecurityImpersonation,TokenPrimary,&hToken2);

windowsIdentity = new WindowsIdentity(hToken2);
impersonationContext = windowsIdentity.Impersonate();
int iLance=CreateProcessAsUser(hToken2, NULL, "cmd.exe", NULL, NULL, false,0, NULL,SysDir, (LPSTARTUPINFO)&StartInfos, (LPPROCESS_INFORMATION)&Proc_Infos);
dwErr= GetLastError();

LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwErr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL );

AfxMessageBox( (LPCTSTR)lpMsgBuf );
WaitForSingleObject (hToken2, INFINITE);


CloseHandle(Token);
CloseHandle(hToken2);

1 réponse

cs_Corwin01 Messages postés 7 Date d'inscription jeudi 18 mars 2004 Statut Membre Dernière intervention 29 juin 2004
29 juin 2004 à 11:39
ps : oubliez les deux lignes :
windowsIdentity = new WindowsIdentity(hToken2);
impersonationContext = windowsIdentity.Impersonate();
elles ne servent à rien
sinon le logonuser fonctionne
mais pas le CreateProcessAsUser
message : "le client ne dispose pas d'un privilège nécessaire"
Je sais plus quoi faire ......
0
Rejoignez-nous