0

I want to translate this AutoIt script to Powershell v2. (AutoIt is a freeware BASIC-like scripting https://www.autoitscript.com/site/autoit/downloads/ )

#include <WinAPIGdi.au3>

Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
Local $colMonitors = $objWMIService.ExecQuery ("Select * from Win32_DesktopMonitor Where Availability=3", "WQL", 0x10 + 0x20)

If NOT IsObj($colMonitors) Then Exit

Local $iCount = 0
For $oMonitor In $colMonitors
    $iCount += 1
Next
MsgBox(0, "", "Number of monitors : " & $iCount)

$aMonitor = _WinAPI_EnumDisplayMonitors()
If @error Then Exit
ConsoleWrite   ("!! multiscreen mode:" & $aMonitor[0][0])            ;value equal one if there is one screen duplicated or not, if extended the value wille be greater than one. I don’t mind if the computer screen   are powered on or not. 
If $aMonitor[0][0] > 1 Then  
    MsgBox(0, "", "extended mode"&$aMonitor[0][0] )        ;give  2
Else
    MsgBox(0, "", "duplicate mode"&$aMonitor[0][0] )        ;give 1
EndIf


;---Excerpt from WinAPIGdi.au3  (included with AutoIt) :---
Func _WinAPI_EnumDisplayMonitors($hDC = 0, $tRECT = 0)
    Local $hEnumProc = DllCallbackRegister('__EnumDisplayMonitorsProc', 'bool', 'handle;handle;ptr;lparam')
    Dim $__g_vEnum[101][2] = [[0]]
    Local $aRet = DllCall('user32.dll', 'bool', 'EnumDisplayMonitors', 'handle', $hDC, 'struct*', $tRECT, _
            'ptr', DllCallbackGetPtr($hEnumProc), 'lparam', 0)
    If @error Or Not $aRet[0] Or Not $__g_vEnum[0][0] Then
        $__g_vEnum = @error + 10
    EndIf
    DllCallbackFree($hEnumProc)
    If $__g_vEnum Then Return SetError($__g_vEnum, 0, 0)

    __Inc($__g_vEnum, -1)
    Return $__g_vEnum
EndFunc   ;==>_WinAPI_EnumDisplayMonitors

I tried to begin with this commands in Powershell:

Get-Wmiobject win32_DesktopMonitor |format-list  
Get-Wmiobject -query "select Name,DeviceID,DisplayType from win32_DesktopMonitor where Availability=3"

It works but it’s really too short...

1 Answers1

1

Can you please specify what you would like to do? I am not sure what you are trying to achieve.

It works but it’s really too short...

So it works. That's good - right?

If you want to check how many screens are connected you can use the following cmdlet:

Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams

Source: Use PowerShell to Discover Multi-Monitor Information

0815 163
  • 51
  • 3
  • Thank you for the help. I am sorry, in fact I tried to explain in my title to briefly summarize that I want to know if the shortcut Windows P (which activate *multiscreen* project mode) is set in *extend mode or not*, with a powershell script. I didn't find any powershell script even with your answer. – A D - France Jan 30 '20 at 21:21
  • Sorry for the confusion. May I ask what your intended purpose is? You can force the settings with displayswitch.exe (see: https://stackoverflow.com/questions/275063/extend-my-windows-desktop-onto-this-monitor-programmatically ) – 0815 163 Jan 30 '20 at 23:42
  • Hello. Thanks again to try to help me, however I already know this. My Context: many computers to make a restraining automate to check if extend mode screen is enabled (I will not be behind the few hundred computers). My objective: disable extend mode temporaly if it's in place to force my users to stay in a window 2 minutes for fill out a form. There is different steps, the step is missing to implement my script is to get the current situation (duplicate/extend/... screen mode): I don't know how to extract data from user32.dll so as to get this information in powershell. Thanks – A D - France Feb 01 '20 at 15:38