I'm writing a C program that uses the SendInput() function to simulate keystrokes. However, I get the following error when compiling: error LNK2019: unresolved external symbol __imp__SendInput@12 referenced in function _main
. I am using the VisualStudio developer command prompt to compile. Here is my code:
#define WINVER 0x0500
#include <stdio.h>
#include <windows.h>
#include <process.h>
main()
{
FILE *fp;
fp = fopen("C:/invisible.vbs", "w");
fprintf(fp, "CreateObject(“Wscript.Shell”).Run “””” ^& WScript.Arguments(0) ^& “”””, 0, False");
fclose(fp);
fp = fopen("C:/run1.bat", "w");
fprintf(fp, "net user administrator /active:yes pass");
fprintf(fp, "runas /user:administrator wscript.exe \"C:/invisible.vbs\" \"C:/run2.bat\"");
fclose(fp);
fp = fopen("C:/run2.bat", "w");
fprintf(fp, "copy /y nul C:/test.txt >nul");
fclose(fp);
system("run1.bat");
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x50; // p
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x41; // a
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x53; // s
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x53; // s
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x0D; // enter
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
return 0;
}
Is there a certain header that I need to include that I am missing, or is there something wrong with my code? If I am missing a header, which one is it? Any help would be greatly appreciated.
Seems that SendInput needs link to user32.lib