Отправляем текст в виртуальную машину или снова про copy paste print type password windows form VM VMRC
Недавно я опять решал две схожие проблемы – отправка пароля в окно виртуальной машины, оставшейся без сети, и ответ на вопрос «как включить copy paste vmware и отправить туда текст».
Самый простой способ – включить copy paste для виртуальной машины – только он не сработает для отправки (точнее, печати в нужном поле) сложного пароля без VM tools. Метод описан в:
kb Enable content Copy/Paste between VMRC client and Windows/Linux Virtual Machine (57122)
https://kb.vmware.com/s/article/57122
треде Copy/Paste through vCenter web console
https://communities.vmware.com/t5/VMware-vSphere-Discussions/Copy-Paste-through-vCenter-web-console/td-p/1829688
и общеизвестен –
isolation.tools.copy.disable FALSE
isolation.tools.paste.disable FALSE
isolation.tools.setGUIOptions.enable TRUE
Еще можно почитать Enabling clipboard copy and paste on vSphere VMs - https://www.altaro.com/vmware/clipboard-vsphere/
Там же описано, как скопировать файл в VM – # Copy File to VM (Person running this should have access within the Guest)
$vm = Get-VM XXX
Get-Item C:\Temp\XXXXXX.txt | Copy-VMGuestFile -Destination C:\Temp -VM $vm -LocalToGuest -GuestUser Administrator -GuestPassword PASSWORDHERE
https://communities.vmware.com/t5/VMware-vSphere-Discussions/Copy-Paste-through-vCenter-web-console/td-p/1829688
Есть метод Automating VM keystrokes using the vSphere API & PowerCLIhttps://williamlam.com/2017/09/automating-vm-keystrokes-using-the-vsphere-api-powercli.html
помогает отправить пару строк в VM
Есть еще методы с использованием старого доброго Powershell – Send Keystrokes/Text to a VM through the Host OS
http://justanotheritblog.co.uk/send-keystrokestext-to-a-vm-through-the-host-os/
Typing text on a virtual machine keyboard via PowerShell CIM Cmdlets
http://justanotheritblog.co.uk/send-keystrokestext-to-a-vm-through-the-host-os/
Is there any way to type the clipboard to the guest in Vmware
https://superuser.com/questions/1325855/is-there-any-way-to-type-the-clipboard-to-the-guest-in-vmware
Simulating mouse/keyboard events to Hyper-V virtual machine
https://stackoverflow.com/questions/44761996/simulating-mouse-keyboard-events-to-hyper-v-virtual-machine
Такие функции есть и в keepass - https://keepass.info/help/base/autotype.html
Можно имитировать нажатия на клавиатуре – см . VMKeystrokes.ps1
https://github.com/lamw/vmware-scripts/blob/master/powershell/VMKeystrokes.ps1
There's a vSphere API that allows you to remotely send keystrokes (same behavior/experience if you were to do that manually by hand via the VM Console). Please see https://www.virtuallyghetto.com/2017/09/automating-vm-keystrokes-using-the-vsphere-api-powercli.html for more details
https://www.reddit.com/r/vmware/comments/7jvyms/can_you_programmatically_send_keyboard/
Можно использовать менеджер паролей - Using a password manager with vSphere
https://communities.vmware.com/t5/Automation-Tools-Discussions/Using-a-password-manager-with-vSphere/td-p/907245
ну и, наконец то, ради чего все это затевалось – взято тут https://github.com/jlouros/PowerShell-toolbox/blob/master/Misc/Automate%20Windows%20Security%20prompt%20input/Run-RemoteDesktop.ps1
Пример переписан для использования блокнота.
# import required assemblies
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
Function FindWindow([string]$windowName, [int]$retries = 5, [int]$sleepInterval = 1000) {
[int]$currentTry = 0;
[bool]$windowFound = $false;
Do {
$currentTry++;
Start-Sleep -Milliseconds $sleepInterval
Try {
[Microsoft.VisualBasic.Interaction]::AppActivate($windowName)
$windowFound = $true;
} Catch {
Write-Host " [$currentTry out of $retries] failed to find Window with title '$windowName'" -ForegroundColor Yellow
$windowFound = $false;
}
} While ($currentTry -lt $retries -and $windowFound -eq $false)
return $windowFound;
}
if(FindWindow("Notepad")) {
Start-Sleep -Milliseconds 500
[System.Windows.Forms.SendKeys]::SendWait('Password123{ENTER}')
}И наконец в наиболее примитивной форме – отправка текста в любое текстовое поле, в том числе vmware VMRC add-type -AssemblyName System.Windows.Forms
start-sleep -Milliseconds 4000
# $text = $textbox1.text #assuming your text box is $textbox1
$text = 'Example123456'
# [System.Windows.Forms.SendKeys]::SendWait("$($text){TAB}")
[System.Windows.Forms.SendKeys]::SendWait("$($text)")
Взято тут https://www.reddit.com/r/PowerShell/comments/3tkmwn/how_to_pass_credentials_into_running_application/