如何用cmd或其他代码的方法来关闭打印机中的双向支持

com com 20 Reputation points
2023-06-16T03:30:26.1233333+00:00

如何用cmd或其他代码的方法来关闭打印机中的双向支持?针式打印机属性中端口一栏有双向支持这个选项,想用脚本一键关闭,不想手动关闭。

Windows for business Windows Server User experience PowerShell
Developer technologies VB
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-06-16T06:32:27.0733333+00:00

    Hi @com com ,

    This is an English-language forum, so it is recommended that you edit the question to post it in English.

    You can refer to the following code using WMI.

        Public Shared Sub DisableBidirectionalSupport(printerName As String)
            Dim query As String = String.Format("SELECT * FROM Win32_Printer WHERE Name = '{0}'", printerName)
    
            Dim searcher As New ManagementObjectSearcher(query)
            Dim printer As ManagementObject = Nothing
    
            For Each obj As ManagementObject In searcher.Get()
                printer = obj
                Exit For
            Next
    
            If printer IsNot Nothing Then
                Dim bidirectionalSupport As Boolean = Convert.ToBoolean(printer("BidirectionalSupport"))
    
                If bidirectionalSupport Then
                    printer("BidirectionalSupport") = False
                    printer.Put()
                    Console.WriteLine("Bidirectional support disabled for printer: " & printerName)
                Else
                    Console.WriteLine("Bidirectional support is already disabled for printer: " & printerName)
                End If
            Else
                Console.WriteLine("Printer not found: " & printerName)
            End If
        End Sub
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.