Beispiel #1
0
        public void TriggerClientAction(string scheduleId, ManagementScope remote)
        {
            ObjectQuery query           = new SelectQuery("SELECT * FROM meta_class WHERE __Class = 'SMS_Client'");
            var         eOption         = new EnumerationOptions();
            var         searcher        = new ManagementObjectSearcher(remote, query, eOption);
            var         queryCollection = searcher.Get();

            foreach (ManagementObject ro in queryCollection)
            {
                // Obtain in-parameters for the method
                var inParams = ro.GetMethodParameters("TriggerSchedule");

                // Add the input parameters.
                inParams["sScheduleID"] = scheduleId;

                try
                {
                    var outParams = ro.InvokeMethod("TriggerSchedule", inParams, null);

                    ResultConsole.Instance.AddConsoleLine($"Returned with value {_wmiServices.GetProcessReturnValueText(Convert.ToInt32(outParams["ReturnValue"]))}");
                }
                catch (Exception ex)
                {
                    ResultConsole.Instance.AddConsoleLine("Error performing SCCM Client Function due to an error.");
                    _logger.LogError($"Error performing SCCM Client Function due to the following error: {ex.Message}", ex);
                }
            }
        }
Beispiel #2
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            var connOps = new ConnectionOptions
            {
                EnablePrivileges = true
            };

            try
            {
                foreach (var device in devlist)
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        continue;
                    }

                    var remote = _wmiServices.ConnectToRemoteWmi(device, _wmiServices.RootNamespace, connOps);
                    if (remote != null)
                    {
                        ObjectQuery query = new SelectQuery("Win32_OperatingSystem");

                        var searcher        = new ManagementObjectSearcher(remote, query);
                        var queryCollection = searcher.Get();

                        foreach (var resultobject in queryCollection)
                        {
                            var ro = resultobject as ManagementObject;
                            // Obtain in-parameters for the method
                            var inParams = ro.GetMethodParameters("Win32Shutdown");

                            // Add the input parameters.
                            inParams["Flags"] = 4;

                            try
                            {
                                // Execute the method and obtain the return values.
                                var outParams = ro.InvokeMethod("Win32Shutdown", inParams, null);

                                ResultConsole.AddConsoleLine($"Returned with value {_wmiServices.GetProcessReturnValueText(Convert.ToInt32(outParams["ReturnValue"]))}");
                            }
                            catch (Exception e)
                            {
                                ResultConsole.AddConsoleLine($"Error running {ActionName} due to a .Net ManagementExcept error. There are likely no users logged on!");
                                Logger.LogWarning($"Error running {ActionName} due to a .Net ManagementExcept error.", e);
                            }
                        }
                    }
                    else
                    {
                        Logger.LogWarning($"There was an error connecting to WMI namespace on {device}", null);
                        ResultConsole.AddConsoleLine($"There was an error connecting to WMI namespace on {device}");
                    }
                }
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }