Пример #1
0
        private bool AddPortMonitor(MONITOR_INFO_2 newMonitor)
        {
            bool monitorAdded = false;

            if ((NativeMethods.AddMonitor(null, 2, ref newMonitor) != 0))
            {
                monitorAdded = true;
            }
            return(monitorAdded);
        }
Пример #2
0
        /// <summary>
        /// Adds the PDF Scribe port monitor
        /// </summary>
        /// <param name="monitorFilePath">Directory where the uninstalled monitor dll is located</param>
        /// <returns>true if the monitor is installed, false if install failed</returns>
        public bool AddPdfScribePortMonitor(String monitorFilePath)
        {
            bool monitorAdded = false;

            IntPtr oldRedirectValue = IntPtr.Zero;

            try
            {
                oldRedirectValue = DisableWow64Redirection();
                if (!DoesMonitorExist(PORTMONITOR))
                {
                    // Copy the monitor DLL to
                    // the system directory
                    String fileSourcePath      = Path.Combine(monitorFilePath, MONITORDLL);
                    String fileDestinationPath = Path.Combine(Environment.SystemDirectory, MONITORDLL);
                    try
                    {
                        File.Copy(fileSourcePath, fileDestinationPath, true);
                    }
                    catch (IOException)
                    {
                        // File in use, log -
                        // this is OK because it means the file is already there
                    }
                    MONITOR_INFO_2 newMonitor = new MONITOR_INFO_2();
                    newMonitor.pName        = PORTMONITOR;
                    newMonitor.pEnvironment = ENVIRONMENT_64;
                    newMonitor.pDLLName     = MONITORDLL;
                    if (!AddPortMonitor(newMonitor))
                    {
                        logEventSource.TraceEvent(TraceEventType.Error,
                                                  (int)TraceEventType.Error,
                                                  String.Format("Could not add port monitor {0}", PORTMONITOR) + Environment.NewLine +
                                                  String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString()));
                    }
                    else
                    {
                        monitorAdded = true;
                    }
                }
                else
                {
                    // Monitor already installed -
                    // log it, and keep going
                    logEventSource.TraceEvent(TraceEventType.Warning,
                                              (int)TraceEventType.Warning,
                                              String.Format("Port monitor {0} already installed.", PORTMONITOR));
                    monitorAdded = true;
                }
            }
            finally
            {
                if (oldRedirectValue != IntPtr.Zero)
                {
                    RevertWow64Redirection(oldRedirectValue);
                }
            }


            return(monitorAdded);
        }
Пример #3
0
 internal static extern Int32 AddMonitor(String pName, UInt32 Level, ref MONITOR_INFO_2 pMonitors);