I have code that gets the IP address of a remote PC as a char. Now i need to use this IP Address. I want to run system("START \\\\IP\C$"). Does anyone have any ideas how i can go about implementing this?
int main()
{
GetHostIP();
system("PAUSE");
}
void GetHostIP()
{
char *Ip;
WSADATA wsaData;
struct hostent *pHostEnt;
struct sockaddr_in tmpSockAddr; //placeholder for the ip address
// Not needed if it is already taken care by some other part of the application
WSAStartup(MAKEWORD(2,0),&wsaData);
char hostname[25];
strcpy(hostname,"PC1");
//This will retrieve the ip details and put it into pHostEnt structure
pHostEnt = gethostbyname(hostname);
if(pHostEnt == NULL)
{
printf("Error occured: %s\n",GetLastError());
return;
}
memcpy(&tmpSockAddr.sin_addr,pHostEnt->h_addr,pHostEnt->h_length);
Ip = NULL;
Ip = newchar[17];
strcpy(Ip,inet_ntoa(tmpSockAddr.sin_addr));
std::cout << Ip;
// Not needed if it is already taken care by some other part of the application
WSACleanup();
delete [] Ip;
}
Its hard to explain. There are multiple environments that are used. Using the IP address is safer because sometimes using the host name will use the IP address from the environment previously used.
The OS is just goint to use gethostbyname just like you. So if you can't use the UNC name in your environment because of DNS/WINS problems, you'll have the same issues in your app.
The program now connects to the network pc using system("START \\pc1\c$") and it prompts for the username and password. Is there a way to pass the username and password in the program instead of the user having to manually enter it?