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
 

Ian

Administrator
Joined
Feb 23, 2002
Messages
19,873
Reaction score
1,498
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:

 
Joined
Apr 20, 2023
Messages
2
Reaction score
0
you need to include the Windows header file and link against the Advapi32.lib library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top