国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C++ > 正文

C++卸載程序功能示例

2020-01-26 15:42:01
字體:
供稿:網(wǎng)友

注:在程序退出的時(shí)候?qū)懮?自己的卸載代碼。

復(fù)制代碼 代碼如下:

// FileName: Uninstall.h
#pragma once

class CUninstall
{
private:

    // Exe文件名
    CString m_strExeName;

    // Bat文件名
    CString m_strBatName;

public:

    // exe的路徑
    CString m_strExePath;

    // bat的路徑
    CString m_strBatPath;

    CString m_unInstallPath;

public:

    // 是否已經(jīng)復(fù)制到臨時(shí)文件夾
    bool GetState (void);

    // 初始化
    void Init (void);

    // 卸載程序
    void Uninstall (void);
public:
    CUninstall();
    ~CUninstall();
};

復(fù)制代碼 代碼如下:

// FileName: Uninstall.cpp

#include "stdafx.h"
#include "Uninstall.h"
#include <atlconv.h>
#include <locale.h>

CUninstall::CUninstall() : m_strExeName(_T("XABC01.exe")), m_strBatName(_T("XABC01.bat"))
{
    TCHAR strPath[MAX_PATH] = {0};
    GetTempPath(MAX_PATH, strPath);
    m_strExePath = strPath;
    m_strExePath += m_strExeName;

    memset(strPath, 0, MAX_PATH);
    GetTempPath(MAX_PATH, strPath);
    m_strBatPath = strPath;
    m_strBatPath += m_strBatName;
}

CUninstall::~CUninstall()
{

}

void CUninstall::Uninstall (void)
{
    // 獲取exe所在路徑
    CString strExePath;        // 臨時(shí)問價(jià)下exe文件所在路徑
    HMODULE hModule = NULL;
    TCHAR strPath[MAX_PATH] = {0};
    HKEY hKey;

    ::GetModuleFileName(hModule, strPath, MAX_PATH);
    strExePath = strPath;

    // 拷貝到臨時(shí)文件夾
    CopyFile(strExePath, m_strExePath, FALSE);

    int nIndex = strExePath.ReverseFind(_T('//'));
    strExePath = strExePath.Left(nIndex);
    m_unInstallPath = strExePath;
    HANDLE hande = CreateFile (m_strBatPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
    CloseHandle(hande);

    // 寫卸載批處理文件文件到磁盤
    CString strBuffer;
    strBuffer = _T(":repeat/ndel ");
    strBuffer += _T("/"") + m_strExeName + _T("/"/nif exist ");
    strBuffer += _T("/"") + m_strExeName + _T("/" goto repeat/n");
    strBuffer += _T("rd /s /q /"") + strExePath + _T("/"/n");
    strBuffer += _T("del /"") + m_strBatName + _T("/"");

    CStdioFile file;
    if (file.Open(m_strBatPath, CFile::modeWrite))
    {
        char* old_locale=_strdup(setlocale(LC_CTYPE,NULL) );
        setlocale( LC_CTYPE,"chs");

        file.WriteString(strBuffer);
        file.Close();

        setlocale( LC_CTYPE, old_locale ); //還原語(yǔ)言區(qū)域的設(shè)置
        free( old_locale );//還原區(qū)域設(shè)定
    }
    else
    {
        ::MessageBox (NULL, TEXT("文件寫入磁盤失敗!"), TEXT(""), MB_OK|MB_ICONEXCLAMATION);
    }
}

bool CUninstall::GetState (void)
{
    if (PathFileExists(m_strBatPath))
    {
        return true;
    }
    else
    {
        return false;
    }
}

void CUninstall::Init (void)
{

}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 崇阳县| 建瓯市| 乐昌市| 刚察县| 新龙县| 永德县| 镇远县| 清徐县| 永平县| 密山市| 奉节县| 攀枝花市| 年辖:市辖区| 大丰市| 改则县| 洪雅县| 泾川县| 区。| 佛教| 克什克腾旗| 鹿泉市| 丹凤县| 保康县| 东乡族自治县| 锦屏县| 洛南县| 确山县| 江华| 仙桃市| 泌阳县| 崇明县| 嘉鱼县| 陆川县| 池州市| 清苑县| 郧西县| 福鼎市| 郧西县| 郧西县| 徐汇区| 资溪县|