public void AddVirtualDirectory() { var siteId = 1574596940; // var siteId = 1; var dir = "iplayer"; var name = String.Format(@"W3SVC/{0}/root/{1}", siteId, dir); var vDir = new ManagementClass(Scope, new ManagementPath("IIsWebVirtualDirSetting"), null).CreateInstance(); vDir["Name"] = name; vDir["Path"] = @"C:\sites\iplayer"; vDir.Put(); var path = string.Format("IIsWebVirtualDir.Name='{0}'", name); var app = new ManagementObject(Scope, new ManagementPath(path), null); app.InvokeMethod("AppCreate2", new object[] { 2 }); vDir["AppPoolId"] = "GipRegForm.Api"; vDir["AppFriendlyName"] = "stuff"; vDir.Put(); }
private void addIPPort() { var conn = new ConnectionOptions { EnablePrivileges = true, Impersonation = ImpersonationLevel.Impersonate }; var mPath = new ManagementPath("Win32_TCPIPPrinterPort"); var mScope = new ManagementScope(@"\\.\root\cimv2", conn) { Options = { EnablePrivileges = true, Impersonation = ImpersonationLevel.Impersonate } }; var mPort = new ManagementClass(mScope, mPath, null).CreateInstance(); var remotePort = 9100; try { if (IP != null && IP.Contains(":")) { var arIP = IP.Split(':'); if (arIP.Length == 2) remotePort = int.Parse(arIP[1]); } } catch (Exception ex) { Log.Error(LogName, "Could not parse port from IP"); Log.Error(LogName, ex); } mPort.SetPropertyValue("Name", Port); mPort.SetPropertyValue("Protocol", 1); mPort.SetPropertyValue("HostAddress", IP); mPort.SetPropertyValue("PortNumber", remotePort); mPort.SetPropertyValue("SNMPEnabled", false); var put = new PutOptions { UseAmendedQualifiers = true, Type = PutType.UpdateOrCreate }; mPort.Put(put); }
public IisVirtualDirectorySettings CreateVirtualDirectory(string subPath, string directory) { var path = String.Format(@"{0}/root/{1}", Name, subPath); var vDir = new ManagementClass(scope, new ManagementPath("IIsWebVirtualDirSetting"), null).CreateInstance(); vDir["Name"] = path; vDir["Path"] = directory; vDir.Put(); var virtualDirPath = string.Format("IIsWebVirtualDir.Name='{0}'", path); var app = new ManagementObject(scope, new ManagementPath(virtualDirPath), null); app.InvokeMethod("AppCreate2", new object[] { 2 }); return new IisVirtualDirectorySettings(scope, path); }
private static void ReplaceClassIfNecessary(string classPath, ManagementClass newClass) { try { ManagementClass managementClass = SchemaNaming.SafeGetClass(classPath); if (managementClass != null) { if (newClass.GetText(TextFormat.Mof) != managementClass.GetText(TextFormat.Mof)) { managementClass.Delete(); newClass.Put(); } } else { newClass.Put(); } } catch (ManagementException managementException1) { ManagementException managementException = managementException1; string str = string.Concat(RC.GetString("CLASS_NOTREPLACED_EXCEPT"), "\r\n{0}\r\n{1}"); throw new ArgumentException(string.Format(str, classPath, newClass.GetText(TextFormat.Mof)), managementException); } }
private static void ReplaceClassIfNecessary(string classPath, ManagementClass newClass) { try { ManagementClass class2 = SafeGetClass(classPath); if (class2 == null) { newClass.Put(); } else if (newClass.GetText(TextFormat.Mof) != class2.GetText(TextFormat.Mof)) { class2.Delete(); newClass.Put(); } } catch (ManagementException exception) { throw new ArgumentException(string.Format(RC.GetString("CLASS_NOTREPLACED_EXCEPT") + "\r\n{0}\r\n{1}", classPath, newClass.GetText(TextFormat.Mof)), exception); } }
public override void Add() { Log.Entry(LogName, "Attempting to add printer:"); Log.Entry(LogName, string.Format("--> Name = {0}", Name)); Log.Entry(LogName, string.Format("--> IP = {0}", IP)); Log.Entry(LogName, string.Format("--> Port = {0}", Port)); if (string.IsNullOrEmpty(IP) || !Name.StartsWith("\\\\")) return; if (IP.Contains(":")) { var arIP = IP.Split(':'); if (arIP.Length == 2) { IP = arIP[0]; Port = arIP[1]; } } var conn = new ConnectionOptions { EnablePrivileges = true, Impersonation = ImpersonationLevel.Impersonate }; var mPath = new ManagementPath("Win32_TCPIPPrinterPort"); var mScope = new ManagementScope(@"\\.\root\cimv2", conn) { Options = { EnablePrivileges = true, Impersonation = ImpersonationLevel.Impersonate } }; var mPort = new ManagementClass(mScope, mPath, null).CreateInstance(); if (mPort != null) { mPort.SetPropertyValue("Name", "IP_" + IP); mPort.SetPropertyValue("Protocol", 1); mPort.SetPropertyValue("HostAddress", IP); mPort.SetPropertyValue("PortNumber", Port); mPort.SetPropertyValue("SNMPEnabled", false); var put = new PutOptions { UseAmendedQualifiers = true, Type = PutType.UpdateOrCreate }; mPort.Put(put); } if (!Name.StartsWith("\\\\")) return; // Add per machine printer connection var proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /ga /n " + Name); if (proc != null) proc.WaitForExit(120000); // Add printer network connection, download the drivers from the print server proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /in /n " + Name); if (proc != null) proc.WaitForExit(120000); }
private string RegisterProviderAsEventProvider(StringCollection events) { ManagementObject obj2 = new ManagementClass(this.EventProviderRegistrationClassPath).CreateInstance(); obj2["provider"] = @"\\.\" + this.ProviderPath; string[] strArray = new string[events.Count]; int num = 0; foreach (string str in events) { strArray[num++] = "select * from " + str; } obj2["EventQueryList"] = strArray; return obj2.Put().Path; }
private void RegisterNamespaceAsInstrumented() { ManagementObject obj2 = new ManagementClass(this.GlobalRegistrationClassPath).CreateInstance(); obj2["NamespaceName"] = this.NamespaceName; obj2.Put(); }
private void RegisterAssemblySpecificDecoupledProviderInstance() { ManagementObject obj2 = new ManagementClass(this.ProviderClassPath).CreateInstance(); obj2["Name"] = this.DecoupledProviderInstanceName; obj2["HostingModel"] = "Decoupled:Com"; if (this.SecurityDescriptor != null) { obj2["SecurityDescriptor"] = this.SecurityDescriptor; } obj2.Put(); }
private void RegisterAssemblyAsInstrumented() { ManagementObject obj2 = new ManagementClass(this.RegistrationClassPath).CreateInstance(); obj2["Name"] = this.DecoupledProviderInstanceName; obj2["RegisteredBuild"] = this.AssemblyUniqueIdentifier; obj2["FullName"] = this.AssemblyName; obj2["PathToAssembly"] = this.AssemblyPath; obj2["Code"] = ""; obj2["Mof"] = ""; obj2.Put(); }
private static void EnsureNamespace(string baseNamespace, string childNamespaceName) { if (!DoesInstanceExist(baseNamespace + ":__NAMESPACE.Name=\"" + childNamespaceName + "\"")) { ManagementObject obj2 = new ManagementClass(baseNamespace + ":__NAMESPACE").CreateInstance(); obj2["Name"] = childNamespaceName; obj2.Put(); } }
/// <summary> /// Given a class path, and a ManagementClass class definition, this /// function will create the class if it does not exist, replace the /// class if it exists but is different, or do nothing if the class /// exists and is identical. This is useful for performance reasons /// since it can be expensive to delete an existing class and replace /// it. /// </summary> /// <param name="classPath">WMI path to class</param> /// <param name="newClass">Class to create or replace</param> static void ReplaceClassIfNecessary(string classPath, ManagementClass newClass) { try { ManagementClass oldClass = SafeGetClass(classPath); if(null == oldClass) newClass.Put(); else { // if(newClass.GetText(TextFormat.Mof) != oldClass.GetText(TextFormat.Mof)) { // oldClass.Delete(); newClass.Put(); } } } catch(ManagementException e) { string strformat = RC.GetString("CLASS_NOTREPLACED_EXCEPT") + "\r\n{0}\r\n{1}"; throw new ArgumentException(String.Format(strformat, classPath, newClass.GetText(TextFormat.Mof)), e); } }
static void EnsureClassExists(InstallLogWrapper context, string classPath, ClassMaker classMakerFunction) { try { context.LogMessage(RC.GetString("CLASS_ENSURE") + " " +classPath); ManagementClass theClass = new ManagementClass(classPath); theClass.Get(); } catch(ManagementException e) { if(e.ErrorCode == ManagementStatus.NotFound) { // The class does not exist. Create it. context.LogMessage(RC.GetString("CLASS_ENSURECREATE")+ " " +classPath); ManagementClass theClass = classMakerFunction(); theClass.Put(); } else throw e; } }
static void createOrUpdateWmi() { Console.WriteLine("Checking for namespace " + wmiNamespaceString + ", and creating if missing"); PutOptions options = new PutOptions(); options.Type = PutType.UpdateOrCreate; ManagementClass objHostSettingClass = new ManagementClass("root\\cimv2", "__Namespace", null); ManagementObject wmiObject = objHostSettingClass.CreateInstance(); wmiObject.SetPropertyValue("Name", wmiNamespaceName); wmiObject.Put(options); System.Management.ManagementClass wmiClass; try { wmiClass = new System.Management.ManagementClass(wmiNamespaceString, wmiClassString, null); wmiClass.CreateInstance(); Console.WriteLine(wmiClassString + " class exists"); } catch (ManagementException me) { Console.WriteLine(wmiClassString + " class does not exist, creating"); wmiClass = new System.Management.ManagementClass(wmiNamespaceString, null, null); wmiClass["__CLASS"] = wmiClassString; wmiClass.Qualifiers.Add("Static", true); wmiClass.Put(); } if (!testValueExists(wmiClass, "ManagedFolder")) { wmiClass.Properties.Add("ManagedFolder", System.Management.CimType.String, false); wmiClass.Properties["ManagedFolder"].Qualifiers.Add("Key", true); } if (!testValueExists(wmiClass, "MachineName")) { wmiClass.Properties.Add("MachineName", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "OverallState")) { wmiClass.Properties.Add("OverallState", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "OverallStateValue")) { wmiClass.Properties.Add("OverallStateValue", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "FileCount")) { wmiClass.Properties.Add("FileCount", System.Management.CimType.UInt64, false); } if (!testValueExists(wmiClass, "NumberOfFilesFailingVerification")) { wmiClass.Properties.Add("NumberOfFilesFailingVerification", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "VerificationFailureDetails")) { wmiClass.Properties.Add("VerificationFailureDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "LastSuccessfulVerification")) { wmiClass.Properties.Add("LastSuccessfulVerification", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "VerifyNewImages")) { wmiClass.Properties.Add("VerifyNewImages", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "ReverifyExistingImages")) { wmiClass.Properties.Add("ReverifyExistingImages", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "ReverifyInterval")) { wmiClass.Properties.Add("ReverifyInterval", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "ConsolidationEnabled")) { wmiClass.Properties.Add("ConsolidationEnabled", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "LastSuccessfulConsolidation")) { wmiClass.Properties.Add("LastSuccessfulConsolidation", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "NumberOfFilesFailingConsolidation")) { wmiClass.Properties.Add("NumberOfFilesFailingConsolidation", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "ConsolidationFailureDetails")) { wmiClass.Properties.Add("ConsolidationFailureDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "FailedReplications")) { wmiClass.Properties.Add("FailedReplications", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "NumberOfFilesQueuedForReplication")) { wmiClass.Properties.Add("NumberOfFilesQueuedForReplication", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "ReplicationTargetDetails")) { wmiClass.Properties.Add("ReplicationTargetDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "RetentionIssues")) { wmiClass.Properties.Add("RetentionIssues", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "RetentionIssueDetails")) { wmiClass.Properties.Add("RetentionIssueDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "RetentionEnabled")) { wmiClass.Properties.Add("RetentionEnabled", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "RetentionPolicyInheritedFromGlobal")) { wmiClass.Properties.Add("RetentionPolicyInheritedFromGlobal", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "DaysToRetainIntraDailyImages")) { wmiClass.Properties.Add("DaysToRetainIntraDailyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "DaysToRetainConsolidatedDailyImages")) { wmiClass.Properties.Add("DaysToRetainConsolidatedDailyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "DaysToRetainConsolidatedWeeklyImages")) { wmiClass.Properties.Add("DaysToRetainConsolidatedWeeklyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "MonthsToRetainConsolidatedMonthlyImages")) { wmiClass.Properties.Add("MonthsToRetainConsolidatedMonthlyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "DaysToRetainIntraDailyImages")) { wmiClass.Properties.Add("DaysToRetainIntraDailyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "MonthlyRetentionIsSupported")) { wmiClass.Properties.Add("MonthlyRetentionIsSupported", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "MoveConsolidatedImages")) { wmiClass.Properties.Add("MoveConsolidatedImages", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "FailedHeadstartJobs")) { wmiClass.Properties.Add("FailedHeadstartJobs", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "HeadstartJobDetails")) { wmiClass.Properties.Add("HeadstartJobDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "LastScriptRunTime")) { wmiClass.Properties.Add("LastScriptRunTime", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "Timestamp")) { wmiClass.Properties.Add("Timestamp", System.Management.CimType.UInt64, false); } if (!testValueExists(wmiClass, "ListOfAllManagedFolders")) { wmiClass.Properties.Add("ListOfAllManagedFolders", System.Management.CimType.String, false); } try { wmiClass.Put(); } catch (ManagementException me) { if (me.ErrorCode.Equals(ManagementStatus.ClassHasInstances)) { Console.WriteLine("Deleting existing instances of " + wmiClassString); ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiNamespaceString, "SELECT * FROM " + wmiClassString); foreach (ManagementObject queryObj in searcher.Get()) { queryObj.Delete(); } wmiClass.Put(); } else { throw me; } } }
private string RegisterProviderAsInstanceProvider() { ManagementObject obj2 = new ManagementClass(this.InstanceProviderRegistrationClassPath).CreateInstance(); obj2["provider"] = @"\\.\" + this.ProviderPath; obj2["SupportsGet"] = true; obj2["SupportsEnumeration"] = true; return obj2.Put().Path; }
static void createOrUpdateWmi() { Console.WriteLine("Checking for namespace " + wmiNamespaceString+", and creating if missing"); PutOptions options = new PutOptions(); options.Type = PutType.UpdateOrCreate; ManagementClass objHostSettingClass = new ManagementClass("root\\cimv2", "__Namespace", null); ManagementObject wmiObject = objHostSettingClass.CreateInstance(); wmiObject.SetPropertyValue("Name", wmiNamespaceName); wmiObject.Put(options); System.Management.ManagementClass wmiClass; try { wmiClass = new System.Management.ManagementClass(wmiNamespaceString, wmiClassString, null); wmiClass.CreateInstance(); Console.WriteLine(wmiClassString + " class exists"); } catch (ManagementException me) { Console.WriteLine(wmiClassString + " class does not exist, creating"); wmiClass = new System.Management.ManagementClass(wmiNamespaceString, null, null); wmiClass["__CLASS"] = wmiClassString; wmiClass.Qualifiers.Add("Static", true); wmiClass.Put(); } if (!testValueExists(wmiClass, "ManagedFolder")) { wmiClass.Properties.Add("ManagedFolder", System.Management.CimType.String, false); wmiClass.Properties["ManagedFolder"].Qualifiers.Add("Key", true); } if (!testValueExists(wmiClass, "MachineName")) { wmiClass.Properties.Add("MachineName", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "OverallState")) { wmiClass.Properties.Add("OverallState", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "OverallStateValue")) { wmiClass.Properties.Add("OverallStateValue", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "FileCount")) { wmiClass.Properties.Add("FileCount", System.Management.CimType.UInt64, false); } if (!testValueExists(wmiClass, "NumberOfFilesFailingVerification")) { wmiClass.Properties.Add("NumberOfFilesFailingVerification", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "VerificationFailureDetails")) { wmiClass.Properties.Add("VerificationFailureDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "LastSuccessfulVerification")) { wmiClass.Properties.Add("LastSuccessfulVerification", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "VerifyNewImages")) { wmiClass.Properties.Add("VerifyNewImages", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "ReverifyExistingImages")) { wmiClass.Properties.Add("ReverifyExistingImages", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "ReverifyInterval")) { wmiClass.Properties.Add("ReverifyInterval", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "ConsolidationEnabled")) { wmiClass.Properties.Add("ConsolidationEnabled", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "LastSuccessfulConsolidation")) { wmiClass.Properties.Add("LastSuccessfulConsolidation", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "NumberOfFilesFailingConsolidation")) { wmiClass.Properties.Add("NumberOfFilesFailingConsolidation", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "ConsolidationFailureDetails")) { wmiClass.Properties.Add("ConsolidationFailureDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "FailedReplications")) { wmiClass.Properties.Add("FailedReplications", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "NumberOfFilesQueuedForReplication")) { wmiClass.Properties.Add("NumberOfFilesQueuedForReplication", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "ReplicationTargetDetails")) { wmiClass.Properties.Add("ReplicationTargetDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "RetentionIssues")) { wmiClass.Properties.Add("RetentionIssues", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "RetentionIssueDetails")) { wmiClass.Properties.Add("RetentionIssueDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "RetentionEnabled")) { wmiClass.Properties.Add("RetentionEnabled", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "RetentionPolicyInheritedFromGlobal")) { wmiClass.Properties.Add("RetentionPolicyInheritedFromGlobal", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "DaysToRetainIntraDailyImages")) { wmiClass.Properties.Add("DaysToRetainIntraDailyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "DaysToRetainConsolidatedDailyImages")) { wmiClass.Properties.Add("DaysToRetainConsolidatedDailyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "DaysToRetainConsolidatedWeeklyImages")) { wmiClass.Properties.Add("DaysToRetainConsolidatedWeeklyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "MonthsToRetainConsolidatedMonthlyImages")) { wmiClass.Properties.Add("MonthsToRetainConsolidatedMonthlyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "DaysToRetainIntraDailyImages")) { wmiClass.Properties.Add("DaysToRetainIntraDailyImages", System.Management.CimType.SInt32, false); } if (!testValueExists(wmiClass, "MonthlyRetentionIsSupported")) { wmiClass.Properties.Add("MonthlyRetentionIsSupported", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "MoveConsolidatedImages")) { wmiClass.Properties.Add("MoveConsolidatedImages", System.Management.CimType.Boolean, false); } if (!testValueExists(wmiClass, "FailedHeadstartJobs")) { wmiClass.Properties.Add("FailedHeadstartJobs", System.Management.CimType.UInt32, false); } if (!testValueExists(wmiClass, "HeadstartJobDetails")) { wmiClass.Properties.Add("HeadstartJobDetails", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "LastScriptRunTime")) { wmiClass.Properties.Add("LastScriptRunTime", System.Management.CimType.String, false); } if (!testValueExists(wmiClass, "Timestamp")) { wmiClass.Properties.Add("Timestamp", System.Management.CimType.UInt64, false); } if (!testValueExists(wmiClass, "ListOfAllManagedFolders")) { wmiClass.Properties.Add("ListOfAllManagedFolders", System.Management.CimType.String, false); } try { wmiClass.Put(); } catch (ManagementException me) { if (me.ErrorCode.Equals(ManagementStatus.ClassHasInstances)) { Console.WriteLine("Deleting existing instances of " + wmiClassString); ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiNamespaceString, "SELECT * FROM " + wmiClassString); foreach (ManagementObject queryObj in searcher.Get()) { queryObj.Delete(); } wmiClass.Put(); } else { throw me; } } }
public Boolean install(long maxWait) { long waited = 0L; int port = 9100; if (isComplete()) { if (maxWait > 0) { //if ( strFile.Length == 0 || File.Exists(strFile)) //{ if (strIP != null && strIP.Length > 0 ) { if (strIP.Contains(":")) { String[] arIP = strIP.Split(new char[] { ':' }); if (arIP.Length == 2) { strIP = arIP[0]; try { port = Int32.Parse( arIP[1] ); } catch { } } } ConnectionOptions conn = new ConnectionOptions(); conn.EnablePrivileges = true; conn.Impersonation = ImpersonationLevel.Impersonate; ManagementPath mPath = new ManagementPath("Win32_TCPIPPrinterPort"); ManagementScope mScope = new ManagementScope(@"\\.\root\cimv2", conn); mScope.Options.EnablePrivileges = true; mScope.Options.Impersonation = ImpersonationLevel.Impersonate; ManagementObject mPort = new ManagementClass(mScope, mPath, null).CreateInstance(); mPort.SetPropertyValue("Name", "IP_" + strIP); mPort.SetPropertyValue("Protocol", 1); mPort.SetPropertyValue("HostAddress", strIP); mPort.SetPropertyValue("PortNumber", port); mPort.SetPropertyValue("SNMPEnabled", false); PutOptions put = new PutOptions(); put.UseAmendedQualifiers = true; put.Type = PutType.UpdateOrCreate; mPort.Put(put); } Process proc; Boolean blIsIPP = false; if (strPort.Trim().ToLower().StartsWith("ipp://")) { // iprint installation proc = new Process(); proc.StartInfo.FileName = @"c:\windows\system32\iprntcmd.exe"; proc.StartInfo.Arguments = " -a no-gui \"" + strPort + "\""; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.Start(); blIsIPP = true; } else if (strAlias.Trim().ToLower().StartsWith("\\\\")) { // Add per machine printer connection proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /ga /n " + strAlias); proc.WaitForExit(120000); // Add printer network connection, download the drivers from the print server proc = Process.Start("rundll32.exe", " printui.dll,PrintUIEntry /in /n " + strAlias); proc.WaitForExit(120000); bounceSpooler(); } else { // Normal Installation proc = Process.Start("rundll32.exe", getInstallArguments()); } while (!proc.HasExited) { sleep(100); waited += 100; if (waited > maxWait) { proc.Kill(); strError = "Max install time exceeded (" + maxWait + ")"; return false; } } if (blIsIPP) { strError = "IPP Return codes unknown"; return true; } if (proc.ExitCode == 0) { strError = ""; return true; } //} //else //strError = "Printer Definition file was not found!"; //strError = "Strfile:" + strFile + "."; } else strError = "Max wait time was less than zero!"; } else strError = "Printer information is incomplete"; return false; }
private void CreateNewAppPool(ManagementScope scope, string name) { ManagementObject appPool = new ManagementClass(scope, new ManagementPath("IIsApplicationPoolSetting"), null).CreateInstance(); appPool["Name"] = String.Format("W3SVC/AppPools/{0}", name); appPool.Put(); }
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); }