Ejemplo n.º 1
0
        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();
        }
        /// <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);
        }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
        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) {}
        }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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;
 }