当前位置: 首页>>代码示例>>C#>>正文


C# ManagementObject.Delete方法代码示例

本文整理汇总了C#中System.Management.ManagementObject.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObject.Delete方法的具体用法?C# ManagementObject.Delete怎么用?C# ManagementObject.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementObject的用法示例。


在下文中一共展示了ManagementObject.Delete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteVirtualDirectory

        public void DeleteVirtualDirectory()
        {
            var siteId = 1574596940;
            //            var siteId = 1;
            var dir = "iplayer";
            var name = String.Format(@"W3SVC/{0}/root/{1}", siteId, dir);

            var path = string.Format("IIsWebVirtualDir.Name='{0}'", name);
            var app = new ManagementObject(Scope, new ManagementPath(path), null);
            app.Delete();
        }
开发者ID:nbucket,项目名称:bounce,代码行数:11,代码来源:Iis6WebSiteTest.cs

示例2: ThreadedPrintJob

        /// <summary>
        ///     Method that can be used in a single thread.
        ///     Based on the printJob given, build a PrintJobData object,
        ///     run automations on the PrintJobData based on BlockedUsers and autoDelete.
        ///     When finished automating, add it to a list of CurrentPrintJobs.
        /// </summary>
        /// <param name="printJob"> A managementObject of type Win32_PrintJob. </param>
        private void ThreadedPrintJob(ManagementObject printJob)
        {
            var logBuilder = "";
            var pages = int.Parse(printJob.Properties ["TotalPages"].Value.ToString());
            var jobDataBuilder = new PrintJobData {
                                                      JobId = int.Parse(printJob.Properties ["JobId"].Value.ToString()),
                                                      Size = int.Parse(printJob.Properties ["Size"].Value.ToString()),
                                                      Pages = pages == 0 ? 1 : pages,
                                                      Status = GetCurrentStatus(printJob.Properties ["StatusMask"].Value.ToString(), true),
                                                      TimeStarted = printJob.Properties ["TimeSubmitted"].Value.ToString(),
                                                      User = printJob.Properties ["Owner"].Value.ToString(),
                                                      DocumentName = printJob.Properties ["Document"].Value.ToString(),
                                                      MachineName = printJob.Properties ["HostPrintQueue"].Value.ToString()
                                                  };
            //Set the proper time to a legible fasion.
            var hour = Convert.ToInt32(jobDataBuilder.TimeStarted.Substring(8, 2));
            var isPm = hour%13 < hour;
            hour = isPm ? hour%13 + 1 : hour;
            var min = jobDataBuilder.TimeStarted.Substring(10, 2);
            var sec = jobDataBuilder.TimeStarted.Substring(12, 2);
            var day = jobDataBuilder.TimeStarted.Substring(6, 2);
            var mon = jobDataBuilder.TimeStarted.Substring(4, 2);
            var year = jobDataBuilder.TimeStarted.Substring(0, 4);
            jobDataBuilder.TimeStarted = hour + ":" + min + ":" + sec + " " + (isPm ? "PM" : "AM") + " - (" + mon + "/" + day + "/" + year + ")";

            var userAllocatedPages = CheckBlockedList(jobDataBuilder);
            //Check for autoDelete.
            if (jobDataBuilder.Pages > PrinterWindow.DeletePrintLimit || userAllocatedPages > PrinterWindow.DeletePrintLimit) {
                try {
                    printJob.Properties ["StatusMask"].Value = (uint) printJob.Properties ["StatusMask"].Value + PrintJobFlags.AutoDelete;
                    jobDataBuilder.Status = GetCurrentStatus(printJob.Properties ["StatusMask"].Value.ToString(), true);
                    printJob.Delete();
                    DeleteBlockedJob(jobDataBuilder);
                    logBuilder += "\r\n   Job deleted: " + jobDataBuilder.JobId + " : " + jobDataBuilder.MachineName;
                }
                catch (Exception ex) {
                    logBuilder += "\r\nError on auto delete for job " + jobDataBuilder.JobId + ": " + ex.Message +
                                  "\r\n\r\n" + ex.StackTrace;
                }
            }
            //Check for autoPause.
            else if (jobDataBuilder.Pages > PrinterWindow.PausePrintLimit || userAllocatedPages > PrinterWindow.PausePrintLimit) {
                try {
                    printJob.InvokeMethod("Pause", null);
                    printJob.Properties ["StatusMask"].Value = (uint) printJob.Properties ["StatusMask"].Value + PrintJobFlags.AutoPause - PrintJobFlags.Paused;
                    jobDataBuilder.Status = GetCurrentStatus(printJob.Properties["StatusMask"].Value.ToString(), true);
                    logBuilder += "\r\n   Job paused: " + jobDataBuilder.JobId + " : " + jobDataBuilder.MachineName;
                }
                catch (Exception ex) {
                    logBuilder += "\r\nError on auto pause for job " + jobDataBuilder.JobId + ": " + ex.Message +
                                  "\r\n\r\n" + ex.StackTrace;
                }
            }
            logBuilder += "\r\n Job allowed: " + jobDataBuilder.JobId + " : " + jobDataBuilder.MachineName;
            LogManager.AppendLog(logBuilder);

            CheckPrintHistory(jobDataBuilder);
            lock (CurrentPrintJobs)
                CurrentPrintJobs.Add(jobDataBuilder);
        }
