複製程序,獲取系統信息

#include <stdio.h>
#include <iostream>
#include <windows.h>
using namespace std;

//複製當前運行的程序到系統目錄下
void CopySelf();
//獲取系統相關信
void GetSysInfo();
int main()
{
//CopySelf();
  GetSysInfo();
return 0;
}


void CopySelf()
{
     char szSelfName[MAX_PATH] = {0};
     char szWindowsPath[MAX_PATH] = {0};
     char szSystemPath[MAX_PATH] = {0};
     char szTmpPath[MAX_PATH] = {0};

     //獲取當前程序自身路徑
     GetModuleFileName(NULL,szSelfName,MAX_PATH);
     cout<<"szSelfName:"<<szSelfName<<endl;

     //獲取系統目錄
     GetWindowsDirectory(szWindowsPath,MAX_PATH);
     cout<<"szWindowsPath:"<<szWindowsPath<<endl;

     //獲取windows目錄
     GetSystemDirectory(szSystemPath,MAX_PATH);
     cout<<"szSystemPath:"<<szSystemPath<<endl;

     strcat(szWindowsPath,"\\mynona.exe");
     strcat(szSystemPath,"\\mynona.exe");

     //cout<<"szWindowsPath:"<<szWindowsPath<<endl;
     //cout<<"szSystemPath:"<<szSystemPath<<endl;

     int isTrue = CopyFile(szSelfName,szWindowsPath,FALSE);//FALSE表示強行覆蓋原有文件
     int isTrue2 = CopyFile(szSelfName,szSystemPath,FALSE);

     cout<<"操作結果:"<<isTrue<<"  "<<isTrue2<<endl;
}

void GetSysInfo()
{
     char szComputerName[MAXBYTE] = {0};
     char szUserName[MAXBYTE] = {0};
     unsigned long nSize = MAXBYTE;
     OSVERSIONINFO OsVer;

     OsVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     GetVersionEx(&OsVer);

     if(OsVer.dwPlatformId == VER_PLATFORM_WIN32_NT)
     {
          if(OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 1)
          {
               cout<<"Widows XP "<<OsVer.dwMinorVersion<<endl;
          }else if(OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 0)
          {
               cout << "Windows 2K"<<endl;
          }else
          {
               cout<<"Other System"<<endl;
          }

          GetComputerName(szComputerName,&nSize);
          cout<<"Computer Name is "<< szComputerName<<endl;

          nSize = MAXBYTE;
          GetUserName(szUserName,&nSize);
          cout<< "User Name is "<<szUserName<<endl;
              
     }
    
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章