• 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
  • 相关阅读:
    托管资源和非托管资源
    无法启动IIS EXpress Web服务器
    SQL 最后一天及第一天
    amchart amline中配置文件amline_settings.xml文件中的配置说明
    SpringBoot添加拦截器
    Lombok插件
    SpringBoot配置访问静态资源
    SpringBoot自动配置原理
    yaml基本格式
    属性文件之SpringBoot注入
  • 原文地址:https://www.cnblogs.com/ives/p/14900141.html
Copyright © 2020-2023  润新知