启动Windows应用程序并自动输入用户名和密码

我有一些想要在启动时打开的应用程序。他们需要用户名和密码才能登录。输入这些内容并按LogIn后,将显示一条确认消息,以确认您是否要登录。

可以使用CMD或PowerShell完成此操作吗?

例如:

> Start <path>/App1 | username ; Password | Press OK
> Start <path>/App2 | username ; Password | Press OK
huazai19851108 回答:启动Windows应用程序并自动输入用户名和密码

也许这对您有帮助:

Add-Type -AssemblyName System.Windows.Forms

#----------------------------------------------------------------------
function win32UserDLL {
<#
// set focus to window 
#>
#----------------------------------------------------------------------
    param(
        [Parameter()]
        $mainWindowHandle = (Get-Process -Id $pid).MainWindowHandle,[Parameter()]
        [ValidateSet('SetFocus','BringWindowToTop')]
        [String]$action = 'SetFocus'
    )

    $win32UserDLL = Add-Type –memberDefinition @” 
    [DllImport("user32.dll",SetLastError = true)] 
    public static extern IntPtr SetFocus(IntPtr hWnd);
    [DllImport("user32.dll",SetLastError = true)]
    public static extern bool BringWindowToTop(IntPtr hWnd);
“@ -name “Win32SetFocus” -namespace Win32Functions –passThru


    switch( $action ) {
        'SetFocus' {
            [void]$win32UserDLL::SetFocus($mainWindowHandle) 
        }
        'BringWindowToTop' {
            [void]$win32UserDLL::BringWindowToTop($mainWindowHandle) 
        }
    }
}

$appName = "myApp"

$handle = (Get-Process | where { $_.ProcessName -like $appName }).MainWindowHandle | where { $_ -ne 0 }

$handle

win32UserDLL -mainWindowHandle $handle -action SetFocus

[System.Windows.Forms.SendKeys]::SendWait("Username")
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
[System.Windows.Forms.SendKeys]::SendWait("Password")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
本文链接:https://www.f2er.com/2693392.html

大家都在问