开发者ID:bkohler616,项目名称:SpoolerMasterUltimate,代码行数:67,代码来源:PrintJobManager.cs

示例3: DeleteVirtualDirectory

 public void DeleteVirtualDirectory(string subPath)
 {
     var name = String.Format(@"{0}/root/{1}", Name, subPath);
     var path = string.Format("IIsWebVirtualDir.Name='{0}'", name);
     var virtualDirectory = new ManagementObject(scope, new ManagementPath(path), null);
     virtualDirectory.Delete();
 }
开发者ID:haos11,项目名称:bounce,代码行数:7,代码来源:IisWebSite.cs

示例4: TryDeletePrintJob

        private void TryDeletePrintJob(Dictionary<string, string> printJobMap, ManagementObject job)
        {
            try
            {
                var printJobName = (string)job["Document"];
                var jobId = (string)job["Name"];
                var commaIndex = jobId.LastIndexOf(',');
                var printerName = jobId.Substring(0, commaIndex);

                if (printJobMap.ContainsKey(printJobName) && printerName.Equals(printJobMap[printJobName]))
                {
                    job.Delete();
                }
            }
            catch (Exception) {}
        }
开发者ID:weiai,项目名称:XiconfLabelPrinter,代码行数:16,代码来源:PrintForm.cs

示例5: RemoveFilter

 private bool RemoveFilter(string name)
 {
     try
     {
         ManagementObject filter = new ManagementObject(@"root\subscription:__EventFilter.Name='" + name + "'");
         filter.Delete();
         Debug.WriteLine("Successfully deleted WMI event filter: " + name);
         return true;
     }
     catch
     {
         Debug.WriteLine("Error occurred deleting filter with name: " + name);
     }
     return false;
 }
开发者ID:pcgeek86,项目名称:PowerEvents,代码行数:15,代码来源:Form1.cs

示例6: RemoveConsumer

 private bool RemoveConsumer(string name, string ConsumerClass)
 {
     try
     {
         ManagementObject consumer = new ManagementObject(@"root\subscription:" + ConsumerClass + ".Name='" + name + "'");
         consumer.Delete();
         Debug.WriteLine("Successfully deleted WMI event consumer type (" + ConsumerClass + ") named: " + name);
         return true;
     }
     catch
     {
         Debug.WriteLine("Error occurred deleting consumer type (" + ConsumerClass + ") named: " + name);
     }
     return false;
 }
开发者ID:pcgeek86,项目名称:PowerEvents,代码行数:15,代码来源:Form1.cs

示例7: RemoveBinding

 private bool RemoveBinding(string WmiPath)
 {
     try
     {
         ManagementObject binding = new ManagementObject(WmiPath);
         binding.Delete();
         Debug.WriteLine("Successfully deleted WMI event binding: " + WmiPath);
         return true;
     }
     catch
     {
         Debug.WriteLine("Error occurred deleting WMI event binding: " + WmiPath);
     }
     return false;
 }
开发者ID:pcgeek86,项目名称:PowerEvents,代码行数:15,代码来源:Form1.cs


注:本文中的System.Management.ManagementObject.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。