Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public WqlConnectionManager Connect()
        {
            System.Diagnostics.StackFrame sf;
            sf = new System.Diagnostics.StackFrame();
            string methodName = sf.GetMethod().Name;
            string userName;
            WqlConnectionManager     connection  = new WqlConnectionManager();
            SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();

            try
            {
                _log.Write(_className, methodName, _serverCode, "Starting the function " + methodName);
                _log.Write(_className, methodName, _serverCode, "WQL connection in progress : " + _serverName + " | Site code : " + _serverCode);
                connection = new WqlConnectionManager(namedValues);
                if (!string.IsNullOrEmpty(_sccmUserDomain) & !string.IsNullOrEmpty(_sccmUser) & !string.IsNullOrEmpty(_sccmUserPassword))
                {
                    userName = _sccmUserDomain + "\\" + _sccmUser;
                    _log.Write(_className, methodName, _serverCode, "Associated user : "******"WQL connection on " + _serverName + " OK");

                return(connection);
            }
            catch (SmsException ex)
            {
                _log.Write(_className, methodName, "Exception", "WARNING : General connection failed");
                _log.Write(_className, methodName, "Exception", ex.Message.ToString());
                connection.Close();
                connection.Dispose();
                throw new Exception("WARNING : " + ex.Message.ToString());
            }
            catch (UnauthorizedAccessException ex)
            {
                _log.Write(_className, methodName, "Exception", "WARNING : Authentication failed");
                _log.Write(_className, methodName, "Exception", ex.Message.ToString());
                connection.Close();
                connection.Dispose();
                throw new Exception("WARNING : " + ex.Message.ToString());
            }
            catch (Exception ex)
            {
                _log.Write(_className, methodName, "Exception", "WARNING : DCOM Connection failed");
                _log.Write(_className, methodName, "Exception", ex.Message.ToString());
                connection.Close();
                connection.Dispose();
                throw new Exception("WARNING : " + ex.Message.ToString());
            }
            finally
            {
                _log.Write(_className, methodName, _serverCode, "End of the function " + methodName);
            }
        }
Esempio n. 2
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            SCCMServer = settings.SCCMSERVER;
            userName   = settings.UserName;
            password   = settings.Password;

            String objID = request.Inputs["Package ID"].AsString();

            //Setup WQL Connection and WMI Management Scope
            WqlConnectionManager connection = CMInterop.connectSCCMServer(SCCMServer, userName, password);

            try
            {
                String[] propertyNameChoices = CMInterop.getSCCMObjectPropertyNames(connection, "SMS_TaskSequencePackage");
                foreach (String propertyName in propertyNameChoices)
                {
                    if ((request.Inputs.Contains(propertyName + " : Property Type")) && (request.Inputs.Contains(propertyName + " : Property Value")))
                    {
                        CMInterop.modifySCCMTaskSequencePackage(connection, objID, request.Inputs[(propertyName + " : Property Type")].AsString(), propertyName, request.Inputs[(propertyName + " : Property Value")].AsString());
                    }
                }

                IResultObject col = CMInterop.getSCCMTaskSequencePackage(connection, "PackageID LIKE '" + objID + "'");
                if (col != null)
                {
                    response.WithFiltering().PublishRange(getObjects(col));
                }
                response.Publish("Number of Task Sequence Packages", ObjCount);
            }
            finally
            {
                connection.Close();
                connection.Dispose();
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        public Boolean Disconnect(WqlConnectionManager wqlConnection)
        {
            System.Diagnostics.StackFrame sf;
            sf = new System.Diagnostics.StackFrame();
            string methodName = sf.GetMethod().Name;

            try
            {
                _log.Write(_className, methodName, _serverCode, "Starting the function " + methodName);
                _log.Write(_className, methodName, _serverCode, "Closing WQL connection " + _serverName);
                wqlConnection.Close();
                wqlConnection.Dispose();
                _log.Write(_className, methodName, _serverCode, "WQL Connection Opening " + _serverName + " OK");
                return(true);
            }
            catch (Exception ex)
            {
                _log.Write(_className, methodName, "Exception", "WARNING : Error closing WQL connection");
                _log.Write(_className, methodName, "Exception", ex.Message.ToString());
                throw new Exception("WARNING : " + ex.Message.ToString());
            }
            finally
            {
                _log.Write(_className, methodName, _serverCode, "End of the function " + methodName);
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     The main entry point for the wrapper. Uncomment the snippets you wish to run here.
        /// </summary>
        public void Run()
        {
            var computer = "";
            var userName = "";
            var password = "";

            Console.WriteLine("Site server you want to connect to (press Return for this computer): ");
            computer = Console.ReadLine();
            Console.WriteLine();

            if (string.IsNullOrEmpty(computer) || computer == ".")
            {
                computer = Dns.GetHostName();
                userName = "";
                password = "";
            }
            else
            {
                Console.WriteLine("Please enter the user name (press Return for current user): ");
                userName = Console.ReadLine();

                if (!string.IsNullOrEmpty(userName))
                {
                    Console.WriteLine("Please enter your password: ");
                    password = ReturnPassword();
                }
            }

            // Make connection to provider.
            WqlConnectionManager wqlConnection = Connect(computer, userName, password);

            if (wqlConnection == null)
            {
                return;
            }

            //
            // Call snippets - uncomment required snippets.
            //

            //
            // Fundamentals
            //
            //IResultObjectExecuteQueryDisposalV1(wqlConnection);
            //IResultObjectExecuteQueryDisposalV2(wqlConnection);
            //IResultObjectDisposalOfReturnValue(wqlConnection);
            //LazyPropertyFromQuery(wqlConnection);

            // Disconnect
            wqlConnection.Close();
            wqlConnection.Dispose();
        }
Esempio n. 5
0
        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Settings     form   = new Settings(server, safety);
            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                String value = form.get_Safety();
                if (value == "")
                {
                    safety = 0;
                }
                else
                {
                    safety = Convert.ToInt32(value);
                }

                if (scope != null)
                {
                    scope.Close();
                }

                server = form.get_Server();
                scope  = Connect("\\" + server);

                exportRejection_List = form.export_Rejection();
                exportNode_List      = form.export_NodeList();
                exportSelection_Log  = form.export_Logging();

                form.Dispose();
            }
            else
            {
                form.Dispose();
            }
        }