/// <summary> /// Check if RuckZuck Token is still valid or request a new token if last refresh was mor than an hour /// </summary> /// <param name="request"></param> //private void _reAuthenticate(Request request) //{ // //Check if there is a token.. // //Guid gToken; // //if (!Guid.TryParse(_AuthenticationToken, out gToken)) // //{ // // dLastTokenRefresh = new DateTime(); // //} // //Re-Authenticate after 30min // if ((DateTime.Now - dLastTokenRefresh).TotalMinutes >= 30) // { // if (string.IsNullOrEmpty(Properties.Settings.Default.Location)) // { // //Properties.Settings.Default.Location = WebServiceURL; // //Properties.Settings.Default.Save(); // } // //RZRestAPI.sURL = Properties.Settings.Default.Location; // if (!string.IsNullOrEmpty(Properties.Settings.Default.Username)) // { // //_AuthenticationToken = RZRestAPI.GetAuthToken(Properties.Settings.Default.Username, ToInsecureString(DecryptString(Properties.Settings.Default.Password))); // //dLastTokenRefresh = DateTime.Now; // request.Debug("RZ Account: " + Properties.Settings.Default.Username); // } // else // { // //_AuthenticationToken = RZRestAPI.GetAuthToken("FreeRZ", GetTimeToken()); // dLastTokenRefresh = DateTime.Now; // request.Debug("RZ Account: FreeRZ"); // } // //if (!Guid.TryParse(_AuthenticationToken, out gToken)) // //{ // // dLastTokenRefresh = new DateTime(); // // request.Warning(_AuthenticationToken); // // _AuthenticationToken = ""; // // return; // //} // request.Debug("RZ Authentication Token:" + _AuthenticationToken); // } //} private void _findPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request) { //_reAuthenticate(request); //Check if AuthToken is still valid try { bool exactSearch = true; if (request.OptionKeys.Contains("Contains")) { name = request.GetOptionValue("Contains"); request.Message("exact search disabled."); exactSearch = false; } //Search all if no name is specified if (string.IsNullOrEmpty(name)) { exactSearch = false; } bool bUpdate = false; if (request.OptionKeys.Contains("Updates")) { request.Message("check updates for installed Software."); bUpdate = true; } List <GetSoftware> lResult = new List <GetSoftware>(); //Get all installed SW if (bUpdate) { oScan.GetSWRepository().Wait(6000); oScan.bCheckUpdates = false; oScan.SWScan().Wait(); oScan.CheckUpdates(null).Wait(); lSoftware = oScan.InstalledSoftware; List <AddSoftware> RequiredUpdates = oScan.NewSoftwareVersions; // RZApi.CheckForUpdate(lSoftware.ToArray()).ToList().Where(t => t.Architecture != "new").ToList(); foreach (var SW in RequiredUpdates) { try { if (string.IsNullOrEmpty(name)) { lResult.Add(new GetSoftware() { ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, ShortName = SW.ShortName, Description = SW.Description, ProductURL = SW.ProductURL }); } else { if ((SW.ProductName.ToLowerInvariant() == name.ToLowerInvariant() | SW.ShortName.ToLowerInvariant() == name.ToLowerInvariant()) && exactSearch) { lResult.Add(new GetSoftware() { ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, ShortName = SW.ShortName, Description = SW.Description, ProductURL = SW.ProductURL }); } if ((SW.ProductName.ToLowerInvariant().Contains(name.ToLowerInvariant()) | SW.ShortName.ToLowerInvariant().Contains(name.ToLowerInvariant())) && !exactSearch) { lResult.Add(new GetSoftware() { ProductName = SW.ProductName, ProductVersion = SW.ProductVersion, Manufacturer = SW.Manufacturer, ShortName = SW.ShortName, Description = SW.Description, ProductURL = SW.ProductURL }); } } } catch { } } if (lResult.Count == 0) { request.Warning("No updates found..."); } } else { if (string.IsNullOrEmpty(requiredVersion)) { //Find by ShortName if (exactSearch) { if (!string.IsNullOrEmpty(name)) { lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower() == name.ToLower()).OrderBy(t => t.ShortName).ToList(); } if (lResult.Count == 0) { //Find any lResult = RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower() == name.ToLower()).OrderBy(t => t.ProductName).ToList(); } } else { if (!string.IsNullOrEmpty(name)) { lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(name.ToLower())).OrderBy(t => t.ShortName).ToList(); } if (lResult.Count == 0) { //Find any lResult = RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(name.ToLower())).OrderBy(t => t.ShortName).ToList(); } if (lResult.Count == 0) { //Find any lResult = RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(name.ToLower())).OrderBy(t => t.ShortName).ToList(); } } } else { //Find by Shortname if (exactSearch) { lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower() == name.ToLower() && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList(); } else { //Find any lResult = RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(name.ToLower()) && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList(); if (lResult.Count == 0) { lResult = RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(name.ToLower()) && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList(); } if (lResult.Count == 0) { lResult = RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(name.ToLower()) && t.ProductVersion.ToLower() == requiredVersion.ToLower()).OrderBy(t => t.ShortName).ToList(); } } } } if (minimumVersion != null) { try { lResult = lResult.Where(p => Version.Parse(p.ProductVersion) >= Version.Parse(minimumVersion)).ToList(); } catch { lResult = lResult.Where(p => p.ProductVersion == minimumVersion).ToList(); } } if (maximumVersion != null) { try { lResult = lResult.Where(p => Version.Parse(p.ProductVersion) <= Version.Parse(maximumVersion)).ToList(); } catch { lResult = lResult.Where(p => p.ProductVersion == maximumVersion).ToList(); } } foreach (var SW in lResult.OrderBy(t => t.ShortName)) { request.YieldSoftwareIdentity(SW.ProductName + ";" + SW.ProductVersion + ";" + SW.Manufacturer, SW.ProductName, SW.ProductVersion, "", SW.Description, Properties.Settings.Default.Location, name, SW.SWId.ToString(), SW.ShortName); //Trust the original RucKZuck source if (string.Equals(Properties.Settings.Default.Location, RZRestAPIv2.sURL, StringComparison.InvariantCultureIgnoreCase)) { request.AddMetadata("FromTrustedSource", "True"); } } } catch (Exception ex) { request.Debug("E334:" + ex.Message); } }
public MainWindow() { DateTime dstart = DateTime.Now; InitializeComponent(); CommandArgs.AddRange(Environment.GetCommandLineArgs()); CommandArgs.RemoveAt(0); //Disable SSL/TLS Errors System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; //Disable CRL Check System.Net.ServicePointManager.CheckCertificateRevocationList = false; //Get Proxy from IE WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy(); if (Properties.Settings.Default.UpgradeSettings) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeSettings = false; Properties.Settings.Default.Save(); } //Get Version FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); tbVersion.Text = string.Format(tbVersion.Text, fvi.FileVersion); lVersion.Content = "Version: " + fvi.FileVersion; //Hide Tabs Style s = new Style(); s.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Collapsed)); tabWizard.ItemContainerStyle = s; tbSVC.Text = RZRestAPIv2.sURL; if (RZRestAPIv2.DisableBroadcast) { cbRZCache.IsChecked = false; cbRZCache.IsEnabled = false; } else { RZRestAPIv2.DisableBroadcast = Properties.Settings.Default.DisableBroadcast; cbRZCache.IsChecked = !Properties.Settings.Default.DisableBroadcast; } if (string.IsNullOrEmpty(RZRestAPIv2.CustomerID)) { tbCustomerID.IsEnabled = true; RZRestAPIv2.CustomerID = Properties.Settings.Default.CustomerID; btSettingsSave.IsEnabled = true; } else { tbCustomerID.Text = RZRestAPIv2.CustomerID; tbCustomerID.IsEnabled = false; btSettingsSave.IsEnabled = false; } oInstPanel.onEdit += oInstPanel_onEdit; oUpdPanel.onEdit += oInstPanel_onEdit; //oInstPanel.OnSWUpdated += OUpdPanel_OnSWUpdated; oUpdPanel.OnSWUpdated += OUpdPanel_OnSWUpdated; double dSeconds = (DateTime.Now - dstart).TotalSeconds; dSeconds.ToString(); //Run PowerShell check in separate thread... Thread thread = new Thread(() => { try { Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); PowerShell powershell = PowerShell.Create(); powershell.AddScript("(get-Host).Version"); powershell.Runspace = runspace; Collection <PSObject> results = powershell.Invoke(); if (((System.Version)(results[0].BaseObject)).Major < 4) { if (MessageBox.Show("The current Version of PowerShell is not supported. Do you want to update ?", "Update Powershell", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes) == MessageBoxResult.Yes) { //Update... Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=50395"); this.Close(); } } } catch { } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); FileVersionInfo FI = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); oSCAN = new RZScan(false, true); //oSCAN.StaticInstalledSoftware.Add(new AddSoftware() { ProductName = "RuckZuck", Manufacturer = FI.CompanyName, ProductVersion = FI.ProductVersion.ToString() }); oSCAN.OnSWScanCompleted += OSCAN_OnSWScanCompleted; oSCAN.OnUpdatesDetected += OSCAN_OnUpdatesDetected; oSCAN.OnSWRepoLoaded += OSCAN_OnSWRepoLoaded; oSCAN.OnUpdScanCompleted += OSCAN_OnUpdScanCompleted; oSCAN.OnInstalledSWAdded += OSCAN_OnInstalledSWAdded; oSCAN.bCheckUpdates = true; oSCAN.GetSWRepository().ConfigureAwait(false); //oSCAN.tRegCheck.Start(); if (CommandArgs.Count > 0) { } else { //Show About once... if (!Properties.Settings.Default.ShowAbout) { tabWizard.SelectedItem = tabMain; } else { tabWizard.SelectedItem = tabStart; Properties.Settings.Default.ShowAbout = false; Properties.Settings.Default.Save(); } } }
private void btInstallSoftware_Click(object sender, RoutedEventArgs e) { Mouse.OverrideCursor = Cursors.Wait; try { if (oSCAN.SoftwareRepository.Count == 0) { try { oSCAN.GetSWRepository().Wait(2000); } catch { } } List <GetSoftware> oDBCat = new List <GetSoftware>(); PropertyGroupDescription PGD = new PropertyGroupDescription("", new ShortNameToCategory()); foreach (GetSoftware oSW in oSCAN.SoftwareRepository) { try { if (oSW.Categories.Count > 1) { foreach (string sCAT in oSW.Categories) { try { //Check if SW is already installed if (lSoftware.FirstOrDefault(t => t.ProductName == oSW.ProductName && t.ProductVersion == oSW.ProductVersion) != null) { GetSoftware oNew = new GetSoftware() { Categories = new List <string> { sCAT }, Description = oSW.Description, Downloads = oSW.Downloads, SWId = oSW.SWId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, ShortName = oSW.ShortName, IconHash = oSW.IconHash, isInstalled = true }; oDBCat.Add(oNew); } else { GetSoftware oNew = new GetSoftware() { Categories = new List <string> { sCAT }, Description = oSW.Description, Downloads = oSW.Downloads, SWId = oSW.SWId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, ShortName = oSW.ShortName, IconHash = oSW.IconHash, isInstalled = false }; oDBCat.Add(oNew); } } catch { } } } else { //Check if SW is already installed if (lSoftware.FirstOrDefault(t => t.ProductName == oSW.ProductName && t.ProductVersion == oSW.ProductVersion) != null) { oDBCat.Add(new GetSoftware() { Categories = oSW.Categories, Description = oSW.Description, Downloads = oSW.Downloads, SWId = oSW.SWId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, ShortName = oSW.ShortName, IconHash = oSW.IconHash, isInstalled = true }); } else { oDBCat.Add(new GetSoftware() { Categories = oSW.Categories, Description = oSW.Description, Downloads = oSW.Downloads, SWId = oSW.SWId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, ShortName = oSW.ShortName, IconHash = oSW.IconHash, isInstalled = false }); } } } catch { } } ListCollectionView lcv = new ListCollectionView(oDBCat.ToList()); foreach (var o in RZRestAPIv2.GetCategories(oSCAN.SoftwareRepository)) { PGD.GroupNames.Add(o); } lcv.GroupDescriptions.Add(PGD); oInstPanel.lvSW.ItemsSource = lcv; oInstPanel.lSoftware = lSoftware; oInstPanel.lAllSoftware = oSCAN.SoftwareRepository; //Mark all installed... oInstPanel.lAllSoftware.ForEach(x => { if (lSoftware.FirstOrDefault(t => (t.ProductName == x.ProductName && t.ProductVersion == x.ProductVersion)) != null) { x.isInstalled = true; } }); /*if (!string.IsNullOrEmpty(tbURL.Text)) * oInstPanel.sInternalURL = tbURL.Text;*/ } finally { Mouse.OverrideCursor = null; } tabWizard.SelectedItem = tabInstallSW; }
private void Connect() { try { connection.Stop(); connection.Start().ContinueWith(task => { if (task.IsFaulted) { Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException()); } else { //Obsolete myHub.On <string, string>("getPS", (s1, s2) => { //using (PowerShell PowerShellInstance = PowerShell.Create()) //{ // try // { // PowerShellInstance.AddScript(s1); // var PSResult = PowerShellInstance.Invoke(); // if (PSResult.Count() > 0) // { // string sResult = PSResult.Last().BaseObject.ToString(); // if (sResult != sScriptResult) //obsolete from 1.0.07 -> returnPS // { // sScriptResult = sResult; // Random rnd = new Random(); // tReInit.Interval = rnd.Next(1000, 10000); //wait max 10s to ReInit // } // myHub.Invoke<string>("Respond", s2, Environment.MachineName + ":" + sResult).ContinueWith(task1 => // { // if (task1.IsFaulted) // { // Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException()); // } // }); // } // } // catch (Exception ex) // { // Console.WriteLine("There was an error: {0}", ex.Message); // } //} //Program.MinimizeFootprint(); }); myHub.On <string, string>("returnPS", (s1, s2) => { TimeSpan timeout = new TimeSpan(0, 5, 0); //default timeout = 5min DateTime dStart = DateTime.Now; TimeSpan dDuration = DateTime.Now - dStart; using (PowerShell PowerShellInstance = PowerShell.Create()) { Trace.WriteLine(DateTime.Now.ToString() + "\t run PS... " + s1); try { PowerShellInstance.AddScript(s1); PSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject>(); outputCollection.DataAdding += ConsoleOutput; PowerShellInstance.Streams.Error.DataAdding += ConsoleError; IAsyncResult async = PowerShellInstance.BeginInvoke <PSObject, PSObject>(null, outputCollection); while (async.IsCompleted == false || dDuration > timeout) { Thread.Sleep(200); dDuration = DateTime.Now - dStart; if (tReInit.Interval > 5000) { tReInit.Interval = 5000; } } //var PSResult = PowerShellInstance.Invoke(); //if (PSResult.Count() > 0) //{ // string sResult = PSResult.Last().BaseObject.ToString(); // if (sResult != sScriptResult) // { // sScriptResult = sResult; // Trace.WriteLine(" done. Result: " + sResult); // Random rnd = new Random(); // tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit // } //} //else //{ // Trace.WriteLine(" done. no result."); //} } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } } Program.MinimizeFootprint(); }); //New 0.9.0.6 myHub.On <string, string>("returnPSAsync", (s1, s2) => { Trace.WriteLine(DateTime.Now.ToString() + "\t run PS async... " + s1); var tSWScan = Task.Run(() => { using (PowerShell PowerShellInstance = PowerShell.Create()) { try { PowerShellInstance.AddScript(s1); var PSResult = PowerShellInstance.Invoke(); if (PSResult.Count() > 0) { string sResult = PSResult.Last().BaseObject.ToString(); if (!string.IsNullOrEmpty(sResult)) //Do not return empty results { if (sResult != sScriptResult) { sScriptResult = sResult; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit } } } } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } } Program.MinimizeFootprint(); }); }); myHub.On <string>("init", (s1) => { try { Trace.Write(DateTime.Now.ToString() + "\t Agent init... "); myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 => { }); Trace.WriteLine(" done."); } catch { } try { foreach (string sGroup in Properties.Settings.Default.Groups.Split(';')) { myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task1 => { }); } Program.MinimizeFootprint(); } catch { } }); myHub.On <string>("reinit", (s1) => { try { //Properties.Settings.Default.InventorySuccess = new DateTime(); //Properties.Settings.Default.HealthCheckSuccess = new DateTime(); //Properties.Settings.Default.Save(); Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } catch { } }); myHub.On <string>("status", (s1) => { try { Trace.Write(DateTime.Now.ToString() + "\t send status..."); string sResult = "{}"; using (PowerShell PowerShellInstance = PowerShell.Create()) { try { PowerShellInstance.AddScript(Properties.Settings.Default.PSStatus); var PSResult = PowerShellInstance.Invoke(); if (PSResult.Count() > 0) { sResult = PSResult.Last().BaseObject.ToString(); sResult = sResult.Replace(Environment.MachineName, Hostname); JObject jRes = JObject.Parse(sResult); jRes.Add("ScriptResult", sScriptResult); jRes.Add("Groups", Properties.Settings.Default.Groups); sResult = jRes.ToString(); } } catch (Exception ex) { Console.WriteLine(" There was an error: {0}", ex.Message); } } myHub.Invoke("Status", new object[] { Hostname, sResult }).ContinueWith(task1 => { }); Trace.WriteLine(" done."); Program.MinimizeFootprint(); } catch (Exception ex) { Trace.Write(DateTime.Now.ToString() + " ERROR: " + ex.Message); } }); myHub.On <string>("version", (s1) => { try { Trace.Write(DateTime.Now.ToString() + "\t Get Version... "); //Get File-Version sScriptResult = (FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)).FileVersion.ToString(); Trace.WriteLine(sScriptResult); Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } catch (Exception ex) { Trace.Write(DateTime.Now.ToString() + " ERROR: " + ex.Message); } }); myHub.On <string>("wol", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { foreach (string sMAC in s1.Split(';')) { try { WOL.WakeUp(sMAC); //Send Broadcast //Send to local Gateway foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces()) { if (f.OperationalStatus == OperationalStatus.Up) { foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses) { //Only use IPv4 if (d.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { WOL.WakeUp(d.Address, 9, sMAC); } } } } } catch { } } } } catch { } }); myHub.On <string>("setinstance", (s1) => { Trace.WriteLine(DateTime.Now.ToString() + "\t Set instance: " + s1); try { if (!string.IsNullOrEmpty(s1)) { string sConfig = Assembly.GetExecutingAssembly().Location + ".config"; XmlDocument doc = new XmlDocument(); doc.Load(sConfig); doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Instance']/value").InnerText = s1; doc.Save(sConfig); RestartService(); //Update Advanced Installer Persistent Properties RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true); if (myKey != null) { myKey.SetValue("INSTANCE", s1.Trim(), RegistryValueKind.String); myKey.Close(); } } } catch { } }); myHub.On <string>("setendpoint", (s1) => { Trace.WriteLine(DateTime.Now.ToString() + "\t Set Endpoint: " + s1); try { if (!string.IsNullOrEmpty(s1)) { if (s1.StartsWith("https://")) { string sConfig = Assembly.GetExecutingAssembly().Location + ".config"; XmlDocument doc = new XmlDocument(); doc.Load(sConfig); doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Endpoint']/value").InnerText = s1; doc.Save(sConfig); RestartService(); //Update Advanced Installer Persistent Properties RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true); if (myKey != null) { myKey.SetValue("ENDPOINT", s1.Trim(), RegistryValueKind.String); myKey.Close(); } } } } catch { } }); myHub.On <string>("setgroups", (s1) => { Trace.WriteLine(DateTime.Now.ToString() + "\t Set Groups: " + s1); try { if (!string.IsNullOrEmpty(s1)) { string sConfig = Assembly.GetExecutingAssembly().Location + ".config"; XmlDocument doc = new XmlDocument(); doc.Load(sConfig); doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Groups']/value").InnerText = s1; doc.Save(sConfig); RestartService(); //Update Advanced Installer Persistent Properties RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true); if (myKey != null) { myKey.SetValue("GROUPS", s1.Trim(), RegistryValueKind.String); myKey.Close(); } } } catch { } }); myHub.On <string>("getgroups", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { sScriptResult = Properties.Settings.Default.Groups; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } } catch { } }); myHub.On <string>("restartservice", (s1) => { try { RestartService(); sScriptResult = "restart Agent..."; } catch { } }); myHub.On <string>("rzinstall", (s1) => { RZInst(s1); }); myHub.On <string>("rzupdate", (s1) => { var tSWScan = Task.Run(() => { try { sScriptResult = "Detecting RZ updates..."; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit RZUpdater oUpdate = new RZUpdater(); RZScan oScan = new RZScan(false, false); oScan.GetSWRepository().Wait(30000); oScan.SWScan().Wait(30000); oScan.CheckUpdates(null).Wait(60000); if (string.IsNullOrEmpty(s1)) { sScriptResult = oScan.NewSoftwareVersions.Count.ToString() + " RZ updates found"; rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } List <string> lSW = new List <string>(); foreach (var oSW in oScan.NewSoftwareVersions) { if (string.IsNullOrEmpty(s1) || s1 == "HUB") { RZInst(oSW.ShortName); } else { var SWList = s1.Split(';'); if (SWList.Contains(oSW.ShortName)) { RZInst(oSW.ShortName); } } } } catch { } }); }); myHub.On <string>("rzscan", (s1) => { var tSWScan = Task.Run(() => { try { sScriptResult = "Detecting updates..."; Random rnd = new Random(); tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit RZUpdater oUpdate = new RZUpdater(); RZScan oScan = new RZScan(false, false); oScan.GetSWRepository().Wait(30000); oScan.SWScan().Wait(30000); oScan.CheckUpdates(null).Wait(30000); List <string> lSW = new List <string>(); foreach (var SW in oScan.NewSoftwareVersions) { lSW.Add(SW.ShortName + " " + SW.ProductVersion + " (old:" + SW.MSIProductID + ")"); } sScriptResult = JsonConvert.SerializeObject(lSW); rnd = new Random(); tReInit.Interval = rnd.Next(2000, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } catch { } }); }); myHub.On <string>("inject", (s1) => { var tSWScan = Task.Run(() => { try { sScriptResult = "Inject external code..."; try { ManagedInjection.Inject(s1); sScriptResult = "External code executed."; } catch (Exception ex) { sScriptResult = "Injection error:" + ex.Message; } } catch { } }); }); myHub.On <string, string>("userprocess", (cmd, arg) => { var tSWScan = Task.Run(() => { if (string.IsNullOrEmpty(cmd)) { cmd = Assembly.GetExecutingAssembly().Location; arg = Environment.MachineName + ":" + "%USERNAME%"; } try { if (string.IsNullOrEmpty(arg)) { ProcessExtensions.StartProcessAsCurrentUser(cmd, null, null, false); } else { ProcessExtensions.StartProcessAsCurrentUser(null, cmd + " " + arg, null, false); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }); }); myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 => { try { if (task1.IsFaulted) { Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException()); } else { try { foreach (string sGroup in Properties.Settings.Default.Groups.Split(';')) { myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task2 => { }); } Program.MinimizeFootprint(); } catch { } } } catch { } }); } }).Wait(); } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } }
static int Main(string[] args) { bool bError = false; //Get Proxy from IE WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy(); if (!string.IsNullOrEmpty(Properties.Settings.Default.Customerid)) { RZRestAPIv2.CustomerID = Properties.Settings.Default.Customerid; } RZRestAPIv2.DisableBroadcast = Properties.Settings.Default.DisableBroadcast; List <string> lArgs = args.ToList(); if (lArgs.Contains("-?") | lArgs.Contains("/?") | lArgs.Count < 1) { Console.WriteLine("RuckZuck CommandLine Tool (c) 2021 by Roger Zander"); Console.WriteLine("Install:"); Console.WriteLine("Install a Software from Shortname : RZGet.exe install \"<Shortname>\"[;\"<Shortname2>\"]"); Console.WriteLine("Install a Software from JSON File : RZGet.exe install \"<JSON full path>\"[;\"<JSON full path>\"]"); Console.WriteLine("Install a Sepcific Version : RZGet.exe install --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\""); Console.WriteLine(""); Console.WriteLine("Update:"); Console.WriteLine("Update all missing updates : RZGet.exe update --all [--retry]"); Console.WriteLine("Update all missing updates : RZGet.exe update --all --exclude \"<Shortname>\"[;\"<Shortname2>\"] [--retry]"); Console.WriteLine("Show all missing updates : RZGet.exe update --list --all"); Console.WriteLine("check if a Software requires an update : RZGet.exe update --list \"<Shortname>\""); Console.WriteLine("Update a Software from Shortname : RZGet.exe update \"<Shortname>\"[;\"<Shortname2>\"] [--retry]"); Console.WriteLine(""); Console.WriteLine("Show:"); Console.WriteLine("Show Metadata : RZGet.exe show \"<Shortname>\""); Console.WriteLine("Show Metadata for a specific Version : RZGet.exe show --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\""); Console.WriteLine(""); Console.WriteLine("Search:"); Console.WriteLine("Show full Catalog JSON: RZGet.exe search"); Console.WriteLine("Search for a Keyword: RZGet.exe search zip"); Console.WriteLine("Search SW in a Category: RZGet.exe search --categories compression"); Console.WriteLine("Search for installed SW: RZGet.exe search --isinstalled true"); Console.WriteLine("Search for a manufacturer: RZGet.exe search --manufacturer zander"); Console.WriteLine("Search for a shortname and return PowerShell Object: RZGet.exe search --shortname ruckzuck | convertfrom-json"); return(0); } if (lArgs[0].ToLower() == "install") { if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase)) { try { RZUpdater oRZSW = new RZUpdater(); string ProductName = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; string Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; if (string.IsNullOrEmpty(Manufacturer)) { Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; } string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!"); return(99); } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + oRZSW.SoftwareUpdate.SW.ShortName + "'...!"); return(91); } } if (Install(oRZSW)) { return(0); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(1); } } if (lArgs.Contains("--retry")) { bRetry = true; } if (lArgs.Contains("--noretry")) { bRetry = false; } foreach (string sArg in args.Skip(1)) { if (!sArg.StartsWith("--")) { if (File.Exists(sArg) || File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg)) || File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg + ".json"))) { string sJFile = sArg; if (!File.Exists(sJFile)) { sJFile = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg); } if (!File.Exists(sJFile)) { sJFile = Path.Combine(Environment.ExpandEnvironmentVariables("%TEMP%"), sArg + ".json"); } RZUpdater oRZSW = new RZUpdater(sJFile); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } else { try { RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); bError = true; } } } } if (bError) { return(1); } else { return(0); } } if (lArgs[0].ToLower() == "update") { if (lArgs.Contains("--retry")) { bRetry = true; } if (lArgs.Contains("--noretry")) { bRetry = false; } bool bUpdateAll = false; bool bList = false; bool bExclude = false; List <string> lExclude = new List <string>(); if (lArgs.Contains("--all", StringComparer.CurrentCultureIgnoreCase)) { bUpdateAll = true; } if (lArgs.Contains("--list", StringComparer.CurrentCultureIgnoreCase)) { bList = true; } if (lArgs.Contains("--exclude", StringComparer.CurrentCultureIgnoreCase)) { bExclude = true; } RZScan oScan = new RZScan(false); oScan.GetSWRepository().Wait(10000); oScan.SWScanAsync().Wait(10000); oScan._CheckUpdates(null); List <string> lUpdate = new List <string>(); if (!bUpdateAll) { foreach (string sArg in args.Skip(1)) { if (oScan.NewSoftwareVersions.Count(t => t.ShortName.ToLower() == sArg.ToLower()) > 0) { lUpdate.Add(sArg); } } } else { if (!bExclude) { lUpdate = oScan.NewSoftwareVersions.Select(t => t.ShortName).ToList(); } else { int iex = lArgs.IndexOf("--exclude", 0); string scl = lArgs[iex + 1]; lExclude = scl.ToLower().Split(';').ToList(); lUpdate = oScan.NewSoftwareVersions.Where(r => !lExclude.Contains(r.ShortName.ToLower())).Select(t => t.ShortName.ToLower()).ToList(); } } foreach (string sArg in lUpdate) { if (bList) { Console.WriteLine(sArg); continue; } if (File.Exists(sArg)) { RZUpdater oRZSW = new RZUpdater(sArg); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } else { try { RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); bError = true; } } } if (bError) { return(1); } else { return(0); } } //if (lArgs[0].ToLower() == "hash") //{ // Console.WriteLine("hash"); // Console.WriteLine(string.Join(";", args.Skip(1))); // return 0; //} if (lArgs[0].ToLower() == "search") { if (lArgs.Count > 1) { if (lArgs[1].StartsWith("--")) { string sProp = lArgs[1].ToLower().TrimStart('-'); string sSearch = lArgs[2].ToLower(); if (sProp == "shortname") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "manufacturer") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "productname" || sProp == "name") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "description") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Description.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "categories" || sProp == "category") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => string.Join(";", t.Categories.ToArray()).ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "producturl" || sProp == "url") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductURL.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "productversion" || sProp == "version") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductVersion.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "isinstalled") { oScan = new RZScan(false, false); oScan.SWScanAsync().Wait(); oScan.GetSWRepository().Wait(); foreach (var osw in oScan.InstalledSoftware) { var oItem = oScan.SoftwareRepository.FirstOrDefault(t => t.ProductName == osw.ProductName && t.Manufacturer == osw.Manufacturer && t.ProductVersion == osw.ProductVersion); if (oItem != null) { oItem.isInstalled = true; } } Console.WriteLine(JsonConvert.SerializeObject(oScan.SoftwareRepository.Where(t => t.isInstalled.ToString().ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } } else { string sSearch = lArgs[1].ToLower(); Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch) || t.Manufacturer.ToLower().Contains(sSearch) || t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } } else { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog(), Formatting.Indented).ToString()); } return(0); } if (lArgs[0].ToLower() == "show") { if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase)) { try { RZUpdater oRZSW = new RZUpdater(); string ProductName = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; string Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; if (string.IsNullOrEmpty(Manufacturer)) { Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; } string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!"); return(99); } Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString()); return(0); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(1); } } foreach (string sArg in args.Skip(1)) { if (File.Exists(sArg)) { RZUpdater oRZSW = new RZUpdater(sArg); Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString()); } else { try { RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString()); return(0); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(1); } } } return(0); } return(0); }
static int Main(string[] args) { bool bError = false; //Get Proxy from IE WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy(); if (!string.IsNullOrEmpty(Properties.Settings.Default.Customerid)) { RZRestAPIv2.CustomerID = Properties.Settings.Default.Customerid; } RZRestAPIv2.DisableBroadcast = Properties.Settings.Default.DisableBroadcast; List <string> lArgs = args.ToList(); if (lArgs.Contains("-?") | lArgs.Contains("/?") | lArgs.Count < 1) { Console.WriteLine("RuckZuck CommandLine Tool (c) 2020 by Roger Zander"); Console.WriteLine("Install:"); Console.WriteLine("Install a Software from Shortname : RZGet.exe install \"<Shortname>\"[;\"<Shortname2>\"]"); Console.WriteLine("Install a Software from JSON File : RZGet.exe install \"<JSON full path>\"[;\"<JSON full path>\"]"); Console.WriteLine("Install a Sepcific Version : RZGet.exe install --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\""); Console.WriteLine(""); Console.WriteLine("Update:"); Console.WriteLine("Update all missing updates : RZGet.exe update --all"); Console.WriteLine("Show all missing updates : RZGet.exe update --list --all"); Console.WriteLine("check if a Software requires an update : RZGet.exe update --list \"<Shortname>\""); Console.WriteLine("Update a Software from Shortname : RZGet.exe update \"<Shortname>\"[;\"<Shortname2>\"]"); Console.WriteLine(""); Console.WriteLine("Show:"); Console.WriteLine("Show Metadata : RZGet.exe show \"<Shortname>\""); Console.WriteLine("Show Metadata for a specific Version : RZGet.exe show --name \"<ProductName>\" --vendor \"<Manufacturer>\" --version \"<ProductVersion>\""); Console.WriteLine(""); Console.WriteLine("Search:"); Console.WriteLine("Show full Catalog JSON: RZGet.exe search"); Console.WriteLine("Search for a Keyword: RZGet.exe search zip"); Console.WriteLine("Search SW in a Category: RZGet.exe search --categories compression"); Console.WriteLine("Search for installed SW: RZGet.exe search --isinstalled true"); Console.WriteLine("Search for a manufacturer: RZGet.exe search --manufacturer zander"); Console.WriteLine("Search for a shortname and return PowerShell Object: RZGet.exe search --shortname ruckzuck | convertfrom-json"); return(0); } if (lArgs[0].ToLower() == "install") { if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase)) { try { RZUpdater oRZSW = new RZUpdater(); string ProductName = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; string Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; if (string.IsNullOrEmpty(Manufacturer)) { Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; } string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!"); return(99); } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + oRZSW.SoftwareUpdate.SW.ShortName + "'...!"); return(91); } } if (Install(oRZSW)) { return(0); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(1); } } foreach (string sArg in args.Skip(1)) { if (File.Exists(sArg)) { RZUpdater oRZSW = new RZUpdater(sArg); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } else { try { RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); bError = true; } } } if (bError) { return(1); } else { return(0); } } if (lArgs[0].ToLower() == "update") { bool bUpdateAll = false; bool bList = false; if (lArgs.Contains("--all", StringComparer.CurrentCultureIgnoreCase)) { bUpdateAll = true; } if (lArgs.Contains("--list", StringComparer.CurrentCultureIgnoreCase)) { bList = true; } RZScan oScan = new RZScan(false); oScan.GetSWRepository().Wait(10000); oScan.SWScanAsync().Wait(10000); oScan._CheckUpdates(null); List <string> lUpdate = new List <string>(); if (!bUpdateAll) { foreach (string sArg in args.Skip(1)) { if (oScan.NewSoftwareVersions.Count(t => t.ShortName.ToLower() == sArg.ToLower()) > 0) { lUpdate.Add(sArg); } } } else { lUpdate = oScan.NewSoftwareVersions.Select(t => t.ShortName).ToList(); } foreach (string sArg in lUpdate) { if (bList) { Console.WriteLine(sArg); continue; } if (File.Exists(sArg)) { RZUpdater oRZSW = new RZUpdater(sArg); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } else { try { RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { oRZSW.SoftwareUpdate.GetInstallType(); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) { Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); bError = false; continue; } } if (Install(oRZSW)) { continue; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); bError = true; } } } if (bError) { return(1); } else { return(0); } } //if (lArgs[0].ToLower() == "hash") //{ // Console.WriteLine("hash"); // Console.WriteLine(string.Join(";", args.Skip(1))); // return 0; //} if (lArgs[0].ToLower() == "search") { if (lArgs[1] != null) { if (lArgs[1].StartsWith("--")) { string sProp = lArgs[1].ToLower().TrimStart('-'); string sSearch = lArgs[2].ToLower(); if (sProp == "shortname") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "manufacturer") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Manufacturer.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "productname" || sProp == "name") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "description") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.Description.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "categories" || sProp == "category") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => string.Join(";", t.Categories.ToArray()).ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "producturl" || sProp == "url") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductURL.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "productversion" || sProp == "version") { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductVersion.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } if (sProp == "isinstalled") { oScan = new RZScan(false, false); oScan.SWScanAsync().Wait(); oScan.GetSWRepository().Wait(); foreach (var osw in oScan.InstalledSoftware) { var oItem = oScan.SoftwareRepository.FirstOrDefault(t => t.ProductName == osw.ProductName && t.Manufacturer == osw.Manufacturer && t.ProductVersion == osw.ProductVersion); if (oItem != null) { oItem.isInstalled = true; } } Console.WriteLine(JsonConvert.SerializeObject(oScan.SoftwareRepository.Where(t => t.isInstalled.ToString().ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } } else { string sSearch = lArgs[1].ToLower(); Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog().Where(t => t.ProductName.ToLower().Contains(sSearch) || t.Manufacturer.ToLower().Contains(sSearch) || t.ShortName.ToLower().Contains(sSearch)), Formatting.Indented).ToString()); } } else { Console.WriteLine(JsonConvert.SerializeObject(RZRestAPIv2.GetCatalog(), Formatting.Indented).ToString()); } return(0); } if (lArgs[0].ToLower() == "show") { if (lArgs.Contains("--name", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--vendor", StringComparer.CurrentCultureIgnoreCase) || lArgs.Contains("--version", StringComparer.CurrentCultureIgnoreCase)) { try { RZUpdater oRZSW = new RZUpdater(); string ProductName = lArgs[lArgs.FindIndex(t => t.IndexOf("--name", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; string Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--vendor", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; if (string.IsNullOrEmpty(Manufacturer)) { Manufacturer = lArgs[lArgs.FindIndex(t => t.IndexOf("--manufacturer", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; } string ProductVersion = lArgs[lArgs.FindIndex(t => t.IndexOf("--version", StringComparison.CurrentCultureIgnoreCase) >= 0) + 1]; oRZSW.SoftwareUpdate = new SWUpdate(ProductName, ProductVersion, Manufacturer); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + ProductName + "' is NOT available in RuckZuck...!"); return(99); } Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString()); return(0); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(1); } } foreach (string sArg in args.Skip(1)) { if (File.Exists(sArg)) { RZUpdater oRZSW = new RZUpdater(sArg); Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString()); } else { try { RZUpdater oRZSW = new RZUpdater(); oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) { Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); bError = true; continue; } Console.WriteLine(JsonConvert.SerializeObject(oRZSW.SoftwareUpdate.SW, Formatting.Indented).ToString()); return(0); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(1); } } } return(0); } //if (lArgs[0].ToLower() == "source") //{ // Console.WriteLine("source"); // Console.WriteLine(string.Join(";", args.Skip(1))); // return 0; //} //if (lArgs[0].ToLower() == "validate") //{ // Console.WriteLine("validate"); // Console.WriteLine(string.Join(";", args.Skip(1))); // return 0; //} //if (lArgs.Count == 1) //{ // if (File.Exists(lArgs[0])) // { // RZUpdater oRZSW = new RZUpdater(lArgs[0]); // Console.WriteLine(oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion + " :"); // Console.Write("Downloading..."); // if (oRZSW.SoftwareUpdate.Download().Result) // { // Console.WriteLine("... done."); // Console.Write("Installing..."); // if (oRZSW.SoftwareUpdate.Install(false,true).Result) // { // Console.WriteLine("... done."); // } // else // { // Console.WriteLine("... Error. The installation failed."); // } // } // } // else // { // if (lArgs[0].ToLower() == "/update" | lArgs[0].ToLower() == "-update") // { // oUpdate = new RZUpdater(); // oScan = new RZScan(true, true); // Console.Write("Detecting updates..."); // oScan.OnUpdScanCompleted += OScan_OnUpdScanCompleted; // while (bRunning) // { // System.Threading.Thread.Sleep(100); // } // } // else // { // foreach (string sArg in lArgs[0].Split(';')) // { // try // { // RZUpdater oRZSW = new RZUpdater(); // oRZSW.SoftwareUpdate = new SWUpdate(sArg.Trim('"').Trim()); // if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.ProductName)) // { // Console.WriteLine("'" + sArg + "' is NOT available in RuckZuck...!"); // bError = true; // continue; // } // Console.WriteLine("PS:" + oRZSW.SoftwareUpdate.SW.PSInstall); // if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) // { // oRZSW.SoftwareUpdate.GetInstallType(); // if (string.IsNullOrEmpty(oRZSW.SoftwareUpdate.SW.PSInstall)) // { // Console.WriteLine("PreRequisites not valid for '" + sArg + "'...!"); // bError = false; // continue; // } // } // Console.WriteLine(oRZSW.SoftwareUpdate.SW.Manufacturer + " " + oRZSW.SoftwareUpdate.SW.ProductName + " " + oRZSW.SoftwareUpdate.SW.ProductVersion); // Console.Write("Downloading..."); // foreach (string sPreReq in oRZSW.SoftwareUpdate.SW.PreRequisites) // { // if (!string.IsNullOrEmpty(sPreReq)) // { // RZUpdater oRZSWPreReq = new RZUpdater(); // oRZSWPreReq.SoftwareUpdate = new SWUpdate(sPreReq); // Console.WriteLine(); // Console.Write("\tDownloading dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.ShortName + ")..."); // if (oRZSWPreReq.SoftwareUpdate.Download().Result) // { // Console.WriteLine("... done."); // Console.Write("\tInstalling dependencies (" + oRZSWPreReq.SoftwareUpdate.SW.ShortName + ")..."); // if (oRZSWPreReq.SoftwareUpdate.Install(false, true).Result) // { // Console.WriteLine("... done."); // } // else // { // Console.WriteLine("... Error. The installation failed."); // bError = true; // } // } // } // } // if (oRZSW.SoftwareUpdate.Download().Result) // { // Console.WriteLine("... done."); // Console.Write("Installing..."); // if (oRZSW.SoftwareUpdate.Install(false, true).Result) // { // Console.WriteLine("... done."); // } // else // { // Console.WriteLine("... Error. The installation failed."); // bError = true; // } // } // } // catch (Exception ex) // { // Console.WriteLine("Error: " + ex.Message); // bError = true; // } // } // } // } //} //if (lArgs.Count == 3) //{ // RZUpdater oRZUpdate = new RZUpdater(); // oRZUpdate.SoftwareUpdate = new SWUpdate(lArgs[0], lArgs[1], lArgs[2]); // if (oRZUpdate.SoftwareUpdate != null) // { // Console.WriteLine("New Version: " + oRZUpdate.SoftwareUpdate.SW.ProductVersion); // Console.Write("Downloading..."); // if (oRZUpdate.SoftwareUpdate.Download().Result) // { // Console.WriteLine("... done."); // Console.Write("Installing..."); // if (oRZUpdate.SoftwareUpdate.Install(false, true).Result) // { // Console.WriteLine("... done."); // return 0; // } // else // { // Console.WriteLine("... Error. The update installation failed."); // return 1; // } // } // return 99; // } // else // { // Console.WriteLine("No Update found..."); // return 0; // } //} //System.Threading.Thread.Sleep(500); //if(bError) // return 2; return(0); }
//public event ChangedEventHandler onEdit; public InstallSwPanel() { InitializeComponent(); tSearch.Elapsed += TSearch_Elapsed; tSearch.Enabled = false; tSearch.AutoReset = false; Mouse.OverrideCursor = Cursors.Wait; try { if (string.IsNullOrEmpty(sAuthToken)) { sAuthToken = RZRestAPI.GetAuthToken("FreeRZ", GetTimeToken()); } RZRestAPI.Token = sAuthToken; RZScan oSCAN = new RZScan(false, false); Task.Run(() => oSCAN.GetSWRepository()).Wait(); lAllSoftware = oSCAN.SoftwareRepository; List <GetSoftware> oDBCat = new List <GetSoftware>(); PropertyGroupDescription PGD = new PropertyGroupDescription("", new ShortnameToCategory()); foreach (GetSoftware oSW in oSCAN.SoftwareRepository) { try { if (oSW.Categories.Count > 1) { foreach (string sCAT in oSW.Categories) { try { //Check if SW is already installed if (lSoftware.FirstOrDefault(t => t.ProductName == oSW.ProductName & t.ProductVersion == oSW.ProductVersion) != null) { GetSoftware oNew = new GetSoftware() { Categories = new List <string> { sCAT }, Description = oSW.Description, Downloads = oSW.Downloads, IconId = oSW.IconId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, Quality = oSW.Quality, Shortname = oSW.Shortname, isInstalled = true }; oDBCat.Add(oNew); } else { GetSoftware oNew = new GetSoftware() { Categories = new List <string> { sCAT }, Description = oSW.Description, Downloads = oSW.Downloads, IconId = oSW.IconId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, Quality = oSW.Quality, Shortname = oSW.Shortname, isInstalled = false }; oDBCat.Add(oNew); } } catch { } } } else { //Check if SW is already installed if (lSoftware.FirstOrDefault(t => t.ProductName == oSW.ProductName & t.ProductVersion == oSW.ProductVersion) != null) { oDBCat.Add(new GetSoftware() { Categories = oSW.Categories, Description = oSW.Description, Downloads = oSW.Downloads, IconId = oSW.IconId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, Quality = oSW.Quality, Shortname = oSW.Shortname, isInstalled = true }); } else { oDBCat.Add(new GetSoftware() { Categories = oSW.Categories, Description = oSW.Description, Downloads = oSW.Downloads, IconId = oSW.IconId, Manufacturer = oSW.Manufacturer, ProductName = oSW.ProductName, ProductURL = oSW.ProductURL, ProductVersion = oSW.ProductVersion, Quality = oSW.Quality, Shortname = oSW.Shortname, isInstalled = false }); } } } catch { } } ListCollectionView lcv = new ListCollectionView(oDBCat.ToList()); foreach (var o in RZRestAPI.GetCategories(oSCAN.SoftwareRepository)) { PGD.GroupNames.Add(o); } lcv.GroupDescriptions.Add(PGD); lvSW.ItemsSource = lcv; } catch { } Mouse.OverrideCursor = null; }
private void Connect() { try { connection.Stop(); connection.Start().ContinueWith(task => { if (task.IsFaulted) { Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException()); } else { //Obsolete myHub.On <string, string>("getPS", (s1, s2) => { //using (PowerShell PowerShellInstance = PowerShell.Create()) //{ // try // { // PowerShellInstance.AddScript(s1); // var PSResult = PowerShellInstance.Invoke(); // if (PSResult.Count() > 0) // { // string sResult = PSResult.Last().BaseObject.ToString(); // if (sResult != sScriptResult) //obsolete from 1.0.07 -> returnPS // { // sScriptResult = sResult; // Random rnd = new Random(); // tReInit.Interval = rnd.Next(1000, 10000); //wait max 10s to ReInit // } // myHub.Invoke<string>("Respond", s2, Environment.MachineName + ":" + sResult).ContinueWith(task1 => // { // if (task1.IsFaulted) // { // Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException()); // } // }); // } // } // catch (Exception ex) // { // Console.WriteLine("There was an error: {0}", ex.Message); // } //} //Program.MinimizeFootprint(); }); myHub.On <string, string>("returnPS", (s1, s2) => { using (PowerShell PowerShellInstance = PowerShell.Create()) { try { PowerShellInstance.AddScript(s1); var PSResult = PowerShellInstance.Invoke(); if (PSResult.Count() > 0) { string sResult = PSResult.Last().BaseObject.ToString(); if (sResult != sScriptResult) { sScriptResult = sResult; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit } } } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } } Program.MinimizeFootprint(); }); //New 0.9.0.6 myHub.On <string, string>("returnPSAsync", (s1, s2) => { var tSWScan = Task.Run(() => { using (PowerShell PowerShellInstance = PowerShell.Create()) { try { PowerShellInstance.AddScript(s1); var PSResult = PowerShellInstance.Invoke(); if (PSResult.Count() > 0) { string sResult = PSResult.Last().BaseObject.ToString(); if (sResult != sScriptResult) { sScriptResult = sResult; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max Xs to ReInit } } } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } } Program.MinimizeFootprint(); }); }); myHub.On <string>("init", (s1) => { try { myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 => { }); } catch { } try { foreach (string sGroup in Properties.Settings.Default.Groups.Split(';')) { myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task1 => { }); } Program.MinimizeFootprint(); } catch { } }); myHub.On <string>("status", (s1) => { try { string sResult = "{}"; using (PowerShell PowerShellInstance = PowerShell.Create()) { try { PowerShellInstance.AddScript(Properties.Settings.Default.PSStatus); var PSResult = PowerShellInstance.Invoke(); if (PSResult.Count() > 0) { sResult = PSResult.Last().BaseObject.ToString(); sResult = sResult.Replace(Environment.MachineName, Hostname); JObject jRes = JObject.Parse(sResult); jRes.Add("ScriptResult", sScriptResult); jRes.Add("Groups", Properties.Settings.Default.Groups); sResult = jRes.ToString(); } } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } } myHub.Invoke("Status", new object[] { Hostname, sResult }).ContinueWith(task1 => { }); Program.MinimizeFootprint(); } catch { } }); myHub.On <string>("version", (s1) => { try { //Get File-Version sScriptResult = (FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)).FileVersion.ToString(); Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } catch { } }); myHub.On <string>("wol", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { foreach (string sMAC in s1.Split(';')) { WOL.WakeUp(sMAC); } } } catch { } }); myHub.On <string>("setinstance", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { string sConfig = Assembly.GetExecutingAssembly().Location + ".config"; XmlDocument doc = new XmlDocument(); doc.Load(sConfig); doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Instance']/value").InnerText = s1; doc.Save(sConfig); RestartService(); //Update Advanced Installer Persistent Properties RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true); if (myKey != null) { myKey.SetValue("INSTANCE", s1.Trim(), RegistryValueKind.String); myKey.Close(); } } } catch { } }); myHub.On <string>("setendpoint", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { if (s1.StartsWith("https://")) { string sConfig = Assembly.GetExecutingAssembly().Location + ".config"; XmlDocument doc = new XmlDocument(); doc.Load(sConfig); doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Endpoint']/value").InnerText = s1; doc.Save(sConfig); RestartService(); //Update Advanced Installer Persistent Properties RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true); if (myKey != null) { myKey.SetValue("ENDPOINT", s1.Trim(), RegistryValueKind.String); myKey.Close(); } } } } catch { } }); myHub.On <string>("setgroups", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { string sConfig = Assembly.GetExecutingAssembly().Location + ".config"; XmlDocument doc = new XmlDocument(); doc.Load(sConfig); doc.SelectSingleNode("/configuration/applicationSettings/DevCDRAgent.Properties.Settings/setting[@name='Groups']/value").InnerText = s1; doc.Save(sConfig); RestartService(); //Update Advanced Installer Persistent Properties RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Zander Tools\\{0AC43E24-4308-4BE7-A369-D50DB4056B32}", true); if (myKey != null) { myKey.SetValue("GROUPS", s1.Trim(), RegistryValueKind.String); myKey.Close(); } } } catch { } }); myHub.On <string>("getgroups", (s1) => { try { if (!string.IsNullOrEmpty(s1)) { sScriptResult = Properties.Settings.Default.Groups; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } } catch { } }); myHub.On <string>("restartservice", (s1) => { try { RestartService(); sScriptResult = "restart Agent..."; } catch { } }); myHub.On <string>("rzinstall", (s1) => { RZInst(s1); }); myHub.On <string>("rzupdate", (s1) => { var tSWScan = Task.Run(() => { try { sScriptResult = "Detecting RZ updates..."; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit RZUpdater oUpdate = new RZUpdater(); RZScan oScan = new RZScan(false, false); oScan.GetSWRepository().Wait(30000); oScan.SWScan().Wait(30000); oScan.CheckUpdates(null).Wait(30000); sScriptResult = oScan.NewSoftwareVersions.Count.ToString() + " RZ updates found"; rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit List <string> lSW = new List <string>(); foreach (var oSW in oScan.NewSoftwareVersions) { RZInst(oSW.Shortname); } } catch { } }); }); myHub.On <string>("rzscan", (s1) => { var tSWScan = Task.Run(() => { try { sScriptResult = "Detecting updates..."; Random rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit RZUpdater oUpdate = new RZUpdater(); RZScan oScan = new RZScan(false, false); oScan.GetSWRepository().Wait(30000); oScan.SWScan().Wait(30000); oScan.CheckUpdates(null).Wait(30000); List <string> lSW = new List <string>(); foreach (var SW in oScan.NewSoftwareVersions) { lSW.Add(SW.Shortname + " " + SW.ProductVersion + " (old:" + SW.MSIProductID + ")"); } sScriptResult = JsonConvert.SerializeObject(lSW); rnd = new Random(); tReInit.Interval = rnd.Next(200, Properties.Settings.Default.StatusDelay); //wait max 5s to ReInit } catch { } }); }); myHub.Invoke <string>("Init", Hostname).ContinueWith(task1 => { if (task1.IsFaulted) { Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException()); } else { try { foreach (string sGroup in Properties.Settings.Default.Groups.Split(';')) { myHub.Invoke <string>("JoinGroup", sGroup).ContinueWith(task2 => { }); } Program.MinimizeFootprint(); } catch { } } }); } }).Wait(); } catch (Exception ex) { Console.WriteLine("There was an error: {0}", ex.Message); } }