copy文件夹,通过C++读取系统、用户名以及计算机名的方法

将编译的exe文件copy到d盘,如果有重名的则名字加上2.exe在copy到D盘

#include <Windows.h>
void copyself()
{
    char szselfname[MAX_PATH]={0};
    char szwindowspath[MAX_PATH]={0};
    bool s;
     GetModuleFileName(NULL,szselfname,MAX_PATH);
//     GetWindowsDirectory(szwindowspath,MAX_PATH);
//     GetSystemDirectory(szsystempath,MAX_PATH);
//     strcat(szwindowspath,"\\backdoor.exe");
//     strcat(szsystempath,"\\backdoor.exe");
    strcat(szwindowspath,"D:\\shit.exe");
//     CopyFile(szselfname,szwindowspath,FALSE);
     bool m=CopyFile(szselfname,szwindowspath,TRUE);
    while(m!=true)
    {
    strcat(szwindowspath,"2.exe");
    m=CopyFile(szselfname,szwindowspath,TRUE);

    }
        
}


查看系统信息,用户名,计算机名

#include <Windows.h>
#include <stdio.h>
void getversion()
{
    char szcom[MAXBYTE]={0};
    char szuserna[MAXBYTE]={0};
    unsigned long nsize=MAXBYTE;
    OSVERSIONINFO osver;
    osver.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
    GetVersionEx(&osver);
    if(osver.dwPlatformId == 2)   
    {       
        if(osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1)      
        {          
            printf("xp\n"); 
        }       
        if(osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2)
        {              
            printf("windows 2003\n");   
        }       
        if(osver.dwMajorVersion ==  6 && osver.dwMinorVersion == 0)  
        {        
            printf("vista and 2008\n");  
        }   
        if(osver.dwMajorVersion ==  6 && osver.dwMinorVersion == 1)   
        {          
            printf("2008 R2 and Windows 7\n");   
        }     
    }     
    GetComputerName(szcom,&nsize);
    GetUserName(szuserna,&nsize);
    printf("computer name is %s \n username is %s",szcom,szuserna);

}

 

 

posted on 2013-11-22 23:12  xds1224  阅读(541)  评论(0编辑  收藏  举报

导航