zoukankan      html  css  js  c++  java
  • mfc 创建桌面快捷方式&删除

    /// <summary>
    /// 删除快捷方式
    /// </summary>
    /// <param name="strName"></param>
    /// <returns></returns>
    BOOL DeleteDesktopShotCut(CString strName) {
    	char Path[MAX_PATH + 1];
    	CString strDestDir;
    	int i = CSIDL_DESKTOPDIRECTORY;
    	LPITEMIDLIST pidl;
    	LPMALLOC pShell;
    	if (SUCCEEDED(SHGetMalloc(&pShell)))
    	{
    		if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, i, &pidl)))
    		{
    			if (!SHGetPathFromIDList(pidl, Path))
    			{
    				pShell->Free(pidl);
    				::CoUninitialize();
    				return FALSE;
    			}
    			pShell->Release();
    			strDestDir.Format("%s", Path);
    			strDestDir += "\";
    			strDestDir += strName;//设置桌面快捷方式的名字
    			strDestDir += ".lnk";
    
    			DeleteFile(strDestDir);
    		}
    	}
    }
    
    BOOL CreateUninstall(string displayName, string uninstallExePath, string modifyPath,
    	string displayVersion,
    	string icoPath, string installPath, string publisher, string company, string helpLink,
    	string helpTelephone, string urlInfoAbout)
    {
    	bool result = true;
    	HKEY hKey = nullptr;
    	string key = GetUninstallKey() + displayName;
    	//string key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + displayName;
    	//string key = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Test";
    	if (ERROR_SUCCESS != RegCreateKey(HKEY_LOCAL_MACHINE, key.c_str(), &hKey))
    	{
    		return false;
    	}
    
    	//先创建可选项(不影响必选项创建结果)
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "DisplayVersion", displayVersion));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "DisplayIcon", icoPath));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "Publisher", publisher));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "RegCompany", company));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "HelpLink", helpLink));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "HelpTelephone", helpTelephone));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "URLInfoAbout", urlInfoAbout));
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "InstallLocation", installPath));
    	/*if (modifyPath != "") {
    		string modifyStr = modifyPath + " " + CONST_UPGRADE;
    
    		result = (ERROR_SUCCESS == RegWriteString(hKey, "ModifyPath", modifyStr));
    	}*/
    
    
    	//必选项
    	result = (ERROR_SUCCESS == RegWriteString(hKey, "DisplayName", displayName, false));
    
    	if (uninstallExePath != "") {
    		string uninstallStr = uninstallExePath + " " + CONST_UNINSTALL;
    		result = (ERROR_SUCCESS == RegWriteString(hKey, "UninstallString", uninstallStr, false));
    	}
    
    
    
    	//EstimatedSize
    	RegCloseKey(hKey);
    
    	return result;
    }
    
    
    留待后查,同时方便他人
    联系我:renhanlinbsl@163.com
  • 相关阅读:
    TestNG DataProvider的几种方法写法
    ruby操作EXCEL的简单示例
    QTP的tsr对象库文件转换成XML
    Ruby对时间的处理
    java读取YAML文件
    ruby遍历文件夹
    ruby操作excel文件
    [转载]利用ruby的Net::HTTP发起http请求并对返回包进行简单的校验
    QTP连接MySQL (转载)
    Ruby 冒泡排序
  • 原文地址:https://www.cnblogs.com/ives/p/14900141.html
Copyright © 2011-2022 走看看