vc编程初学者教程(VC编程实现KMS激活工具)

最近微软上架了一款KMS激活工具。引来很多人围观讨论。

这里就用VC编程来实现类似的工具。其中激活服务器需要自己搭建或者别人搭建好的。密钥则来自微软的官方网站。用到的脚本请参考:如何使用kms激活服务器

先看一下界面

vc编程初学者教程(VC编程实现KMS激活工具)(1)

vc编程初学者教程(VC编程实现KMS激活工具)(2)

vc编程初学者教程(VC编程实现KMS激活工具)(3)

关键代码:

将kms服务器地址写入kmssvr.txt文件中

void CKMSSvrDlg::SaveKMSSvr() { TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("kmssvr.txt")); CStdioFile file; file.Open(FilePath, CFile::modeCreate | CFile::modeWrite); file.SeekToBegin(); UpdateData(true); for (int i = 0; i < m_ctrlKMSAddrList.GetCount(); i ) { CString strContent; m_ctrlKMSAddrList.GetText(i, strContent); strContent = strContent _T("\n"); file.WriteString(strContent); } file.Close(); } void CKMSSvrDlg::ReadKMSSvr() { TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("kmssvr.txt")); CStdioFile file; file.Open(FilePath, CFile::modeRead); file.SeekToBegin(); CString strContent; while (file.ReadString(strContent)) { m_ctrlKMSAddrList.AddString(strContent); } file.Close(); UpdateData(false); }

将windows激活密钥写入key.txt文件中

void CKMSKeyDlg::SaveKEY() { TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("key.txt")); CStdioFile file; file.Open(FilePath, CFile::modeCreate | CFile::modeWrite); file.SeekToBegin(); UpdateData(true); for (int i = 0; i < m_ctrlKeyList.GetCount(); i ) { CString strContent; m_ctrlKeyList.GetText(i, strContent); strContent = strContent _T("\n"); file.WriteString(strContent); } file.Close(); } void CKMSKeyDlg::ReadKEY() { TCHAR FilePath[MAX_PATH]; GetModuleFileName(NULL, FilePath, MAX_PATH); (_tcsrchr(FilePath, '\\'))[1] = 0; lstrcat(FilePath, _T("key.txt")); CStdioFile file; file.Open(FilePath, CFile::modeRead); file.SeekToBegin(); CString strContent; while (file.ReadString(strContent)) { m_ctrlKeyList.AddString(strContent); } file.Close(); UpdateData(false); }

激活Windows代码

void CKMSMainDlg::OnBnClickedButtonRunActivation() { CString strParam; CString strSKMS; int iCurSel; iCurSel = m_ctrlKMSSvrList.GetCurSel(); m_ctrlKMSSvrList.GetLBText(iCurSel, strParam); strSKMS = _T("/skms ") strParam; RunAsAdmin(NULL, _T("slmgr.vbs"), strSKMS.GetBuffer()); strSKMS.ReleaseBuffer(); CString strIPK; iCurSel = m_ctrlKeyList.GetCurSel(); m_ctrlKeyList.GetLBText(iCurSel, strParam); CString strPos = _T("|"); int nPos = strParam.Find(strPos); if (nPos != -1) { strParam = strParam.Right(strParam.GetLength() - nPos - 1); } strIPK = _T("/ipk ") strParam; RunAsAdmin(NULL, _T("slmgr.vbs"), strIPK.GetBuffer()); strIPK.ReleaseBuffer(); strParam.Format(_T("/ato")); RunAsAdmin(NULL, _T("slmgr.vbs"), strParam.GetBuffer()); strParam.ReleaseBuffer(); }

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页