复制程序,获取系统信息

来源:互联网 发布:人工智能ppt 编辑:程序博客网 时间:2024/05/29 05:55
#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;
              
     }
    
}
原创粉丝点击