public static bool CheckPrinterExists()
        {
            if (objUDC != null)
            {
                return(true);
            }
            object objPrn = null;

            try
            {
                bool v6         = true;
                Type objPrnType = Type.GetTypeFromCLSID(new Guid(WripperGuid));
                if (objPrnType == null)
                {
                    objPrnType = Type.GetTypeFromCLSID(new Guid(PrinterGuid));
                    v6         = false;
                }

                if (objPrnType == null)
                {
                    return(false);
                }
                else
                {
                    objPrn     = Activator.CreateInstance(objPrnType);
                    objPrnType = null;
                    if (objPrn == null)
                    {
                        return(false);
                    }
                    else if (v6)
                    {
                        objUDC = (IUDC)objPrn;
                        objPrn = null;
                    }
                    else
                    {
                        Marshal.ReleaseComObject(objPrn);
                        objPrn = null;
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                if (objPrn != null)
                {
                    Marshal.ReleaseComObject(objPrn);
                    objPrn = null;
                }
            }
        }
        public static string GetPrinterPath()
        {
            Console.WriteLine("{0}: GetPrinterPath printer com exists : {1}", DateTime.Now.ToString("HH:mm:ss fff"), objUDC != null);
            object objPrn = null;
            object objPrf = null;

            if (objUDC == null || objUDC.Version < 6)
            {
                Type objPrnType = Type.GetTypeFromCLSID(new Guid(WripperGuid));
                if (objPrnType == null)
                {
                    objPrnType = Type.GetTypeFromCLSID(new Guid(PrinterGuid));
                }

                if (objPrnType == null)
                {
                    return(null);
                }
                try
                {
                    objPrn = Activator.CreateInstance(objPrnType);
                    if (objPrn == null)
                    {
                        return(null);
                    }
                    var ver = RunCom.GetProperty(objPrn, "Version");
                    int v   = 0;
                    if (ver is float)
                    {
                        v = (int)(float)ver;
                    }
                    else
                    {
                        v = (int)ver;
                    }
                    if (v < 6)
                    {
                        var str = (string)RunCom.GetProperty(objPrn, "DefaultProfile");
                        objPrf = RunCom.GetProperty(objPrn, "Profile", str);
                        var path = (string)RunCom.GetProperty(objPrf, "PreDefinedImageFilePath");
                        if (!string.IsNullOrEmpty(path))
                        {
                            return(path);
                        }
                    }
                    else
                    {
                        objUDC = (IUDC)objPrn;
                        objPrf = RunCom.GetProperty(objPrn, "Printers", Environment.PrinterName);
                        objPrn = null;
                        if (objPrf == null)
                        {
                            return(null);
                        }
                        object Profile = RunCom.GetProperty(objPrf, "Profile");
                        if (Profile == null)
                        {
                            return(null);
                        }
                        object OutputLocation = RunCom.GetProperty(Profile, "OutputLocation");
                        Marshal.ReleaseComObject(Profile);
                        Profile = null;
                        if (OutputLocation == null)
                        {
                            return(null);
                        }
                        var s = RunCom.GetProperty(OutputLocation, "FolderPath");

                        string path = s as string;
                        Marshal.ReleaseComObject(OutputLocation);
                        OutputLocation = null;
                        if (string.IsNullOrEmpty(path))
                        {
                            return(null);
                        }
                        else
                        {
                            path = Path.GetFullPath(path.Replace("&[TEMP]", Path.GetTempPath()).Replace("&[Documents]",
                                                                                                        System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)));
                        }
                        return(path);
                    }
                }
                catch (Exception ex)
                {
                    Data.Env.WriteToLog(ex, "TestPrinter.GetPrinterPath");
                }
                finally
                {
                    objPrnType = null;
                    if (objPrn != null)
                    {
                        Marshal.ReleaseComObject(objPrn);
                        objPrn = null;
                    }
                    if (objPrf != null)
                    {
                        Marshal.ReleaseComObject(objPrf);
                        objPrf = null;
                    }
                }
            }
            else
            {
                try
                {
                    Printer pr   = objUDC.Printers[Environment.PrinterName];
                    string  path = pr.Profile.OutputLocation.FolderPath;
                    Marshal.ReleaseComObject(pr);
                    pr = null;
                    if (string.IsNullOrEmpty(path))
                    {
                        return(null);
                    }
                    else
                    {
                        path = Path.GetFullPath(path.Replace("&[TEMP]", Path.GetTempPath()).Replace("&[Documents]",
                                                                                                    System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments)));
                    }
                    return(path);
                }
                catch (Exception ex)
                {
                    Log.Logger.WriteEx(ex);
                }
            }
            return(null);
        }