Click here to Skip to main content
15,891,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to set the name of my local host. I am using sethostname() function but I get an error as follows:
error C3861: 'sethostname': identifier not found.
Below is the code snippet:

C#
WSADATA wsa;
///Initialise winsock///
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
   {
      //Socket Initialization Failed///
      exit(EXIT_FAILURE);
   }
 char setname[128]="Ayesha-PC";
 sethostname(setname, sizeof (setname));
Posted

Are you looking for SetComputerNameEx[^]?
 
Share this answer
 
Comments
ayesha hassan 11-Apr-13 8:06am    
Thank you for the help, but this function changes the name of PC after the system is restarted while I want to change the name as soon as the function is called.
According to the winsock documentation[^] there is no such function.
 
Share this answer
 
You probably have seen that as example in a Unix-based application. There the function sethostname exists, (although it would be called with strlen (name) as second argument, and not with sizeof (name).

For an equivalent in the Windows world, CPallini has given you already the correct link.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900