Ejemplo n.º 1
2
        //private char NULL_VALUE = char(0);
        public static ProcessReturnCode Run(string machineName, string commandLine, string args, string currentDirectory)
        {
            var connOptions = new ConnectionOptions
                                  {
                                      EnablePrivileges = true
                                  };

            var scope = new ManagementScope(@"\\{0}\root\cimv2".FormatWith(machineName), connOptions);
            scope.Connect();
            var managementPath = new ManagementPath(CLASSNAME);
            using (var processClass = new ManagementClass(scope, managementPath, new ObjectGetOptions()))
            {
                var inParams = processClass.GetMethodParameters("Create");
                commandLine = System.IO.Path.Combine(currentDirectory, commandLine);
                inParams["CommandLine"] = "{0} {1}".FormatWith(commandLine, args);

                var outParams = processClass.InvokeMethod("Create", inParams, null);

                var rtn = Convert.ToUInt32(outParams["returnValue"]);
                var pid = Convert.ToUInt32(outParams["processId"]);
                if (pid != 0)
                {
                    WaitForPidToDie(machineName, pid);
                }

                return (ProcessReturnCode)rtn;
            }
        }
Ejemplo n.º 2
1
 public string FindMACAddress()
 {
     //create out management class object using the
     //Win32_NetworkAdapterConfiguration class to get the attributes
     //of the network adapter
     ManagementClass mgmt = new ManagementClass("Win32_NetworkAdapterConfiguration");
     //create our ManagementObjectCollection to get the attributes with
     ManagementObjectCollection objCol = mgmt.GetInstances();
     string address = String.Empty;
     //loop through all the objects we find
     foreach (ManagementObject obj in objCol)
     {
         if (address == String.Empty)  // only return MAC Address from first card
         {
             //grab the value from the first network adapter we find
             //you can change the string to an array and get all
             //network adapters found as well
             //check to see if the adapter's IPEnabled
             //equals true
             if ((bool)obj["IPEnabled"] == true)
             {
                 address = obj["MacAddress"].ToString();
             }
         }
         //dispose of our object
         obj.Dispose();
     }
     //replace the ":" with an empty space, this could also
     //be removed if you wish
     address = address.Replace(":", "");
     //return the mac address
     return address;
 }
Ejemplo n.º 3
1
        public ViewModel()
        {
            mgt = new ManagementClass("Win32_Processor");
            procs = mgt.GetInstances();

            CPU = new ObservableCollection<Model>();
            timer = new DispatcherTimer();
            random = new Random();
            time = DateTime.Now;
            cpuCounter = new PerformanceCounter();
            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";
            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            ProcessorID = GetProcessorID();
            processes = Process.GetProcesses();
            Processes = processes.Length;
            MaximumSpeed = GetMaxClockSpeed();
            LogicalProcessors = GetNumberOfLogicalProcessors();
            Cores = GetNumberOfCores();
            L2Cache = GetL2CacheSize();
            L3Cache = GetL3CacheSize();
            foreach (ManagementObject item in procs)
                L1Cache = ((UInt32)item.Properties["L2CacheSize"].Value / 2).ToString() + " KB";

            timer.Interval = TimeSpan.FromMilliseconds(1000);
            timer.Tick += timer_Tick;
            timer.Start();
            for (int i = 0; i < 60; i++)
            {
                CPU.Add(new Model(time, 0,0));
                time = time.AddSeconds(1);
            }
        }
