Professional Documents
Culture Documents
#include<Windows.h>
#include <string>
#include<fstream>
#include <tchar.h>
#include<iomanip>
using namespace std;
#define BUFFER_SIZE 1024
#define COPY_SIZE 512
static ULARGE_INTEGER lastCPU, lastSysCPU, lastUserCPU;
static int numProcessors;
static HANDLE self;
//function for getting the current process in the cpu
double getCurrentValue(){
FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user;
double percent;
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
percent = (sys.QuadPart - lastSysCPU.QuadPart) + (user.QuadPart - lastUserCPU.QuadPart);
percent /= (now.QuadPart - lastCPU.QuadPart);
percent /= numProcessors;
lastCPU = now;
lastUserCPU = user;
lastSysCPU = sys;
return percent * 100;
}
//indicate to the user that the file julius.txt has been created successfully
cout << "The file Julius.txt has been created!!\nPress any key to continue\n";
};break;
case 2:
{
//code to open the file named julius.txt
ofstream myfile;
myfile.open("Julius.txt");
//writting to the open file
myfile << "This statement has been written by the program!!";
//close and save the statement written to the file
myfile.close();
//indicate to the user that the statement was successfully written to the file
cout << "The statement has been written to the file\n\n";
/*BOOL mat;
char dataw[] = "i am awesome";
DWORD dwwhat = (DWORD)strlen(dataw);
DWORD dwBytesWritten = 0;
mat = WriteFile (MATH,dataw,dwwhat,&dwBytesWritten,NULL);*/
};
break;
case 3:
{
//code to delete the file in the specified file location
system("del E:\kimson_project\case_code\case_code\Julius.txt");
/*LPCWSTR m = TEXT("Julius.txt");
DeleteFile (m);*/
};break;
}
};
break;
case 2:
{
//tasks that can be conducted in process manipulation
cout<<"You can do the following Process control tasks\n";
cout<<"===============================================\n";
cout<<"1 Create a process ..run firefox application \n";
cout<<"2 Create a process...run a notepad application \n";
cout<<"=========================== \n";
cout<<"what is your choice? \n";
cin>>y;
switch (y)
{
case 1:
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL sam;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
//run the firefox application already installed in the machine
system("start firefox.exe");
/*if (!
CreateProcess
(
TEXT("C:\Program Files\Mozilla Firefox\firefox.exe"), NULL, NULL, NULL, FALSE,
CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)
)
{
cout << "Unable to execute."<<endl;
}*/
//system("pause");
};break;
case 2:
{
//void main()
{
//run the notepad application
system("start notepad.exe");
}
};break;
}
};
break;
case 3:
{
cout<<"You can do the following Information Maintenace tasks\n";
cout<<"======================================================\n";
cout<<"1 Get current process ID in a notepad \n";
cout<<"2 Sleep a process and get the amount of time it has slept \n";
cout<<"========================================================= \n";
cout<<"what is your choice? \n";
cin>>y;
switch (y)
{
case 1:
{
//get the id of the process currently running
DWORD id = GetCurrentProcessId();
case 5:
{
//tasks in CPU management
cout<<"You can do the following under CPU management\n";
cout<<"=============================================\n";
cout<<"1 Get the processes currently in the CPU \n";
cout<<"2 Get total virtual memory \n";
cout<<"========================== \n";
cout<<"what is your choice? \n";
cin>>y;
switch (y)
{
case 1:
{
//get and display all processes and even background processes
system("tasklist");
char a;
cin >> a;
};break;
case 2:
{
//total virtual memory
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
DWORDLONG totalVirtualMem = memInfo.ullTotalPageFile;
};break;
}
};break;
case 6:
{
//log out of the system
ExitWindows(0,0);
};break;
}
}while(x!=5);
return 0;
}