public void OpenXML(AddSoftware oSoftware) { tbArchitecture.Text = (oSoftware.Architecture ?? "").Trim(); tbContentId.Text = oSoftware.ContentID; if (string.IsNullOrEmpty(tbContentId.Text)) { tbContentId.Text = Guid.NewGuid().ToString(); } tbDescription.Text = oSoftware.Description; if (oSoftware.Files != null) { foreach (contentFiles vFiles in oSoftware.Files) { if (string.IsNullOrEmpty(vFiles.HashType)) { vFiles.HashType = "MD5"; } } dgSourceFiles.ItemsSource = oSoftware.Files; } else { dgSourceFiles.ItemsSource = null; dgSourceFiles.Items.Clear(); } tbManufacturer.Text = oSoftware.Manufacturer; tbMSIId.Text = oSoftware.MSIProductID; tbProductName.Text = oSoftware.ProductName; tbVersion.Text = oSoftware.ProductVersion; tbPSDetection.Text = oSoftware.PSDetection; tbPSInstall.Text = oSoftware.PSInstall; tbPSPrereq.Text = oSoftware.PSPreReq; tbPSUnInstall.Text = oSoftware.PSUninstall; tbProductURL.Text = oSoftware.ProductURL; tbPSPostInstall.Text = oSoftware.PSPostInstall; tbPSPreInstall.Text = oSoftware.PSPreInstall; tbAuthor.Text = oSoftware.Author; if (oSoftware.PreRequisites != null) { tbPreReq.Text = string.Join(";", oSoftware.PreRequisites) ?? ""; } else { tbPreReq.Text = ""; } try { imgIcon.Tag = oSoftware.Image; imgIcon.Source = ByteToImage(oSoftware.Image); } catch { } tbCategories.Text = oSoftware.Category ?? ""; tbShortName.Text = oSoftware.ShortName ?? ""; }
internal void _RegScan(RegistryHive RegHive, RegistryView RegView, List <AddSoftware> lScanList) { try { RegistryKey oUBase = RegistryKey.OpenBaseKey(RegHive, RegView); RegistryKey oUKey = oUBase.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall", false); List <string> USubKeys = new List <string>(); USubKeys.AddRange(oUKey.GetSubKeyNames()); foreach (string sProdID in USubKeys) { try { RegistryKey oRegkey = oUKey.OpenSubKey(sProdID); bool bSystemComponent = Convert.ToBoolean(oRegkey.GetValue("SystemComponent", 0)); bool bWindowsInstaller = Convert.ToBoolean(oRegkey.GetValue("WindowsInstaller", 0)); string sParent = oRegkey.GetValue("ParentKeyName", "").ToString(); string sRelease = oRegkey.GetValue("ReleaseType", "").ToString(); //Check if its a SystemComponent or WindowsInstaller if (bSystemComponent) { continue; } //Check if NO PrentKeyName exists if (!string.IsNullOrEmpty(sParent)) { continue; } //Check if NO ReleaseType exists if (!string.IsNullOrEmpty(sRelease)) { continue; } AddSoftware oItem = GetSWProperties(oUKey.OpenSubKey(sProdID)); if (!string.IsNullOrEmpty(oItem.ProductName)) { try { lock (lScanList) { lScanList.Add(oItem); } } catch (Exception ex) { ex.Message.ToString(); } } } catch { } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void miCreateExe_Click(object sender, RoutedEventArgs e) { Mouse.OverrideCursor = Cursors.Wait; try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); } CreateExe oExe = new CreateExe(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, oSW.SW.ShortName + "_setup.exe")); //Get Icon if missing if (oSW.SW.Image == null) { oSW.SW.Image = RZRestAPIv2.GetIcon(oSW.SW.IconHash); } oExe.Icon = oSW.SW.Image; oExe.Sources.Add(Properties.Resources.Source.Replace("RZRZRZ", oSW.SW.ShortName)); oExe.Sources.Add(Properties.Resources.RZUpdate); oExe.Sources.Add(Properties.Resources.RZRestApi); oExe.Sources.Add(Properties.Resources.Assembly.Replace("RZRZRZ", oSW.SW.ShortName)); if (!oExe.Compile()) { MessageBox.Show("Failed to create .Exe", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(oSW.SW.ShortName + "_setup.exe" + " created in: " + AppDomain.CurrentDomain.BaseDirectory, "EXE created", MessageBoxButton.OK, MessageBoxImage.Information); } } catch { } } } finally { Mouse.OverrideCursor = null; } }
void oInstPanel_onEdit(object sender, EventArgs e) { AnonymousDelegate update = delegate() { try { bool bNoPreReqCheck = false; if (sender.GetType() == typeof(GetSoftware)) { GetSoftware oSelectedItem = (GetSoftware)sender; //Ignore PreRequisites if SHIFT is pressed if (Keyboard.Modifiers == ModifierKeys.Shift) { bNoPreReqCheck = true; } //Load Software details for a valid DeploymentType... SWUpdate oSW = new SWUpdate(oSelectedItem.ProductName, oSelectedItem.ProductVersion, oSelectedItem.Manufacturer, bNoPreReqCheck); //get Icon if (oSW.SW != null) { oSW.SW.Image = RZRestAPIv2.GetIcon(oSW.SW.IconHash); oNewPanel.OpenXML(oSW.SW); } tabNewSWSMI.Tag = tabWizard.SelectedItem; tabWizard.SelectedItem = tabNewSWSMI; } if (sender.GetType() == typeof(AddSoftware)) { AddSoftware oSelectedItem = (AddSoftware)sender; //Ignore PreRequisites if SHIFT is pressed if (Keyboard.Modifiers == ModifierKeys.Shift) { bNoPreReqCheck = true; } //Load Software details for a valid DeploymentType... SWUpdate oSW = new SWUpdate(oSelectedItem.ProductName, oSelectedItem.ProductVersion, oSelectedItem.Manufacturer, bNoPreReqCheck); oNewPanel.OpenXML(oSW.SW); tabNewSWSMI.Tag = tabWizard.SelectedItem; tabWizard.SelectedItem = tabNewSWSMI; } } catch { } }; Dispatcher.Invoke(update); }
private void SaveAsJSON(string sFile) { AddSoftware oSoftware = new AddSoftware(); oSoftware.Architecture = tbArchitecture.Text.Trim(); oSoftware.ContentID = tbContentId.Text.Trim(); oSoftware.Description = tbDescription.Text; try { oSoftware.Files = ((List <contentFiles>)dgSourceFiles.ItemsSource); foreach (contentFiles oFile in oSoftware.Files) { if (string.IsNullOrEmpty(oFile.HashType)) { oFile.HashType = "MD5"; } } } catch { } try { oSoftware.Files = ((List <contentFiles>)dgSourceFiles.ItemsSource); } catch { } oSoftware.Manufacturer = tbManufacturer.Text.Trim(); oSoftware.MSIProductID = tbMSIId.Text; oSoftware.ProductName = tbProductName.Text.Trim(); oSoftware.ProductVersion = tbVersion.Text.Trim(); oSoftware.PSDetection = tbPSDetection.Text; oSoftware.PSInstall = tbPSInstall.Text; oSoftware.PSPreReq = tbPSPrereq.Text; oSoftware.PSUninstall = tbPSUnInstall.Text; oSoftware.ProductURL = tbProductURL.Text.Trim(); //oSoftware.Author = Properties.Settings.Default.UserKey; oSoftware.PSPreInstall = tbPSPreInstall.Text; oSoftware.PSPostInstall = tbPSPostInstall.Text; oSoftware.PreRequisites = tbPreReq.Text.Split(';'); oSoftware.ShortName = tbShortName.Text.Trim(); oSoftware.Category = tbCategories.Text.Trim(); oSoftware.Author = tbAuthor.Text.Trim(); if (imgIcon.Tag != null) { oSoftware.Image = imgIcon.Tag as byte[]; } //Convert to JSON JavaScriptSerializer ser = new JavaScriptSerializer(); string sJson = ser.Serialize(oSoftware); File.WriteAllText(sFile, sJson); }
private void miCreateExe_Click(object sender, RoutedEventArgs e) { Mouse.OverrideCursor = Cursors.Wait; try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); } CreateExe oExe = new CreateExe(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, oSW.SW.ShortName + "_setup.exe")); oExe.Icon = oSW.SW.Image; oExe.Sources.Add(Properties.Resources.Source.Replace("RZRZRZ", oSW.SW.ShortName)); oExe.Sources.Add(Properties.Resources.RZUpdate); oExe.Sources.Add(Properties.Resources.RZRestApi); oExe.Sources.Add(Properties.Resources.Assembly.Replace("RZRZRZ", oSW.SW.ShortName)); if (!oExe.Compile()) { MessageBox.Show("Failed to create .Exe", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } //Non authenticated Users can create one EXE if (!EnableEdit) { miCreateExe.IsEnabled = false; return; } } catch { } } } finally { Mouse.OverrideCursor = null; } }
private void miDownloadFiles_Click(object sender, RoutedEventArgs e) { if (lvSW.SelectedItem != null) { try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); } oSW.sUserName = Properties.Settings.Default.UserKey; //lDLTasks.Add(oSW.downloadTask); if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oSW.SW.ProductName) == null) { //oSW.Downloaded += OSW_Downloaded; oSW.ProgressDetails += OSW_ProgressDetails; oSW.downloadTask.AutoInstall = false; oSW.Download(false).ConfigureAwait(false); dm.lDLTasks.Add(oSW.downloadTask); } dm.Show(); continue; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch { } OnSWUpdated(this, new EventArgs()); } }
private void miEdit_Click(object sender, RoutedEventArgs e) { lvSW.ContextMenu.IsOpen = false; Thread.Sleep(200); Dispatcher.Invoke(new Action(() => { }), System.Windows.Threading.DispatcherPriority.ContextIdle, null); if (lvSW.SelectedItems.Count > 0) { AddSoftware oSelectedItem = lvSW.SelectedItems[0] as AddSoftware; if (onEdit != null) { onEdit(oSelectedItem, EventArgs.Empty); } } }
private void Button_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbDescription.Text)) { if (MessageBox.Show("Description is empty !", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) != MessageBoxResult.OK) { return; } } if (tbPSInstall.Text.Contains("/?") || tbPSUnInstall.Text.Contains("/?")) { if (MessageBox.Show("Paremeter for silent In-Uninstall are missing or unknown ( \"/?\")", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) != MessageBoxResult.OK) { return; } } if (((List <contentFiles>)dgSourceFiles.ItemsSource).Count(t => !string.IsNullOrEmpty(t.URL)) == 0) { if (MessageBox.Show("one File-URL is empty !", "Warning", MessageBoxButton.OKCancel, MessageBoxImage.Warning) != MessageBoxResult.OK) { return; } } AddSoftware oSoftware = new AddSoftware(); oSoftware.Architecture = tbArchitecture.Text; oSoftware.ContentID = tbContentId.Text; oSoftware.Description = tbDescription.Text; try { oSoftware.Files = ((List <contentFiles>)dgSourceFiles.ItemsSource).Where(t => !string.IsNullOrEmpty(t.URL)).ToList(); } catch { } try { List <contentFiles> lResult = new List <contentFiles>(); foreach (contentFiles oFile in dgSourceFiles.ItemsSource) { lResult.Add(new contentFiles() { FileHash = oFile.FileHash, FileName = oFile.FileName, HashType = oFile.HashType, URL = oFile.URL, FileSize = oFile.FileSize }); } oSoftware.Files = lResult; } catch { } oSoftware.Manufacturer = tbManufacturer.Text; oSoftware.MSIProductID = tbMSIId.Text; oSoftware.ProductName = tbProductName.Text; oSoftware.ProductVersion = tbVersion.Text; oSoftware.PSDetection = tbPSDetection.Text; oSoftware.PSInstall = tbPSInstall.Text; oSoftware.PSPreReq = tbPSPrereq.Text; oSoftware.PSUninstall = tbPSUnInstall.Text; oSoftware.ProductURL = tbProductURL.Text; oSoftware.Author = tbAuthor.Text;; oSoftware.PSPreInstall = tbPSPreInstall.Text; oSoftware.PSPostInstall = tbPSPostInstall.Text; if (!string.IsNullOrEmpty(tbPreReq.Text)) { oSoftware.PreRequisites = tbPreReq.Text.Split(';'); } if (imgIcon.Tag != null) { oSoftware.Image = imgIcon.Tag as byte[]; } oSoftware.Category = tbCategories.Text.Trim(); oSoftware.ShortName = tbShortName.Text.Trim(); if (RZRestAPIv2.UploadSWEntry(oSoftware)) { btUpload.IsEnabled = false; } }
private void btCreatARPSW_Click(object sender, RoutedEventArgs e) { Mouse.OverrideCursor = Cursors.Wait; try { if (arpGrid2.SelectedItems.Count > 0) { AddSoftware oSelectedItem = arpGrid2.SelectedItem as AddSoftware; //oNewPanel = new NewSWPanelxaml(); oNewPanel.tbManufacturer.Text = oSelectedItem.Manufacturer; oNewPanel.tbProductName.Text = oSelectedItem.ProductName; oNewPanel.tbVersion.Text = oSelectedItem.ProductVersion; oNewPanel.imgIcon.Tag = oSelectedItem.Image; oNewPanel.tbProductURL.Text = oSelectedItem.ProductURL; oNewPanel.tbDescription.Text = oSelectedItem.Description; oNewPanel.tbArchitecture.Text = oSelectedItem.Architecture; oNewPanel.tbContentId.Text = oSelectedItem.ContentID; oNewPanel.tbPSDetection.Text = oSelectedItem.PSDetection; oNewPanel.tbPSInstall.Text = oSelectedItem.PSInstall; oNewPanel.tbPSPrereq.Text = oSelectedItem.PSPreReq; oNewPanel.tbPSUnInstall.Text = oSelectedItem.PSUninstall; oNewPanel.tbPSPreInstall.Text = oSelectedItem.PSPreInstall; oNewPanel.tbPSPostInstall.Text = oSelectedItem.PSPostInstall; oNewPanel.tbMSIId.Text = oSelectedItem.MSIProductID; oNewPanel.imgIcon.Source = ByteToImage(oSelectedItem.Image); oNewPanel.dgSourceFiles.DataContext = null; if (string.IsNullOrEmpty(oSelectedItem.ContentID)) { oNewPanel.tbContentId.Text = Guid.NewGuid().ToString(); } if (oSelectedItem.Architecture == "NEW") { if (Environment.Is64BitOperatingSystem) { oNewPanel.tbArchitecture.Text = "X64"; } else { oNewPanel.tbArchitecture.Text = "X86"; } } if (oNewPanel.tbPSUnInstall.Text.ToLowerInvariant().Contains("(x86)") || oNewPanel.tbPSDetection.Text.ToLowerInvariant().Contains("wow6432node")) { oNewPanel.tbPSPrereq.Text = "[Environment]::Is64BitProcess"; } //oNewPanel.tbPSUnInstall.Text = oNewPanel.tbPSUnInstall.Text.Replace(@"C:\Program Files (x86)", "$(${Env:ProgramFiles(x86)})"); //oNewPanel.tbPSUnInstall.Text = oNewPanel.tbPSUnInstall.Text.Replace(@"C:\Program Piles", "$($Env:ProgramFiles)"); oNewPanel.tbPSUnInstall.Text = System.Text.RegularExpressions.Regex.Replace(oNewPanel.tbPSUnInstall.Text, System.Text.RegularExpressions.Regex.Escape(@"C:\Program Files (x86)"), @"$(${Env:ProgramFiles(x86)})", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace); oNewPanel.tbPSUnInstall.Text = System.Text.RegularExpressions.Regex.Replace(oNewPanel.tbPSUnInstall.Text, System.Text.RegularExpressions.Regex.Escape(@"C:\Program Files"), "$($Env:ProgramFiles)", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace); oNewPanel.tbPSUnInstall.Text = System.Text.RegularExpressions.Regex.Replace(oNewPanel.tbPSUnInstall.Text, System.Text.RegularExpressions.Regex.Escape(@"C:\Program Data"), "$($Env:ProgramData)", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace); if (oNewPanel.tbPSDetection.Text.ToLowerInvariant().Contains("wow6432node")) { oNewPanel.tbArchitecture.Text = "X64"; } if (oNewPanel.tbPSUnInstall.Text.ToLowerInvariant().Contains("(x86)")) { oNewPanel.tbArchitecture.Text = "X64"; } if (oNewPanel.tbPSUnInstall.Text.ToUpperInvariant().Contains("/SILENT")) { oNewPanel.tbPSInstall.Text = oNewPanel.tbPSInstall.Text.Replace("/?", "/SP- /VERYSILENT /NORESTART"); } } tabWizard.SelectedItem = tabNewSWSMI; } finally { Mouse.OverrideCursor = null; } }
private void miUninstall_Click(object sender, RoutedEventArgs e) { tSearch.Stop(); lvSW.ContextMenu.IsOpen = false; Thread.Sleep(200); Dispatcher.Invoke(new Action(() => { }), System.Windows.Threading.DispatcherPriority.ContextIdle, null); if (lvSW.SelectedItem != null) { try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); if (oSW.SW == null) { dm.lDLTasks.Add(new DLTask() { ProductName = dgr.ProductName, ProductVersion = dgr.ProductVersion, Error = true, ErrorMessage = "Requirements not valid." }); dm.Show(); continue; } } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); if (oSW.SW == null) { dm.lDLTasks.Add(new DLTask() { ProductName = dgr.ProductName, ProductVersion = dgr.ProductVersion, Error = true, ErrorMessage = "Requirements not valid." }); dm.Show(); continue; } } oSW.sUserName = Properties.Settings.Default.UserKey; //lDLTasks.Add(oSW.downloadTask); if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oSW.SW.ProductName) == null) { //oSW.Downloaded += OSW_Downloaded; oSW.ProgressDetails += OSW_ProgressDetails; oSW.downloadTask.AutoInstall = true; dm.lDLTasks.Add(oSW.downloadTask); oSW.UnInstall(false, false).ConfigureAwait(false); } dm.Show(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch { } OnSWUpdated(this, new EventArgs()); } }
private void btInstall_Click(object sender, RoutedEventArgs e) { if (lvSW.SelectedItem != null) { tSearch.Stop(); try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; if (oSW == null) { oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oSW.SW == null) { dm.lDLTasks.Add(new DLTask() { ProductName = dgr.ProductName, ProductVersion = dgr.ProductVersion, Error = true, ErrorMessage = "Requirements not valid. Installation will not start." }); dm.Show(); continue; } } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); if (oSW.SW == null) { dm.lDLTasks.Add(new DLTask() { ProductName = dgr.ProductName, ProductVersion = dgr.ProductVersion, Error = true, ErrorMessage = "Requirements not valid. Installation will not start." }); dm.Show(); continue; } } oSW.sUserName = Properties.Settings.Default.UserKey; try { var xRem = dm.lDLTasks.Where(x => x.ProductName == oSW.SW.ProductName && (x.Error || (x.PercentDownloaded == 100 && x.AutoInstall == false) || (x.Status == "Waiting" && x.DownloadedBytes == 0 && x.Downloading == false) || x.UnInstalled)).ToList(); foreach (var o in xRem) { try { dm.lDLTasks.Remove(o); } catch { } } //xRem.ForEach(x => lDLTasks.Remove(x)); } catch { } //Allow only one entry if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oSW.SW.ProductName) == null) { //oSW.Downloaded += OSW_Downloaded; oSW.ProgressDetails += OSW_ProgressDetails; oSW.downloadTask.AutoInstall = true; oSW.Download(false).ConfigureAwait(false);; dm.lDLTasks.Add(oSW.downloadTask); foreach (string sPreReq in oSW.SW.PreRequisites) { try { SWUpdate oPreReq = new SWUpdate(sPreReq); if (oPreReq.GetInstallType()) { oPreReq.sUserName = Properties.Settings.Default.UserKey; if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oPreReq.SW.ProductName) == null) { //oPreReq.Downloaded += OSW_Downloaded; oPreReq.ProgressDetails += OSW_ProgressDetails; oPreReq.downloadTask.AutoInstall = true; oPreReq.Download(false).ConfigureAwait(false);; dm.lDLTasks.Add(oPreReq.downloadTask); } } } catch { } } } dm.Show(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch { } OnSWUpdated(this, new EventArgs()); } }
internal AddSoftware GetSWProperties(RegistryKey oRegkey) { AddSoftware oResult = new AddSoftware(); oResult.PSPreReq = "$true"; if (oRegkey.View == RegistryView.Registry32) { oResult.Architecture = "X86"; } else { oResult.Architecture = "X64"; oResult.PSPreReq = "[Environment]::Is64BitProcess"; } string sMSI = oRegkey.Name.Split('\\').Last(); string EncKey = ""; if (sMSI.StartsWith("{") & sMSI.EndsWith("}")) { bool bIsMSI = true; EncKey = descramble(sMSI.Substring(1, 36).Replace("-", "")); try { RegistryKey oBase = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, oRegkey.View); RegistryKey oKey = oBase.OpenSubKey(@"SOFTWARE\Classes\Installer\Products\" + EncKey, false); if (oKey == null) { bIsMSI = false; } } catch { bIsMSI = false; } if (bIsMSI) { oResult.MSIProductID = sMSI; oResult.PSUninstall = "$proc = (Start-Process -FilePath \"msiexec.exe\" -ArgumentList \"/x " + sMSI + " /qb! \" -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; oResult.PSDetection = @"Test-Path 'HKLM:\SOFTWARE\Classes\Installer\Products\" + EncKey + "'"; try { RegistryKey oSource = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\Installer\Products\" + EncKey + "\\SourceList"); if (oSource != null) { oResult.PSInstall = "$proc = (Start-Process -FilePath \"msiexec.exe\" -ArgumentList \"/i `\"" + oSource.GetValue("PackageName") + "`\" /qb! ALLUSERS=2 REBOOT=REALLYSUPPRESS\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; } } catch { try { oResult.PSDetection = @"if((Get-ItemProperty -path '" + oRegkey.Name.Replace("HKEY_LOCAL_MACHINE", "HKLM:") + "' -Name DisplayVersion -ea SilentlyContinue | select -exp DisplayVersion) -eq '" + oRegkey.GetValue("DisplayVersion", "").ToString() + "') { $true } else { $false }"; } catch { } oResult.PSInstall = "$proc = (Start-Process -FilePath \"msiexec.exe\" -ArgumentList \"/i `\"<PackageName.msi>`\" /qb! ALLUSERS=2 REBOOT=REALLYSUPPRESS\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; } } else { oResult.PSInstall = "$proc = (Start-Process -FilePath \"setup.exe\" -ArgumentList \"/?\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; if (Environment.Is64BitOperatingSystem & oRegkey.View == RegistryView.Registry32) { oResult.PSDetection = @"if((Get-ItemProperty -path '" + oRegkey.Name.ToUpper().Replace("HKEY_LOCAL_MACHINE", "HKLM:").Replace("SOFTWARE\\", "SOFTWARE\\WOW6432NODE\\") + "' -Name DisplayVersion -ea SilentlyContinue | select -exp DisplayVersion) -eq '" + oRegkey.GetValue("DisplayVersion", "").ToString() + "') { $true } else { $false }"; } else { oResult.PSDetection = @"if((Get-ItemProperty -path '" + oRegkey.Name.ToUpper().Replace("HKEY_LOCAL_MACHINE", "HKLM:") + "' -Name DisplayVersion -ea SilentlyContinue | select -exp DisplayVersion) -eq '" + oRegkey.GetValue("DisplayVersion", "").ToString() + "') { $true } else { $false }"; } } } else { oResult.PSInstall = "$proc = (Start-Process -FilePath \"setup.exe\" -ArgumentList \"/?\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; if (Environment.Is64BitOperatingSystem & oRegkey.View == RegistryView.Registry32) { oResult.PSDetection = @"if((Get-ItemProperty -path '" + oRegkey.Name.ToUpper().Replace("HKEY_LOCAL_MACHINE", "HKLM:").Replace("SOFTWARE\\", "SOFTWARE\\WOW6432NODE\\") + "' -Name DisplayVersion -ea SilentlyContinue | select -exp DisplayVersion) -eq '" + oRegkey.GetValue("DisplayVersion", "").ToString() + "') { $true } else { $false }"; } else { oResult.PSDetection = @"if((Get-ItemProperty -path '" + oRegkey.Name.ToUpper().Replace("HKEY_LOCAL_MACHINE", "HKLM:") + "' -Name DisplayVersion -ea SilentlyContinue | select -exp DisplayVersion) -eq '" + oRegkey.GetValue("DisplayVersion", "").ToString() + "') { $true } else { $false }"; } } oResult.PSDetection = oResult.PSDetection.Replace("HKEY_LOCAL_MACHINE", "HKLM:"); oResult.PSDetection = oResult.PSDetection.Replace("HKEY_CURRENT_USER", "HKCU:"); oResult.ProductName = oRegkey.GetValue("DisplayName", "").ToString(); oResult.ProductVersion = oRegkey.GetValue("DisplayVersion", "").ToString(); oResult.Manufacturer = oRegkey.GetValue("Publisher", "").ToString(); //If not an MSI try to get Uninstall command from Registry if (string.IsNullOrEmpty(oResult.MSIProductID)) { try { string sUninst = oRegkey.GetValue("QuietUninstallString", "").ToString().Replace("\"", ""); if (!string.IsNullOrEmpty(sUninst)) { try { if (sUninst.IndexOf('/') >= 0) { oResult.PSUninstall = "$proc = (Start-Process -FilePath \"" + sUninst.Split('/')[0] + "\" -ArgumentList \"" + sUninst.Substring(sUninst.IndexOf('/')) + "\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; } else { oResult.PSUninstall = "$proc = (Start-Process -FilePath \"" + sUninst + "\" -ArgumentList \"/?\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; } //$proc = (Start-Process -FilePath "zps17_en.exe" -ArgumentList "/Silent" -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode } catch { oResult.PSUninstall = "$proc = (Start-Process -FilePath \"" + sUninst + "\" -ArgumentList \"/?\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; } } } catch { } } //If no silent uninstall is provided, use the normal uninstall string if (string.IsNullOrEmpty(oResult.PSUninstall)) { if (string.IsNullOrEmpty(oResult.MSIProductID)) { string sUninst = oRegkey.GetValue("UninstallString", "").ToString().Replace("\"", ""); oResult.PSUninstall = "$proc = (Start-Process -FilePath \"" + sUninst + "\" -ArgumentList \"/?\" -Wait -PassThru);$proc.WaitForExit();$ExitCode = $proc.ExitCode"; } } //get Version String if (string.IsNullOrEmpty(oResult.ProductVersion)) { string sVersion = oRegkey.GetValue("Version", "").ToString(); if (!string.IsNullOrEmpty(sVersion)) { try { Int32 iVersion = Convert.ToInt32(sVersion); string sfullval = iVersion.ToString("X8"); sVersion = Convert.ToInt32(sfullval.Substring(0, 2), 16).ToString(); sVersion = sVersion + "." + Convert.ToInt32(sfullval.Substring(2, 2), 16).ToString(); sVersion = sVersion + "." + Convert.ToInt32(sfullval.Substring(4, 4), 16).ToString(); oResult.ProductVersion = sVersion; } catch { } } } //Get Image string sDisplayIcon = oRegkey.GetValue("DisplayIcon", "").ToString().Split(',')[0]; if (!string.IsNullOrEmpty(EncKey)) { try { RegistryKey oKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\Installer\Products\" + EncKey, false); if (oKey != null) { string sIcon = oKey.GetValue("ProductIcon", "") as string; if (!string.IsNullOrEmpty(sIcon)) { sDisplayIcon = sIcon; } } } catch { } } //Add default Icon if (string.IsNullOrEmpty(sDisplayIcon)) { sDisplayIcon = @"C:\windows\system32\msiexec.exe"; } if (!sDisplayIcon.Contains(":\\")) { sDisplayIcon = @"C:\windows\system32\" + sDisplayIcon; } sDisplayIcon = sDisplayIcon.Replace("\"", ""); sDisplayIcon = sDisplayIcon.Split(',')[0]; if (!File.Exists(sDisplayIcon)) { if (File.Exists(sDisplayIcon.Replace(" (x86)", ""))) { sDisplayIcon = sDisplayIcon.Replace(" (x86)", ""); } else { sDisplayIcon = ""; } } if (!string.IsNullOrEmpty(sDisplayIcon)) { oResult.Image = imageToByteArray(GetImageFromExe(sDisplayIcon.Replace("\"", ""))); } oResult.Architecture = "X64"; return(oResult); }
private void miDownloadIpfs_Click(object sender, RoutedEventArgs e) { if (lvSW.SelectedItem != null) { try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); //oSW = new SWUpdate(dgr); } oSW.sUserName = Properties.Settings.Default.UserKey; //lDLTasks.Add(oSW.downloadTask); if (dm.lDLTasks.FirstOrDefault(t => t.ProductName == oSW.SW.ProductName) == null) { //oSW.Downloaded += OSW_Downloaded; oSW.ProgressDetails += OSW_ProgressDetails; oSW.downloadTask.AutoInstall = false; foreach (var oFile in oSW.SW.Files.ToList()) { //Check if there is a known IPFS hash and update URL if there is... string sHash = RuckZuck_WCF.RZRestAPI.GetIPFS(oSW.SW.ContentID, oFile.FileName); if (sHash.Length > 12) { oFile.URL = RuckZuck_WCF.RZRestAPI.ipfs_GW_URL + "/" + sHash + "/"; oSW.Download(false).ConfigureAwait(false); } else { return; } } dm.lDLTasks.Add(oSW.downloadTask); } dm.Show(); continue; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch { } OnSWUpdated(this, new EventArgs()); } }
public void RuckZuckSync(AddSoftware oRZ, DLTask downloadTask, bool Bootstrap = false) { string PkgName = oRZ.ProductName; string PkgVersion = oRZ.ProductVersion; string Manufacturer = oRZ.Manufacturer.TrimEnd('.'); //Temp Fix Bootstrap = false; downloadTask.Installing = true; //RZUpdate.SWUpdate oUpd = new RZUpdate.SWUpdate(PkgName, PkgVersion, Manufacturer); //var lSW = GetRZSoftware(PkgName, PkgVersion, Manufacturer); downloadTask.Installing = true; string SWID = "RZID" + oRZ.SWId.ToString(); Boolean bDownloadStatus = true; bool bPreReq = false; downloadTask.Installing = true; try { if (oRZ.Architecture.StartsWith("_prereq_")) { bPreReq = true; return; } //RZUpdate.SWUpdate oUpd = new RZUpdate.SWUpdate(oRZ); downloadTask.Status = "Downloading File(s)..."; //Listener.WriteLine(SW.Shortname, "Creating DeploymentType: " + oIT.Architecture); DirectoryInfo oDir = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("TEMP"), oRZ.ContentID.ToString())); if (!Directory.Exists(oDir.FullName)) { oDir = Directory.CreateDirectory(Path.Combine(Environment.GetEnvironmentVariable("TEMP"), oRZ.ContentID.ToString())); } //generating PowerShell Scripts downloadTask.Status = "generating PowerShell scripts..."; using (StreamWriter outfile = new StreamWriter(Path.Combine(oDir.FullName, "install.ps1"), false, new UTF8Encoding(false))) { outfile.WriteLine("Set-Location $PSScriptRoot;"); if (!string.IsNullOrEmpty(oRZ.PSPreInstall)) { outfile.Write(oRZ.PSPreInstall); outfile.WriteLine(); } outfile.Write(oRZ.PSInstall); outfile.WriteLine(); if (!string.IsNullOrEmpty(oRZ.PSPostInstall)) { outfile.Write(oRZ.PSPostInstall); outfile.WriteLine(); } outfile.WriteLine("Exit($ExitCode)"); outfile.Close(); } using (StreamWriter outfile = new StreamWriter(Path.Combine(oDir.FullName, "uninstall.ps1"), false, new UTF8Encoding(false))) { outfile.WriteLine("Set-Location $PSScriptRoot;"); outfile.Write(oRZ.PSUninstall); outfile.Close(); } using (StreamWriter outfile = new StreamWriter(Path.Combine(oDir.FullName, "detection.ps1"), false, new UTF8Encoding(false))) { outfile.WriteLine("$bRes = " + oRZ.PSDetection + ";"); outfile.WriteLine("if($bRes) { $true } else { $null };"); outfile.WriteLine("exit(0);"); outfile.Close(); } using (StreamWriter outfile = new StreamWriter(Path.Combine(oDir.FullName, "requirements.ps1"), false, new UTF8Encoding(false))) { outfile.WriteLine(oRZ.PSPreReq + ";"); outfile.Close(); } downloadTask.Status = "Downloading File(s)..."; //Listener.WriteLine(SW.Shortname, "Downloading File(s)..."); //if (!Bootstrap) //{ // bDownloadStatus = oRZ.Download(true, oDir.FullName).Result; // //DL Failed! // if (!bDownloadStatus) // { // downloadTask.Error = true; // downloadTask.ErrorMessage = "content download failed."; // Thread.Sleep(3000); // } //} } catch (Exception ex) { downloadTask.Status = ""; downloadTask.Installing = false; downloadTask.Installed = true; downloadTask.Error = true; downloadTask.ErrorMessage = ex.Message; } downloadTask.Status = "Creating Application..."; if (!Directory.Exists(Environment.ExpandEnvironmentVariables("%TEMP%\\intunewin"))) { Directory.CreateDirectory(Environment.ExpandEnvironmentVariables("%TEMP%\\intunewin")); } File.WriteAllText(Environment.ExpandEnvironmentVariables("%TEMP%\\intunewin\\RZ4Intune.ps1"), Properties.Settings.Default.RZCreateAppPS); try { if (Properties.Settings.Default.NoExit) { Process.Start("powershell.exe", "-executionpolicy bypass -noexit -file " + Environment.ExpandEnvironmentVariables("%TEMP%\\intunewin\\RZ4Intune.ps1") + " \"" + oRZ.ShortName + "\" \"" + authResult.AccessToken + "\" \"" + authResult.ExpiresOn.ToString("u") + "\" \"" + authResult.Account.Username + "\"").WaitForExit(); } else { Process.Start("powershell.exe", "-executionpolicy bypass -file " + Environment.ExpandEnvironmentVariables("%TEMP%\\intunewin\\RZ4Intune.ps1") + " \"" + oRZ.ShortName + "\" \"" + authResult.AccessToken + "\" \"" + authResult.ExpiresOn.ToString("u") + "\" \"" + authResult.Account.Username + "\"").WaitForExit(); } } catch { Process.Start("powershell.exe", "-executionpolicy bypass -file " + Environment.ExpandEnvironmentVariables("%TEMP%\\intunewin\\RZ4Intune.ps1") + " \"" + oRZ.ShortName + "\" \" \" \" \" \" \"").WaitForExit(); DirectoryInfo oDir = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("TEMP"), oRZ.ContentID.ToString())); File.WriteAllText(Path.Combine(oDir.FullName, "azure-pipelines.yml"), Properties.Settings.Default.azurepipelines); downloadTask.Status = ""; downloadTask.Installing = false; downloadTask.Installed = true; downloadTask.Error = false; return; } downloadTask.Status = ""; downloadTask.Installing = false; downloadTask.Installed = true; downloadTask.Error = false; //foreach (var oIT in RZRestAPIv2.GetSoftwares(SW.ProductName, SW.ProductVersion, SW.Manufacturer, "RZ4Intune")) //{ //} }
private void miCreateArtifact_Click(object sender, RoutedEventArgs e) { Mouse.OverrideCursor = Cursors.Wait; try { foreach (var oItem in lvSW.SelectedItems) { try { SWUpdate oSW = null; if (oItem.GetType() == typeof(GetSoftware)) { GetSoftware dgr = oItem as GetSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr.ProductName, dgr.ProductVersion, dgr.Manufacturer); } if (oItem.GetType() == typeof(AddSoftware)) { AddSoftware dgr = oItem as AddSoftware; //sPS = GetSWInstallPS(dgr.ProductName, dgr.ProductVersion, ""); oSW = new SWUpdate(dgr); } string sDir = AppDomain.CurrentDomain.BaseDirectory; sDir = Path.Combine(sDir, "windows-" + oSW.SW.Shortname.Replace(" ", "")).Trim(); Directory.CreateDirectory(sDir); CreateExe oExe = new CreateExe(Path.Combine(sDir, oSW.SW.Shortname.Replace(" ", "") + "_setup.exe")); oExe.Icon = oSW.SW.Image; oExe.Sources.Add(Properties.Resources.Source.Replace("RZRZRZ", oSW.SW.Shortname)); oExe.Sources.Add(Properties.Resources.RZUpdate); oExe.Sources.Add(Properties.Resources.RZRestApi); oExe.Sources.Add(Properties.Resources.Assembly.Replace("RZRZRZ", oSW.SW.Shortname)); if (!oExe.Compile()) { MessageBox.Show("Failed to create .Exe", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } List <string> lLines = new List <string>(); lLines.Add("{"); lLines.Add("\t\"title\": \"" + oSW.SW.Shortname + "\","); lLines.Add("\t\"description\": \"" + oSW.SW.Description + "\","); lLines.Add("\t\"publisher\": \"" + oSW.SW.Manufacturer + "\","); lLines.Add("\t\"tags\": [\"Windows\""); if (((GetSoftware)oItem).Categories.Count > 0) { foreach (string sCat in ((GetSoftware)oItem).Categories) { lLines.Add("\t, \"" + sCat + "\""); } lLines.Add("\t],"); } else { lLines.Add("\t],"); } lLines.Add("\t\"iconUri\": \"https://ruckzuck.azurewebsites.net/wcf/RZService.svc/rest/GetIcon?id=" + ((GetSoftware)oItem).IconId + "\","); lLines.Add("\t\"targetOsType\": \"Windows\","); lLines.Add("\t\"runCommand\": { \"commandToExecute\": \"" + oSW.SW.Shortname.Replace(" ", "") + "_setup.exe" + "\" }"); lLines.Add("}"); System.IO.File.WriteAllLines(Path.Combine(sDir, "artifactfile.json"), lLines.ToArray()); //Non authenticated Users can create one EXE if (!EnableEdit) { miCreateArtifact.IsEnabled = false; return; } } catch { } } } finally { Mouse.OverrideCursor = null; } }