Ejemplo n.º 4
0
 public static string GetMACAddress()
 {
     ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
     ManagementObjectCollection moc = mc.GetInstances();
     string MACAddress = string.Empty;
     try
     {
         ManagementObjectCollection.ManagementObjectEnumerator enumerator = moc.GetEnumerator();
         while (enumerator.MoveNext())
         {
             ManagementObject mo = (ManagementObject)enumerator.Current;
             if (Operators.CompareString(MACAddress, string.Empty, false) == 0 && Conversions.ToBoolean(mo["IPEnabled"]))
             {
                 MACAddress = mo["MacAddress"].ToString();
             }
             mo.Dispose();
         }
     }
     finally
     {
         ManagementObjectCollection.ManagementObjectEnumerator enumerator;
         if (enumerator != null)
         {
             ((IDisposable)enumerator).Dispose();
         }
     }
     MACAddress = MACAddress.Replace(":", "");
     return MACAddress;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a share for a given local path, and sets read/write access rights to everybody
        /// </summary>
        /// <param name="sharePath">local path of directory to be shared</param>
        /// <param name="shareName">Share Name</param>
        public static bool CreateShare(string sharePath, string shareName)
        {
            ManagementObject trustee = new ManagementClass("Win32_Trustee").CreateInstance();
            trustee["Domain"] = null;
            trustee["Name"] = "Everyone";
            trustee["SID"] = new Object[] { 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; // everybody

            ManagementObject ace = new ManagementClass("Win32_Ace").CreateInstance();
            ace["AccessMask"] = 2032127; // full access
            ace["AceFlags"] = 0x1 | 0x2; //OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE
            ace["AceType"] = 0; //Access Allowed
            ace["Trustee"] = trustee;

            ManagementObject dacl = new ManagementClass("Win32_SecurityDescriptor").CreateInstance();
            dacl["DACL"] = new Object[] { ace };

            ManagementClass share = new ManagementClass("Win32_Share");
            ManagementBaseObject inParams = share.GetMethodParameters("Create");
            ManagementBaseObject outParams;
            inParams["Description"] = "Create Share Folder";
            inParams["Name"] = shareName;
            inParams["Path"] = sharePath;
            inParams["Type"] = 0x0; // Disk Drive
            inParams["Access"] = dacl;
            outParams = share.InvokeMethod("Create", inParams, null);

            // Check to see if the method invocation was successful
            if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
            {
                //throw new Exception("Unable to share directory.");
                return false;
            }
            return true;
        }
Ejemplo n.º 6
0
        public static string GetIdentifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
        {
            if (_log.IsTraceEnabled)
            {
                _log.Trace(m => m(string.Format("wmiClass:{0}, wmiProperty:{1}, wmiMustBeTrue:{2}", wmiClass, wmiProperty, wmiMustBeTrue)));
            }

            string result = "";
            var managementClass = new ManagementClass(wmiClass);
            var moc = managementClass.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if (mo[wmiMustBeTrue].ToString() == "True")
                {
                    //Only get the first one
                    if (result == "")
                    {
                        try
                        {
                            result = mo[wmiProperty].ToString();
                            break;
                        }
                        catch(Exception ex)
                        {
                            _log.Warn(ex);
                        }
                    }
                }
            }
            return result;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a Send Handler.
        /// </summary>
        /// <param name="adapterName">The Adapter name.</param>
        /// <param name="hostName">The Host name.</param>
        /// <param name="isDefault">Indicating if the Handler is the default.</param>
        public static void Create(string adapterName, string hostName, bool isDefault)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            using (ManagementClass handlerManagementClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_SendHandler2", null))
            {
                foreach (ManagementObject handler in handlerManagementClass.GetInstances())
                {
                    if ((string)handler["AdapterName"] == adapterName && (string)handler["HostName"] == hostName)
                    {
                        handler.Delete();
                    }
                }

                ManagementObject handlerInstance = handlerManagementClass.CreateInstance();
                if (handlerInstance == null)
                {
                    throw new CoreException("Could not create Management Object.");
                }

                handlerInstance["AdapterName"] = adapterName;
                handlerInstance["HostName"] = hostName;
                handlerInstance["IsDefault"] = isDefault;
                handlerInstance.Put(options);
            }
        }
Ejemplo n.º 8
0
        private void LoadDeviceList()
        {
            devices.Clear();
            devices.Add(new SoundDevice("Default", "0000", "0000"));

            ManagementPath path = new ManagementPath();
            ManagementClass devs = null;
            path.Server = ".";
            path.NamespacePath = @"root\CIMV2";
            path.RelativePath = @"Win32_SoundDevice";
            using (devs = new ManagementClass(new ManagementScope(path), path, new ObjectGetOptions(null, new TimeSpan(0, 0, 0, 2), true)))
            {
                ManagementObjectCollection moc = devs.GetInstances();

                foreach (ManagementObject mo in moc)
                {
                    PropertyDataCollection devsProperties = mo.Properties;
                    string devid = devsProperties["DeviceID"].Value.ToString();
                    if (devid.Contains("PID_"))
                    {
                        string vid = devid.Substring(devid.IndexOf("VID_") + 4, 4);
                        string pid = devid.Substring(devid.IndexOf("PID_") + 4, 4);

                        devices.Add(new SoundDevice(devsProperties["Caption"].Value.ToString(), vid, pid));

                    }
                }
            }
        }
Ejemplo n.º 9
0
 //获取硬盘卷标号
 public static string GetDiskVolumeSerialNumber()
 {
     ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
     ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
     disk.Get();
     return disk.GetPropertyValue("VolumeSerialNumber").ToString();
 }
Ejemplo n.º 10
0
        public static string[] getComPorts()
        {
            var list = new ArrayList();

            ManagementClass win32_pnpentity = new ManagementClass("Win32_PnPEntity");
            ManagementObjectCollection col = win32_pnpentity.GetInstances();

            Regex reg = new Regex(".+\\((?<port>COM\\d+)\\)");

            foreach (ManagementObject obj in col)
            {
                // name : "USB Serial Port(COM??)"
                string name = (string)obj.GetPropertyValue("name");
                if (name != null && name.Contains("(COM"))
                {
                    // "USB Serial Port(COM??)" -> COM??
                    Match m = reg.Match(name);
                    string port = m.Groups["port"].Value;

                    // description : "USB Serial Port"
                    string desc = (string)obj.GetPropertyValue("Description");

                    // result string : "COM?? (USB Serial Port)"
                    list.Add(port + " (" + desc + ")");
                }
            }

            ComPortComparer comp = new ComPortComparer();
            list.Sort(comp);

            return (string[])list.ToArray(typeof(string));
        }
 /// <summary>
 /// Retorna una lista de adaptadores de red disponibles en la máquina
 /// Si ocurre un error se arroja una Excepción
 /// </summary>
 /// <returns></returns>
 public static List<NetworkAdapter> getNetworkAdapters()
 {
     try
     {
         List<NetworkAdapter> adapters = new List<NetworkAdapter>();
         ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection objMOC = objMC.GetInstances();
         foreach (ManagementObject objMO in objMOC)
         {
             if(true)
             {
                 NetworkAdapter adapter = new NetworkAdapter();
                 adapter.Id = (String)objMO["SettingID"];
                 adapter.Description = (String)objMO["Description"];
                 adapter.Index = (UInt32)objMO["Index"];
                 adapters.Add(adapter);
             }
         }
         return adapters;
     }
     catch (ThreadAbortException e)
     {
         throw e;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 12
0
 public string DeviceInformation(string stringIn)
 {
     StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
     ManagementClass ManagementClass1 = new ManagementClass(stringIn);
     //Create a ManagementObjectCollection to loop through
     ManagementObjectCollection ManagemenobjCol = ManagementClass1.GetInstances();
     //Get the properties in the class
     PropertyDataCollection properties = ManagementClass1.Properties;
     foreach (ManagementObject obj in ManagemenobjCol)
     {
         foreach (PropertyData property in properties)
         {
             try
             {
                 // resit pres pole kde budou nazvy parametru co me zajimaji
                 if(property.Name.Equals("Name"))
                 StringBuilder1.AppendLine(property.Name + ":  " +
                   obj.Properties[property.Name].Value.ToString());
             }
             catch
             {
                 //Add codes to manage more informations
             }
         }
         StringBuilder1.AppendLine();
     }
     return StringBuilder1.ToString();
 }
Ejemplo n.º 13
0
Archivo: Util.cs Proyecto: mfz888/xcore
 /// <summary>
 /// 获取机器码(根据XCore定制的规则)
 /// </summary>
 /// <returns>当前主机的机器码</returns>
 public static String GetComputerId()
 {
     String DiskDriveid = String.Empty;
     String CPUid = String.Empty;
     ManagementClass mcdisk = new ManagementClass(strUtil.GetStringByUnicode(@"\u0057\u0069\u006e\u0033\u0032\u005f\u0044\u0069\u0073\u006b\u0044\u0072\u0069\u0076\u0065"));
     foreach (ManagementObject mo in mcdisk.GetInstances())
     {
         DiskDriveid = (string)mo.Properties["Model"].Value;
         break;
     }
     ManagementClass mccpu = new ManagementClass(strUtil.GetStringByUnicode(@"\u0057\u0069\u006e\u0033\u0032\u005f\u0050\u0072\u006f\u0063\u0065\u0073\u0073\u006f\u0072"));
     foreach (ManagementObject mo in mccpu.GetInstances())
     {
         CPUid = (string)mo.Properties["ProcessorId"].Value;
         break;
     }
     Int64 diskid = DiskDriveid.GetHashCode();
     Int64 cpuid = CPUid.GetHashCode();
     Int64 computerid = ((diskid > 0 ? diskid : -diskid) % 10000000) * ((cpuid > 0 ? cpuid : -cpuid) % 10000000);
     if (computerid > 100000000000)
         computerid = computerid % 1000000000000;
     else if (computerid < 100000000000)
         computerid += 100000000000;
     return computerid.ToString();
 }
Ejemplo n.º 14
0
        public bool CheckDeviceMacadress(string strMacadress)
        {
           
            MacAdress = strMacadress;
           
            ManagementPath cmPath = new ManagementPath("root\\sms\\site_PS1:SMS_R_SYSTEM"); 
            ManagementClass cmClass = new ManagementClass(cmPath);
            ManagementObjectCollection cmCollection = cmClass.GetInstances();

            DeviceFound = false;

            foreach (ManagementObject deviceInfo in cmCollection)
            {
                string[] listCmDeviceMacAdresses = (string[])deviceInfo["MACAddresses"];
                foreach (string MacAdressExist in listCmDeviceMacAdresses)
                {
                    if (MacAdressExist == MacAdress)
                    {
                        DeviceFound = true;
                    }
                    
                }
         
            }

            return DeviceFound;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 获取 CPU 属性参数
        /// </summary>
        /// <returns>返回 CPU 属性参数</returns>
        public static string GetCPUProperties()
        {
            // Get the WMI class
            ManagementClass c = new ManagementClass(new ManagementPath("Win32_Processor"));
            // Get the properties in the class
            ManagementObjectCollection moc = c.GetInstances();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            // display the properties
            sb.AppendLine("Property Names: ");
            sb.AppendLine("=================");
            foreach (ManagementObject mo in moc)
            {
                PropertyDataCollection properties = mo.Properties;
                //获取内核数代码
                sb.AppendLine("物理内核数:" + properties["NumberOfCores"].Value);
                sb.AppendLine("逻辑内核数:" + properties["NumberOfLogicalProcessors"].Value);
                //其他属性获取代码
                foreach (PropertyData property in properties)
                {
                    sb.AppendLine(property.Name + ":" + property.Value);
                }
            }
            string s = sb.ToString();
            return s;
        }
Ejemplo n.º 16
0
        // Windowsの製品名を取得
        public static string GetOsVersion()
        {
            string OsVersion = null;

            ManagementClass objCS = new ManagementClass("Win32_OperatingSystem");
            ManagementObjectCollection objCol = objCS.GetInstances();

            foreach(ManagementObject objMgmt in objCol)
            {
                OsVersion = objMgmt["Caption"].ToString();
                objMgmt.Dispose();
            }

            objCol.Dispose();
            objCS.Dispose();

            if (System.Environment.Is64BitOperatingSystem)
            {
                return OsVersion + "(64bit)";
            }
            else
            {
                return OsVersion + "(32bit)";
            }
        }
Ejemplo n.º 17
0
 //Return a hardware identifier
 private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue)
 {
     string result = "";
     System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass);
     System.Management.ManagementObjectCollection moc = mc.GetInstances();
     foreach (System.Management.ManagementObject mo in moc)
     {
         if (mo[wmiMustBeTrue].ToString() == "True")
         {
             //Only get the first one
             if (result == "")
             {
                 try
                 {
                     result = mo[wmiProperty].ToString();
                     break;
                 }
                 catch
                 {
                 }
             }
         }
     }
     return result;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Create a Receive Handler.
        /// </summary>
        /// <param name="adapterName">The Adapter name.</param>
        /// <param name="hostName">The Host name.</param>
        public static void Create(string adapterName, string hostName)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            using (ManagementClass handlerManagementClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ReceiveHandler", null))
            {
                foreach (ManagementObject handler in handlerManagementClass.GetInstances())
                {
                    if ((string)handler["AdapterName"] == adapterName && (string)handler["HostName"] == hostName)
                    {
                        handler.Delete();
                    }
                }

                ManagementObject recieveHandlerManager = handlerManagementClass.CreateInstance();
                if (recieveHandlerManager == null)
                {
                    throw new BizTalkExtensionsException("Could not create Management Object.");
                }

                recieveHandlerManager["AdapterName"] = adapterName;
                recieveHandlerManager["HostName"] = hostName;
                recieveHandlerManager.Put(options);
            }
        }
Ejemplo n.º 19
0
 public List<String> GetMacAddress()
 {
     List<String> macs = new List<string>();
     try
     {
         string mac = "";
         ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection moc = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             if ((bool)mo["IPEnabled"])
             {
                 mac = mo["MacAddress"].ToString();
                 macs.Add(mac);
             }
         }
         moc = null;
         mc = null;
     }
     catch(Exception ex)
     {
         //_log.Error("MacAddress get error",ex);
     }
     return macs;
 }
Ejemplo n.º 20
0
        public DeviceDTOResponse GetDeviceInfo()
        {
            DeviceDTOResponse device = new DeviceDTOResponse();

            try
            {
                ManagementClass mc = new ManagementClass("Win32_ComputerSystemProduct");

                foreach (ManagementObject obj in mc.GetInstances())
                {
                    device.Label = GetValueAsString(obj, "Name");
                    device.Sn = GetValueAsString(obj, "IdentifyingNumber");
                    device.Caption = GetValueAsString(obj, "Caption");
                    device.Vendor = GetValueAsString(obj, "Vendor");
                    device.Version = GetValueAsString(obj, "Version");

                    break;
                }
            }
            catch (ManagementException e)
            {
                Logger.Instance.LogError(e.ToString());
            }

            return device;
        }
Ejemplo n.º 21
0
        private static void SendInstallData(string error)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var data = new NameValueCollection();
                    data.Add("error", error);
                    data.Add("computername", SystemInformation.ComputerName);

                    using (var mgmt = new ManagementClass("Win32_OperatingSystem"))
                    {
                        try
                        {
                            foreach (ManagementObject mgmtObj in mgmt.GetInstances())
                            {
                                // Just get first value.
                                data.Add("os", mgmtObj["Caption"].ToString().Trim());
                                break;
                            }
                        }
                        catch { }
                        var result = System.Text.Encoding.Default.GetString(client.UploadValues("http://www.filmkhoj.com/api/install", data));
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 获取CPU编号
        /// </summary>
        /// <returns></returns>
        public static string GetCpuID()
        {
            try
            {
                //获取CPU序列号代码
                string cpuInfo = "";//cpu序列号
                ManagementClass mc = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                }
                moc = null;
                mc = null;
                return cpuInfo;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }

        }
Ejemplo n.º 23
0
 /// <summary>
 ///����ȡIP��ַ
 /// </summary>
 /// <returns></returns>
 public static string GetIPAddress()
 {
     try
     {
         string st = string.Empty;
         ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection moc = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             if ((bool)mo["IPEnabled"] == true)
             {
                 System.Array ar = null;
                 ar = (System.Array)(mo.Properties["IpAddress"].Value);
                 st = ar.GetValue(0).ToString();
                 break;
             }
         }
         moc = null;
         mc = null;
         return st;
     }
     catch
     {
         return "0";
     }
     finally
     {
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// 获取网卡地址
 /// </summary>
 /// <returns></returns>
 public static string GetMacAddress()
 {
     try
     {
         //获取网卡硬件地址
         string mac = "";
         ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
         ManagementObjectCollection moc = mc.GetInstances();
         foreach (ManagementObject mo in moc)
         {
             if ((bool)mo["IPEnabled"] == true)
             {
                 mac = mo["MacAddress"].ToString();
                 break;
             }
         }
         moc = null;
         mc = null;
         return mac;
     }
     catch
     {
         return "unknow";
     }
     finally
     {
     }
 }
Ejemplo n.º 25
0
        public static void Shutdown(string mode)
        {
            if (mode == "WMI")
            {
                ManagementBaseObject mboShutdown = null;
                ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
                mcWin32.Get();

                // Get Security Privilages
                mcWin32.Scope.Options.EnablePrivileges = true;
                ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");

                //Option Flags
                mboShutdownParams["Flags"] = "1";
                mboShutdownParams["Reserved"] = "0";
                foreach (ManagementObject manObj in mcWin32.GetInstances())
                {
                    mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
                }
            }
            else if (mode == "Core")
            {
                Process.Start("shutdown", "/s /t 0");
            }
        }
Ejemplo n.º 26
0
        public void AddARecord(string hostName, string zone, string iPAddress, string dnsServerName)
        {
            /*ConnectionOptions connOptions = new ConnectionOptions();
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            connOptions.Username = "******";
            connOptions.Password = "******";
            */
            ManagementScope scope =
               new ManagementScope(@"\\" + dnsServerName + "\\root\\MicrosoftDNS"); //,connOptions);

            scope.Connect();

            ManagementClass wmiClass =
               new ManagementClass(scope,
                                   new ManagementPath("MicrosoftDNS_AType"),
                                   null);

            ManagementBaseObject inParams =
                wmiClass.GetMethodParameters("CreateInstanceFromPropertyData");

            inParams["DnsServerName"] = dnsServerName;
            inParams["ContainerName"] = zone;
            inParams["OwnerName"] = hostName + "." + zone;
            inParams["IPAddress"] = iPAddress;

            wmiClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null);
        }
Ejemplo n.º 27
0
        public static string InstallHosts(string ServerName, string HostName, string UserName, string Password, bool StartHost)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;
            ObjectGetOptions bts_objOptions = new ObjectGetOptions();

            // Creating instance of BizTalk Host.
            ManagementClass bts_AdminObjClassServerHost = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ServerHost", bts_objOptions);
            ManagementObject bts_AdminObjectServerHost = bts_AdminObjClassServerHost.CreateInstance();

            // Make sure to put correct Server Name,username and // password
            bts_AdminObjectServerHost["ServerName"] = ServerName;
            bts_AdminObjectServerHost["HostName"] = HostName;
            bts_AdminObjectServerHost.InvokeMethod("Map", null);

            ManagementClass bts_AdminObjClassHostInstance = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostInstance", bts_objOptions);
            ManagementObject bts_AdminObjectHostInstance = bts_AdminObjClassHostInstance.CreateInstance();

            bts_AdminObjectHostInstance["Name"] = "Microsoft BizTalk Server " + HostName + " " + ServerName;

            //Also provide correct user name and password.
            ManagementBaseObject inParams = bts_AdminObjectHostInstance.GetMethodParameters("Install");
            inParams["GrantLogOnAsService"] = false;
            inParams["Logon"] = UserName;
            inParams["Password"] = Password;

            bts_AdminObjectHostInstance.InvokeMethod("Install", inParams, null);
            
            if(StartHost)
                bts_AdminObjectHostInstance.InvokeMethod("Start", null);

            return "  Host - " + HostName + " - has been installed. \r\n";
        }
Ejemplo n.º 28
0
        public static string MakeHost(string HostName, string Type, string HostNTGroup, bool AuthTrusted)
        {
            PutOptions options = new PutOptions();
            options.Type = PutType.CreateOnly;

            // create a ManagementClass object and spawn a ManagementObject instance
            ManagementClass objHostSettingClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostSetting", null);
            ManagementObject objHostSetting = objHostSettingClass.CreateInstance();

            // set the properties for the Managementobject
            // Host Name
            objHostSetting["Name"] = HostName;
            
            // Host Type
            if(Type == "Isolated")
                objHostSetting["HostType"] = HostType.Isolated;
            else
                objHostSetting["HostType"] = HostType.InProcess;

            objHostSetting["NTGroupName"] = HostNTGroup;

            objHostSetting["AuthTrusted"] = AuthTrusted;

            //create the Managementobject
            objHostSetting.Put(options);

            return Type + " Host - " + HostName + " - has been created. \r\n";
        }
Ejemplo n.º 29
0
        private static string GetUncPath(string path)
        {
            string uncPath = string.Empty;
            using (ManagementClass managementClass = new ManagementClass("Win32_Share"))
            {
                foreach (ManagementObject item in managementClass.GetInstances())
                {
                    if (item.Properties["Path"].Value.ToString().Trim() == "" | item.Properties["Name"].Value.ToString().EndsWith("$") == true)
                        continue;
                    if (path.StartsWith(item.Properties["Path"].Value.ToString(), StringComparison.CurrentCultureIgnoreCase) == true)
                    {
                        uncPath = @"\\" + Environment.MachineName + @"\";
                        uncPath += item.Properties["Name"].Value;
                        uncPath += path.Substring(item.Properties["Path"].Value.ToString().Length);
                        break;
                    }

                }
            }
            if (string.IsNullOrEmpty(uncPath))
            {
                throw new IOException("No unc path found for path");
            }
            return uncPath;
        }
Ejemplo n.º 30
-1
 public IisAppPool CreateAppPool(string name)
 {
     ManagementObject appPool = new ManagementClass(scope, new ManagementPath("IIsApplicationPoolSetting"), null).CreateInstance();
     appPool["Name"] = String.Format("W3SVC/AppPools/{0}", name);
     appPool.Put();
     return new IisAppPool(scope, name);
 }
Ejemplo n.º 31
-1
        void Test()
        {
            Log("win32_processor");
            try
            {
                System.Management.ManagementClass mc = new ManagementClass("win32_processor");
                Log("new ManagementClass");
                ManagementObjectCollection moc = mc.GetInstances();
                Log("mc.GetInstances");

                foreach (ManagementObject mo in moc)
                {
                    Log(mo["processorid"].ToString());
                }
            }
            catch (Exception ex)
            {
                Log($"ex: {ex.Message}");
            }

            Log("SerialNumber");
            System.Management.ManagementClass mcBoard = new System.Management.ManagementClass("Win32_BaseBoard");
            Log("new ManagementClass");

            ManagementObjectCollection mocBoard = mcBoard.GetInstances();

            Log("mc.GetInstances");

            foreach (ManagementObject mx in mocBoard)
            {
                Log(mx.Properties["SerialNumber"].Value.ToString());
            }

            Log("Win32_DiskDrive");
            try
            {
                System.Management.ManagementClass mcDisk = new System.Management.ManagementClass("Win32_DiskDrive");
                Log("new ManagementClass");

                ManagementObjectCollection mocDisk = mcDisk.GetInstances();
                Log("mc.GetInstances");

                foreach (ManagementObject mo in mocDisk)
                {
                    Log(mo.Properties["Model"].Value.ToString());
                }
            }
            catch (Exception ex)
            {
                Log($"ex: {ex.Message}");
            }
            Log("Win32_NetworkAdapterConfiguration");

            try
            {
                System.Management.ManagementClass mcNetwork = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
                Log("new ManagementClass");

                ManagementObjectCollection mocNetwork = mcNetwork.GetInstances();
                Log("mc.GetInstances");

                foreach (ManagementObject mo in mocNetwork)
                {
                    if ((bool)mo["IPEnabled"] == true)
                    {
                        Log(mo["MacAddress"].ToString());
                    }

                    mo.Dispose();
                }
            }
            catch (Exception ex)
            {
                Log($"ex: {ex.Message}");
            }

            Log("Win32_OperatingSystem");
            try
            {
                System.Management.ManagementClass mcMemory = new System.Management.ManagementClass("Win32_OperatingSystem");
                Log("new ManagementClass");

                ManagementObjectCollection mocMemory = mcMemory.GetInstances();
                Log("mc.GetInstances");

                foreach (ManagementObject mo in mocMemory)
                {
                    if (mo.Properties["TotalVisibleMemorySize"].Value != null)
                    {
                        Log(mo.Properties["TotalVisibleMemorySize"].Value.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Log($"ex: {ex.Message}");
            }
        }