/// <summary> /// Called when [uninstall software]. /// </summary> /// <param name="UninstallString">The uninstall string.</param> /// <returns>json object.if successful return a array of Software match UninstallString registry key we try to uninstall them else return error</returns> public OnGetSoftwareListResponse OnUninstallSoftware(string UninstallString) { OnGetSoftwareListResponse JOnUninstallSoftware = new OnGetSoftwareListResponse(); try { _m_File_Manager mfm = new _m_File_Manager(); OnGetSoftwareListResponse JAllSoftwareFind = OnSerachSoftware("UninstallString", UninstallString); JOnUninstallSoftware = JAllSoftwareFind; foreach (OnGetSoftwareListResponse.Software JTarget in JAllSoftwareFind.software) { string InstallLocation = ""; if (JTarget.InstallLocation != null) { InstallLocation = JTarget.InstallLocation; } else//extract InstallLocation from UninstallString { InstallLocation = GetPathFromFullPath(UninstallString); } KillOpenedProcessFromPath(InstallLocation); KillDesktopLNKFromPath(InstallLocation); mfm.OnDeleteDirectory(InstallLocation); Utils._s_Utils_Registry_Manager.DeleteKey(JTarget.RegistryKeyAddress); } } catch (Exception ex) { JOnUninstallSoftware.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message); } return(JOnUninstallSoftware); }
/// <summary> /// Kills the desktop LNK from path. /// </summary> /// <param name="InstallLocation">The install location.</param> /// <returns>if has lnk return true other return false</returns> private bool KillDesktopLNKFromPath(string InstallLocation) { bool HasLNK = false; string[] desktopPath = new string[2]; desktopPath[0] = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory); desktopPath[1] = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); foreach (string desk in desktopPath) { _m_File_Manager mfm = new _m_File_Manager(); OnDirResponse Dirs = mfm.OnDir(desk); foreach (OnDirResponse.FileOrDir FileOrFolder in Dirs.fileOrdir) { //if (FileOrFolder.Path.Contains("Resizer 5")) //{ //} if (FileOrFolder.Path.EndsWith(".lnk")) { string TempAddress = _m_File_Manager.GetShortcutTargetFile(FileOrFolder.Path); string TargetAdress = ""; if (TempAddress.EndsWith("\\")) { TargetAdress = TempAddress; } else { TargetAdress = GetPathFromFullPath(TempAddress, true); } if (TargetAdress == InstallLocation) { System.IO.File.Delete(FileOrFolder.Path); } } } } return(HasLNK); }