Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. // ПарноеПрограммирование1.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. #include <Windows.h>
  7. using namespace std;
  8.  
  9. void menu1();
  10. void menu2();
  11. void menu3();
  12. void menu4();
  13. void menu5();
  14. void menu6();
  15. void menu7();
  16. void menu8();
  17.  
  18. int _tmain(int argc, _TCHAR* argv[])
  19. {
  20. menu1();
  21. system("pause");
  22. system("cls");
  23. menu2();
  24. system("pause");
  25. system("cls");
  26. menu3();
  27. system("pause");
  28. system("cls");
  29. menu4();
  30. system("pause");
  31. system("cls");
  32. menu5();
  33. system("pause");
  34. system("cls");
  35. menu6();
  36. system("pause");
  37. system("cls");
  38. menu7();
  39. system("pause");
  40. system("cls");
  41. menu8();
  42. system("pause");
  43. return 0;
  44. }
  45.  
  46. void menu1()
  47. {
  48. //GetLogicalDrivers
  49. int n;
  50. char dd[4];
  51. DWORD dr = GetLogicalDrives();
  52.  
  53. for( int i = 0; i < 26; i++ )
  54. {
  55. n = ((dr>>i)&0x00000001);
  56. if( n == 1 )
  57. {
  58. dd[0] = char(65+i); dd[1] = ':'; dd[2] = '\\'; dd[3] = 0;
  59. cout << "Available disk drives : " << dd << endl;
  60. }
  61. }
  62. }
  63.  
  64. void menu2()
  65. {
  66. DWORD dwSize = MAX_PATH;
  67. char szLogicalDrives[MAX_PATH] = {0};
  68. DWORD dwResult = GetLogicalDriveStrings(dwSize,(LPWSTR)szLogicalDrives);
  69.  
  70. if (dwResult > 0 && dwResult <= MAX_PATH)
  71. {
  72. char* szSingleDrive = szLogicalDrives;
  73. while(*szSingleDrive)
  74. {
  75. printf("Drive: %s\n", szSingleDrive);
  76.  
  77. // get the next drive
  78. szSingleDrive += strlen(szSingleDrive) + 1;
  79. }
  80. }
  81. }
  82.  
  83. void menu3()
  84. {
  85. int d;
  86. d = GetDriveTypeA((LPCSTR)"C:\\");
  87. if( d == DRIVE_UNKNOWN ) cout << " UNKNOWN" << endl;
  88. if( d == DRIVE_NO_ROOT_DIR ) cout << " DRIVE NO ROOT DIR" << endl;
  89. if( d == DRIVE_REMOVABLE ) cout << " REMOVABLE" << endl;
  90. if( d == DRIVE_FIXED ) cout << " FIXED" << endl;
  91. if( d == DRIVE_REMOTE ) cout << " REMOTE" << endl;
  92. if( d == DRIVE_CDROM ) cout << " CDROM" << endl;
  93. if( d == DRIVE_RAMDISK ) cout << " RAMDISK" << endl;
  94. }
  95.  
  96. void menu4()
  97. {
  98. char VolumeNameBuffer[100];
  99. char FileSystemNameBuffer[100];
  100. unsigned long VolumeSerialNumber;
  101.  
  102. BOOL GetVolumeInformationFlag = GetVolumeInformationA((LPCSTR)
  103. "c:\\",
  104. VolumeNameBuffer,
  105. 100,
  106. &VolumeSerialNumber,
  107. NULL, //&MaximumComponentLength,
  108. NULL, //&FileSystemFlags,
  109. FileSystemNameBuffer,
  110. 100
  111. );
  112.  
  113. if(GetVolumeInformationFlag != 0)
  114. {
  115. cout << " Volume Name is " << VolumeNameBuffer << endl;
  116. cout << " Volume Serial Number is " << VolumeSerialNumber << endl;
  117. cout << " File System is " << FileSystemNameBuffer << endl;
  118. }
  119. else cout << " Not Present (GetVolumeInformation)" << endl;
  120. }
  121.  
  122. void menu5()
  123. {
  124. LPCWSTR pszDrive = NULL;
  125. BOOL test, fResult;
  126.  
  127. __int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
  128. DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
  129. fResult = GetDiskFreeSpace(pszDrive,
  130. &dwSectPerClust,
  131. &dwBytesPerSect,
  132. &dwFreeClusters,
  133. &dwTotalClusters);
  134.  
  135. printf("\nUsing GetDiskFreeSpace()...\n");
  136. printf("The return value: %d, error code: %d\n", fResult, GetLastError());
  137. printf("Sector per cluster = %ul\n", dwSectPerClust);
  138. printf("Bytes per sector = %ul\n", dwBytesPerSect);
  139. printf("Free cluster = %ul\n", dwFreeClusters);
  140. printf("Total cluster = %ul\n", dwTotalClusters);
  141. printf("Total free bytes = %ul\n", (dwFreeClusters*dwSectPerClust*dwBytesPerSect));
  142. }
  143.  
  144. void menu6()
  145. {
  146. LPCWSTR szDirPath = L"c:\\testdir";
  147. if(!CreateDirectory(szDirPath, NULL))
  148. printf("\nCouldn't create %S directory.\n", szDirPath);
  149. else
  150. printf("\n%S directory successfully created.\n", szDirPath);
  151. }
  152.  
  153. void menu7()
  154. {
  155. LPCWSTR szDirPath = L"c:\\testdir";
  156. if(RemoveDirectory(szDirPath) != 0)
  157. printf("\n%S directory successfully deleted.\n", szDirPath);
  158. else
  159. printf("\n%S directory deletion failed.\n", szDirPath);
  160. }
  161.  
  162. void menu8()
  163. {
  164. HANDLE hFile;
  165. LPCWSTR fname = L"d:\\testfile.txt";
  166. hFile = CreateFile(fname, //file to be opened
  167. GENERIC_READ, //open for writing
  168. FILE_SHARE_READ, //share for writing
  169. NULL, //default security
  170. CREATE_ALWAYS, //create new file only
  171. FILE_ATTRIBUTE_ARCHIVE | SECURITY_IMPERSONATION,
  172. //archive and impersonate client
  173. NULL); //no attribute template
  174. if(hFile == INVALID_HANDLE_VALUE)
  175. printf("\nCould not open %S file, error %d)\n", fname, GetLastError());
  176. else
  177. {
  178. printf("\n%S file HANDLE is OK!\n", fname);
  179. printf("\n%S opened successfully!\n", fname);
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement