Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ПарноеПрограммирование1.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include "iostream"
- #include <Windows.h>
- using namespace std;
- void menu1();
- void menu2();
- void menu3();
- void menu4();
- void menu5();
- void menu6();
- void menu7();
- void menu8();
- int _tmain(int argc, _TCHAR* argv[])
- {
- menu1();
- system("pause");
- system("cls");
- menu2();
- system("pause");
- system("cls");
- menu3();
- system("pause");
- system("cls");
- menu4();
- system("pause");
- system("cls");
- menu5();
- system("pause");
- system("cls");
- menu6();
- system("pause");
- system("cls");
- menu7();
- system("pause");
- system("cls");
- menu8();
- system("pause");
- return 0;
- }
- void menu1()
- {
- //GetLogicalDrivers
- int n;
- char dd[4];
- DWORD dr = GetLogicalDrives();
- for( int i = 0; i < 26; i++ )
- {
- n = ((dr>>i)&0x00000001);
- if( n == 1 )
- {
- dd[0] = char(65+i); dd[1] = ':'; dd[2] = '\\'; dd[3] = 0;
- cout << "Available disk drives : " << dd << endl;
- }
- }
- }
- void menu2()
- {
- DWORD dwSize = MAX_PATH;
- char szLogicalDrives[MAX_PATH] = {0};
- DWORD dwResult = GetLogicalDriveStrings(dwSize,(LPWSTR)szLogicalDrives);
- if (dwResult > 0 && dwResult <= MAX_PATH)
- {
- char* szSingleDrive = szLogicalDrives;
- while(*szSingleDrive)
- {
- printf("Drive: %s\n", szSingleDrive);
- // get the next drive
- szSingleDrive += strlen(szSingleDrive) + 1;
- }
- }
- }
- void menu3()
- {
- int d;
- d = GetDriveTypeA((LPCSTR)"C:\\");
- if( d == DRIVE_UNKNOWN ) cout << " UNKNOWN" << endl;
- if( d == DRIVE_NO_ROOT_DIR ) cout << " DRIVE NO ROOT DIR" << endl;
- if( d == DRIVE_REMOVABLE ) cout << " REMOVABLE" << endl;
- if( d == DRIVE_FIXED ) cout << " FIXED" << endl;
- if( d == DRIVE_REMOTE ) cout << " REMOTE" << endl;
- if( d == DRIVE_CDROM ) cout << " CDROM" << endl;
- if( d == DRIVE_RAMDISK ) cout << " RAMDISK" << endl;
- }
- void menu4()
- {
- char VolumeNameBuffer[100];
- char FileSystemNameBuffer[100];
- unsigned long VolumeSerialNumber;
- BOOL GetVolumeInformationFlag = GetVolumeInformationA((LPCSTR)
- "c:\\",
- VolumeNameBuffer,
- 100,
- &VolumeSerialNumber,
- NULL, //&MaximumComponentLength,
- NULL, //&FileSystemFlags,
- FileSystemNameBuffer,
- 100
- );
- if(GetVolumeInformationFlag != 0)
- {
- cout << " Volume Name is " << VolumeNameBuffer << endl;
- cout << " Volume Serial Number is " << VolumeSerialNumber << endl;
- cout << " File System is " << FileSystemNameBuffer << endl;
- }
- else cout << " Not Present (GetVolumeInformation)" << endl;
- }
- void menu5()
- {
- LPCWSTR pszDrive = NULL;
- BOOL test, fResult;
- __int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
- DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
- fResult = GetDiskFreeSpace(pszDrive,
- &dwSectPerClust,
- &dwBytesPerSect,
- &dwFreeClusters,
- &dwTotalClusters);
- printf("\nUsing GetDiskFreeSpace()...\n");
- printf("The return value: %d, error code: %d\n", fResult, GetLastError());
- printf("Sector per cluster = %ul\n", dwSectPerClust);
- printf("Bytes per sector = %ul\n", dwBytesPerSect);
- printf("Free cluster = %ul\n", dwFreeClusters);
- printf("Total cluster = %ul\n", dwTotalClusters);
- printf("Total free bytes = %ul\n", (dwFreeClusters*dwSectPerClust*dwBytesPerSect));
- }
- void menu6()
- {
- LPCWSTR szDirPath = L"c:\\testdir";
- if(!CreateDirectory(szDirPath, NULL))
- printf("\nCouldn't create %S directory.\n", szDirPath);
- else
- printf("\n%S directory successfully created.\n", szDirPath);
- }
- void menu7()
- {
- LPCWSTR szDirPath = L"c:\\testdir";
- if(RemoveDirectory(szDirPath) != 0)
- printf("\n%S directory successfully deleted.\n", szDirPath);
- else
- printf("\n%S directory deletion failed.\n", szDirPath);
- }
- void menu8()
- {
- HANDLE hFile;
- LPCWSTR fname = L"d:\\testfile.txt";
- hFile = CreateFile(fname, //file to be opened
- GENERIC_READ, //open for writing
- FILE_SHARE_READ, //share for writing
- NULL, //default security
- CREATE_ALWAYS, //create new file only
- FILE_ATTRIBUTE_ARCHIVE | SECURITY_IMPERSONATION,
- //archive and impersonate client
- NULL); //no attribute template
- if(hFile == INVALID_HANDLE_VALUE)
- printf("\nCould not open %S file, error %d)\n", fname, GetLastError());
- else
- {
- printf("\n%S file HANDLE is OK!\n", fname);
- printf("\n%S opened successfully!\n", fname);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement