예제 #1
0
        internal static CimSession CreateCimSession(
            string computerName,
            PSCredential credential,
            string authentication,
            bool isLocalHost,
            PSCmdlet cmdlet,
            CancellationToken cancellationToken)
        {
            if (isLocalHost)
            {
                return(CimSession.Create(null));
            }

            var sessionOptions = new CimSessionOptions();

            CimCredential cimCredentials = GetCimCredentials(authentication, credential);

            if (cimCredentials != null)
            {
                sessionOptions.AddDestinationCredentials(cimCredentials);
            }

            CimSession cimSession = CimSession.Create(computerName, sessionOptions);

            return(cimSession);
        }
예제 #2
0
        internal static CimSession CreateCimSession(string computerName, PSCredential credential, string authentication, CancellationToken cancellationToken, PSCmdlet cmdlet)
        {
            CimSessionOptions sessionOptions = new CimSessionOptions();
            CimCredential     cimCredentials = GetCimCredentials(authentication, credential);

            if (cimCredentials != null)
            {
                sessionOptions.AddDestinationCredentials(cimCredentials);
            }
            return(CimSession.Create(computerName, sessionOptions));
        }
예제 #3
0
        private void KickOffCimAsync(Computer computer, Credential credential, string commandline, CimSessionOptions options)
        {
            var optionsBuilder = new DbContextOptionsBuilder <ACEWebServiceDbContext>();

            optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ACEWebService;Trusted_Connection=True;MultipleActiveResultSets=true");
            using (ACEWebServiceDbContext context = new ACEWebServiceDbContext(optionsBuilder.Options))
            {
                // Convert stored password to a secure string
                SecureString securePwd = new SecureString();
                foreach (char c in _cryptoService.Decrypt(credential.Password))
                {
                    securePwd.AppendChar(c);
                }

                CimCredential cimCreds = null;

                if (credential.UserName.Contains('\\'))
                {
                    // Create a CimCredential object
                    cimCreds = new CimCredential(PasswordAuthenticationMechanism.Kerberos, credential.UserName.Split('\\')[0], credential.UserName.Split('\\')[1], securePwd);
                }
                else
                {
                    // Create a CimCredential object
                    cimCreds = new CimCredential(PasswordAuthenticationMechanism.Default, null, credential.UserName, securePwd);
                }

                // Create a CimSession with the remote system
                options.AddDestinationCredentials(cimCreds);
                CimSession session = CimSession.Create(computer.ComputerName, options);

                // Create a CimMethodParametersCollection to pass to method invocation
                CimMethodParametersCollection collection = new CimMethodParametersCollection();
                collection.Add(CimMethodParameter.Create("CommandLine", commandline, CimFlags.None));

                CimMethodResult result = session.InvokeMethod("root/cimv2", "Win32_Process", "Create", collection);
                if (result.ReturnValue.ToString() == "0")
                {
                }
                else
                {
                }

                session.Dispose();
            }
        }
예제 #4
0
        private void KickOffCim(Computer computer, Credential credential, string commandline, CimSessionOptions options)
        {
            // Convert stored password to a secure string
            SecureString securePwd = new SecureString();

            foreach (char c in _cryptoService.Decrypt(credential.Password))
            {
                Console.WriteLine("[char]: {0}", c);
                securePwd.AppendChar(c);
            }

            CimCredential cimCreds = null;

            if (credential.UserName.Contains('\\'))
            {
                // Create a CimCredential object
                cimCreds = new CimCredential(PasswordAuthenticationMechanism.Kerberos, credential.UserName.Split('\\')[0], credential.UserName.Split('\\')[1], securePwd);
            }
            else
            {
                // Create a CimCredential object
                cimCreds = new CimCredential(PasswordAuthenticationMechanism.Default, null, credential.UserName, securePwd);
            }

            // Create a CimSession with the remote system
            options.AddDestinationCredentials(cimCreds);
            CimSession session = CimSession.Create(computer.ComputerName, options);

            // Create a CimMethodParametersCollection to pass to method invocation
            CimMethodParametersCollection collection = new CimMethodParametersCollection
            {
                CimMethodParameter.Create("CommandLine", commandline, CimFlags.None)
            };

            CimMethodResult result = session.InvokeMethod("root/cimv2", "Win32_Process", "Create", collection);

            if (result.ReturnValue.ToString() == "0")
            {
            }
            else
            {
            }

            session.Dispose();
        }
예제 #5
0
        /// <summary>
        /// Creates a new collection of <see cref="ComponentDescriptor"/> that describes the specified
        /// components installed in system associated with a network host-name.
        /// </summary>
        /// <param name="hostName">
        ///     The network host-name that should be described.
        /// </param>
        /// <returns>
        ///     The resulting collection of <see cref="ComponentDescriptor"/> if successful.
        /// </returns>
        public static IEnumerable <ComponentDescriptor> Create(string hostName)
        {
            // Validate parameters.
            if (String.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentNullException("hostName");
            }

            CimSessionOptions sessionOptions = new CimSessionOptions()
            {
            };

            sessionOptions.AddDestinationCredentials(new CimCredential(ImpersonatedAuthenticationMechanism.Negotiate));
            CimSession session = CimSession.Create(hostName, sessionOptions);

            return
                (ComponentDescriptor.GetProcessors(session)
                 .Concat(ComponentDescriptor.GetMemory(session))
                 .Concat(ComponentDescriptor.GetHardDrives(session))
                 .ToList());
        }
예제 #6
0
        /// <summary>
        /// Creates a new <see cref="AssetDescriptor"/> that describes the specified
        /// network host-name.
        /// </summary>
        /// <param name="hostName">
        ///     The network host-name that should be described.
        /// </param>
        /// <returns>
        ///     The resulting <see cref="AssetDescriptor"/> if successful.
        /// </returns>
        public static AssetDescriptor Create(string hostName)
        {
            CimSessionOptions sessionOptions = new CimSessionOptions()
            {
            };

            sessionOptions.AddDestinationCredentials(new CimCredential(ImpersonatedAuthenticationMechanism.Negotiate));
            CimSession session = CimSession.Create(hostName, sessionOptions);

            CimInstance computerDetails = session.EnumerateInstances(@"root\cimv2", "Win32_ComputerSystem").FirstOrDefault();
            CimInstance productDetails  = session.EnumerateInstances(@"root\cimv2", "Win32_ComputerSystemProduct").FirstOrDefault();

            return(new AssetDescriptor()
            {
                Serial = Convert.ToString(productDetails.CimInstanceProperties["IdentifyingNumber"].Value, CultureInfo.InvariantCulture),
                Name = Convert.ToString(computerDetails.CimInstanceProperties["Name"].Value, CultureInfo.InvariantCulture),
                Manufacturer = Convert.ToString(computerDetails.CimInstanceProperties["Manufacturer"].Value, CultureInfo.InvariantCulture),
                Model = String.Join(" ", computerDetails.CimInstanceProperties["Manufacturer"].Value, computerDetails.CimInstanceProperties["Model"].Value),
                ModelNumber = Convert.ToString(computerDetails.CimInstanceProperties["Model"].Value, CultureInfo.InvariantCulture),
                Category = pcSystemTypeExMap[Convert.ToInt32(computerDetails.CimInstanceProperties["PCSystemTypeEx"].Value, CultureInfo.InvariantCulture)]
            });
        }