none
[問題]Retrieving the COM class factory for component CSID...... RRS feed

  • 問題

  • 各位大大你們好!

     

    又有問題了...

    我有一個SERVICE 要不停MONITION 指定的PRINTER 的EVENT

    當PRINTER 有PRINT JOB 時 就會做BACKUP  的工作...這樣

    以下的CODE 是可行的

    但當電腦要 LOG OFF, RESTART, SHUT DOWN時, 就會出EXCEPTION ,

    會把我的SERVICE STOP 掉 ,再開電腦時 SERVICE 也會停止了, 直至 手動把SERVICE 再開就可以了

     

    問題是:

    1, 錯什啊>.<~?

    2, 解決方法是?

    3 我的CODE 有錯嗎? OR 有更好的寫法嗎?

     

     

    EXCEPTION:

    7/8/2008 11:01:57 Retrieving the COM class factory for component with CLSID {EB87E1BD-3233-11D2-AEC9-00C04FB68820} failed due to the following error: 80070013.,    at System.Management.ManagementException.GetMessage(ManagementStatus errorCode)
       at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
       at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext()
       at System.Management.ManagementObjectCollection.get_Count()
       at PrinterMonitionService.PrinterMonitionService.printerTimer_Elapsed(Object sender, ElapsedEventArgs e)

     

    CODE:

             ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_PrintJob");

             ManagementObjectCollection moc = null;

     

             try

             {

                    moc = mos.Get();
                    if (moc.Count == 0)
                    {
                        if (alPrinterJob.Count > 0)
                        {
                           //do somthing
                        }
                    }
                    else
                    {
                        foreach (ManagementObject printerJob in moc)
                        {
                            bool bolSameJob = false;
                            string[] tmp2 = printerJob["Name"].ToString().Split(',');
                            if (tmp2[0] == printerName)
                            {
                                for (int i = 0; i < alPrinterJob.Count; i++)
                                {
                                    if (((PrinterInfo)alPrinterJobIdea).jobID == Convert.ToInt32(printerJob["JobId"]))
                                    {
                                        bolSameJob = true;
                                        break;
                                    }
                                }
                                if (!bolSameJob)
                                {
                                    writeEventLog(printerJob["JobId"].ToString());
                                    PrinterInfo pi = new PrinterInfo(printerJob);
                                    alPrinterJob.Add(pi);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    writeEventLog(ex.Message + ", " + ex.StackTrace);
                    //this.Stop();
                }

            }

    2008年8月7日 上午 07:14