Home > Software engineering > On the outside of the service using CreateProcessAsUser running EXE can't create a shortcut
On the outside of the service using CreateProcessAsUser running EXE can't create a shortcut
Time:09-27
In service program using CreateProcessAsUser run external EXE cannot create desktop shortcuts and start menu bar shortcut, other directory file to read and write is no problem, interact with the desktop is also no problem, Is not the problem of external EXE, direct manually run external EXE didn't appear these problems, The following is the code:
HANDLE hToken; //create a snapshot process PROCESSENTRY32 pe32={0}; Pe32. DwSize=sizeof (pe32); HANDLE hSnapShot=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0); If (hSnapShot!=0 & amp; & HSnapShot!=INVALID_HANDLE_VALUE) { BOOL bRet=Process32FirstW (hSnapShot, & amp; Pe32); While (bRet) { If (_tcsicmp (pe32 szExeFile, L "Explorer. EXE")==0) { HANDLE hProcess=OpenProcess (PROCESS_ALL_ACCESS, false, pe32 th32ProcessID);
If (hProcess!=NULL) { BOOL flag=OpenProcessToken (hProcess, TOKEN_ALL_ACCESS, & amp; HToken); The CloseHandle (hProcess); } break; } BRet=Process32Next (hSnapShot, & amp; Pe32); } The CloseHandle (hSnapShot); }
STARTUPINFO si={sizeof (si)}; PROCESS_INFORMATION PI; //TCHAR FileName [256] external EXE the full path of the BOOL bSuccess=CreateProcessAsUser (hToken, FileName, NULL, NULL, NULL, FALSE, NULL, NULL, NULL, & amp; Si, & amp; PI);