#include "stdio.h" #include "shlwapi.h" void RemoveNewLine (char* str) { char* pos = strrchr(str,'\n'); if (pos) *pos = '\0'; } int main(int argc, char *argv[]) { // Get command line argument if (argc < 2) return 0; if (stricmp(argv[1],"/s")) return 0; // Init vars char config_file[MAX_PATH] = ""; char command[MAX_PATH] = ""; char args[MAX_PATH] = ""; // Get own path and set config_file GetModuleFileName (NULL,config_file,MAX_PATH); PathRemoveExtension (config_file); strcat (config_file,".cfg"); // Read config file FILE* file = fopen (config_file,"r") ; if (file == NULL) { MessageBox (NULL,"Error opening config file",NULL,0); return 1; } fgets (command,MAX_PATH,file); RemoveNewLine (command); fgets (args,MAX_PATH,file); RemoveNewLine (args); // Run process PROCESS_INFORMATION processInformation; STARTUPINFO startupInfo; memset ( &processInformation,0,sizeof (processInformation) ); memset ( &startupInfo,0,sizeof (startupInfo) ); if ( !CreateProcess (command,args,NULL,NULL,0,CREATE_NO_WINDOW,NULL,NULL,&startupInfo,&processInformation) ) { MessageBox (NULL,"ERROR: Create Process failed!",NULL,0); return 1; } // Wait until child process exits. WaitForSingleObject (processInformation.hProcess,INFINITE); // Close process and thread handles. CloseHandle (processInformation.hProcess); CloseHandle (processInformation.hThread); }
c:\windows\system32\cscript.exe
cscript.exe c:\windows\winexec.vbs
'Create common objects Set WshShell = CreateObject("WScript.Shell") Set WshNetwork = CreateObject("WScript.NetWork") 'Set common variables username = WshNetwork.UserName title = " " & " " & username text = " ?" 'Run logout dialog Button = WshShell.Popup(text,,title,36) 'Check answer If Button <> 6 Then Wscript.Quit 'Force logoff if "Yes" WshShell.Run "shutdown.exe -l",,true
i586-mingw32msvc-gcc -mwindows -s winexec.cpp -o winexec.scr -lshlwapi
i586-mingw32msvc-gcc -mwindows -s winexec.cpp -o winexec.scr -lshlwapi
Archlinux: i486-mingw32-gcc -mwindows -s winexec.cpp -o winexec.scr -lshlwapi
Source: https://habr.com/ru/post/115730/
All Articles