2012-02-22 3 views
1

나는 스풀러의 AddMonitor 함수를 호출하여 설치하는 포트 모니터 DLL을 가지고있다. 그러나이 모니터를 제거하지 않으려면 DeleteMonitor 함수가 오류 코드 3008 - "지정된 인쇄 모니터가 현재 사용 중입니다"를 반환합니다. 모니터 DLL을 어떻게 무료로 사용할 수 있습니까? 현재 해당 유형의 포트를 사용하여 하나 이상의 프린터 개체가있는 경우가상 프린터 포트 모니터 설치



    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] 
    private class MONITOR_INFO_2 
    { 
     [MarshalAs(UnmanagedType.LPStr)] 
     public string pName; 
     [MarshalAs(UnmanagedType.LPStr)] 
     public string pEnvironment; 
     [MarshalAs(UnmanagedType.LPStr)] 
     public string pDLLName; 
    } 

    [DllImport("winspool.Drv", EntryPoint = "AddMonitorA", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    private static extern bool AddMonitor(
    [MarshalAs(UnmanagedType.LPStr)] string Name, 
    Int32 Level, 
    [In, MarshalAs(UnmanagedType.LPStruct)] MONITOR_INFO_2 mi2); 

    [DllImport("winspool.Drv", EntryPoint = "DeleteMonitorA", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    private static extern bool DeleteMonitor(
    [MarshalAs(UnmanagedType.LPStr)] string pNullServerName, 
    [MarshalAs(UnmanagedType.LPStr)] string pNullEnvironment, 
    [MarshalAs(UnmanagedType.LPStr)] string MonitorName); 

    private unsafe void InstallMonitor(string monitorName, string dllName) 
    { 
     MONITOR_INFO_2 mi2 = new MONITOR_INFO_2(); 
     mi2.pName = monitorName; 
     mi2.pEnvironment = null; 
     mi2.pDLLName = dllName; 

     try 
     { 
      bool bRet = AddMonitor(null, 2, mi2); 
      if (!bRet) 
       throw new Win32Exception(Marshal.GetLastWin32Error()); 
     } 
     catch (Exception e) 
     { 
      if (!DeleteMonitor(null, null, monitorName)) 
      { 
       throw new Win32Exception(Marshal.GetLastWin32Error()); 
      } 
      bRet = AddMonitor(null, 2, mi2); 
      if (!bRet) 
       throw new Win32Exception(Marshal.GetLastWin32Error()); 
     } 
    } 

답변

0

당신은 DeleteMonitor 호출을 통해 포트 모니터를 삭제 할 수 없습니다.

이 몇 가지 옵션을 잎 :

  • 스왑 다른 포트에 영향을받는 모든 프린터의 포트입니다. (LPT1과 같은 것을 사용하는 것이 가장 좋습니다 : 항상 거기에 있기 때문에).
  • 포트를 사용하는 모든 프린터를 삭제하십시오.
  • 스풀러 서비스를 중지하고 레지스트리 (HKLM \ SYSTEM \ CurrentControlSet \ Control \ Print \ Monitors)에서 해당 항목을 제거한 다음 스풀러를 다시 시작하십시오. 이렇게하면 영향을받는 프린터가 그대로 남아 있지만 사용할 수 없게됩니다.