Execute Powershell function from SSH

This topic contains 0 replies, has 1 voice, and was last updated by  Marco 3 months, 3 weeks ago.

  • Author
    Posts
  • #90328

    Marco
    Participant

    Hello – I´m new to this Forum and to powershell. I have a home -automatisation System working mainly in python on raspberry.py (called smarthome.py). I have a touchscreen that I´d like to remotly turn on/off from that System. The screen is connected to a mini-pc running Windows 10 home.
    I was able to install the "toggleDisplay" module and it is working perfectly when I run this from powershell on the mini-pc itself. If I run it from SSH, it is not turning the Screen off nor on, allthough it is exucuted.
    The Powershell Version is 5.1.16299.98 and I connect with OpenSSH (loaded from optional Features) from Putty. The Executionplicy is unrestricted and as informed before there is no error message and the function is called but not turning of the Display (when called it returns a "1" in the console).

    Here you find the code of the module:

    Add-Type -Namespace Win32API -Name Message -MemberDefinition @'
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(
            int hWnd,
            UInt32 Msg,
            int wParam,
            int lParam
        );
    '@
    
    $msg = @{
        HWND_Broadcast = 0xFFFF
        WM_SysCommand = 0x0112
        SC_MonitorPower = 0xF170
        PowerOn = -1
        PowerOff = 2
    }
    
    Function Start-Display {
         Start-Display
    
        This command will turn on the display of the computer.
    
        .LINK
        Add-Type
        #>
    
        [CmdletBinding(HelpURI='https://gallery.technet.microsoft.com/Turn-the-Display-On-and-Off-3414d706')]
        
        Param()
    
        [Win32API.Message]::SendMessage($msg.HWND_Broadcast, $msg.WM_SysCommand, $msg.SC_MonitorPower, $msg.PowerOn) 
    }
    
    Function Stop-Display {
         Stop-Display
    
        This command will turn on the display of the computer.
    
        .LINK
        Add-Type
        #>
    
        [CmdletBinding(HelpURI='https://gallery.technet.microsoft.com/Turn-the-Display-On-and-Off-3414d706')]
    
        Param()
    
        [Win32API.Message]::SendMessage($msg.HWND_Broadcast, $msg.WM_SysCommand, $msg.SC_MonitorPower, $msg.PowerOff)
    }
    
    New-Alias -Name sadp -Value Start-Display
    New-Alias -Name spdp -Value Stop-Display
    

    Thanks for your help

You must be logged in to reply to this topic.