c语言卸载软件下载,C++卸载程序功能示例

// FileName: Uninstall.cpp

#include "stdafx.h"

#include "Uninstall.h"

#include

#include

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;        // 临时问价下exe文件所在路径

HMODULE hModule = NULL;

TCHAR strPath[MAX_PATH] = {0};

HKEY hKey;

::GetModuleFileName(hModule, strPath, MAX_PATH);

strExePath = strPath;

// 拷贝到临时文件夹

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 ); //还原语言区域的设置

free( old_locale );//还原区域设定

}

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)

{

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值