zoukankan      html  css  js  c++  java
  • 复制程序,获取系统信息

    #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;
                  
         }
        
    }
  • 相关阅读:
    vue语法 `${ }` (模版字符串)
    Apache HttpClient工具类
    JS —— 数组去重
    HTML5——新增的API
    HTML5——新特性
    HTML5——Svg
    HTML5——多媒体(Audio音频、Video视频)
    CSS3——transform
    CSS3——animation中的属性--steps
    CSS3——动画transition、animation
  • 原文地址:https://www.cnblogs.com/mynona/p/3162641.html
Copyright © 2011-2022 走看看