Windows 10 Error: 'CreateProcessWithTokenW' was not declared in this scope

Joined
Mar 16, 2023
Messages
1
Reaction score
0
Hi all,

I'm trying to code program c++ for create process from token. but when I compile this code, it return the error 'CreateProcessWithTokenW' was not declared in this scope. My code as below:

#include <windows.h>
#include <iostream>
int main(int argc, char * argv[]) {
char a;
LoadLibrary((LPCWSTR("ADVAPI32.dll")));
HANDLE processHandle;
HANDLE tokenHandle = NULL;
HANDLE duplicateTokenHandle = NULL;
STARTUPINFOW startupInfo;
PROCESS_INFORMATION processInformation;
DWORD PID_TO_IMPERSONATE = 3060;
wchar_t cmdline[] = L"C:\\shell.cmd";
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
ZeroMemory(&processInformation, sizeof(PROCESS_INFORMATION));
startupInfo.cb = sizeof(STARTUPINFO);
processHandle = OpenProcess(PROCESS_ALL_ACCESS, true, PID_TO_IMPERSONATE);
OpenProcessToken(processHandle, TOKEN_ALL_ACCESS, &tokenHandle);
DuplicateTokenEx(tokenHandle, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &duplicateTokenHandle);
CreateProcessWithTokenW(duplicateTokenHandle, LOGON_WITH_PROFILE, NULL, cmdline, 0, NULL, NULL, &startupInfo, &processInformation);

std::cin >> a;
return 0;
}

do you know how to fix this error?
thank you so much
 
I don't really understand C++, but this may be a good opportunity to try the AI Bot we've got on here, as it works well with code. You could try posting the question here:

 
you need to include the Windows header file and link against the Advapi32.lib library.
 
Back
Top