[SOLVED] Autotype from clipboard in remote RDP session
[SOLVED] Autotype from clipboard in remote RDP session
I have a large script code that i need to autotype in a (webbased) Remote Desktop session. But because the script Tabs someone right before start of a text an extra nummer is typed, e.g.
Start script
5Get-command
2Get-AdUser-identity Dummysusr1
Write-output “This is a test”
Get-AdGroups -name Dummy
Invoke-command -script a-$scriptblock
so why this happends? I try inserting some delay in autohotkey script but so far no success. of course i do not want to remove the tab in each script i’m trying to paste.
The remote session prohibit Paste clipboard thats why i need to make it type every character.
Start script
5Get-command
2Get-AdUser-identity Dummysusr1
Write-output “This is a test”
Get-AdGroups -name Dummy
Invoke-command -script a-$scriptblock
so why this happends? I try inserting some delay in autohotkey script but so far no success. of course i do not want to remove the tab in each script i’m trying to paste.
The remote session prohibit Paste clipboard thats why i need to make it type every character.
Last edited by Topsport on 27 Nov 2022, 01:15, edited 1 time in total.
Re: Autotype from clipboard in remote RDP session
Welcome to this AutoHotkey forum!
You can post your AutoHotkey script in a reply below.
You can post your AutoHotkey script in a reply below.
Re: Autotype from clipboard in remote RDP session
Code: Select all
setkeydelay 300
return
return
!y::Send {Text}%Clipboard%
return
Re: Autotype from clipboard in remote RDP session
This worked in Notepad. Is it what you are trying to achieve?
Code: Select all
Clipboard =
(
Start script
Get-command
Get-AdUser-identity Dummysusr1
Write-output "This is a test"
Get-AdGroups -name Dummy
Invoke-command -script a-$scriptblock
)
!y::SendInput {Text}%Clipboard%
Re: Autotype from clipboard in remote RDP session
This work in Windows Notepad for me also. But i want to make autotype within a RDP session as explained in my start post.
Re: Autotype from clipboard in remote RDP session
In Notepad locally works for me also. But Notepad in a remote RDP session not.
I have recorded a short session but do not know how to upload the video. Its an gif file by the way.
I have recorded a short session but do not know how to upload the video. Its an gif file by the way.
Re: Autotype from clipboard in remote RDP session
When you run the script, activate RDP, and trigger the hotkey, you see something different? If so, I am not sure how to resolve, but some of the other posts about RDP may help you. Sorry I am not more helpful.
Re: Autotype from clipboard in remote RDP session
I think because of delays in RDP session. Autohotkey tries to rapidly type a lot of info faster than any human can do. But so yeah, local notepad works flawlessly it not Autohotkey fault. I'll try to find more post if someone else has a workaround for this issue. I really need autotype to work in a remote session because my company does not allow copy+paste.
Thanks for the help
Thanks for the help
Re: Autotype from clipboard in remote RDP session
Worth a try:
Code: Select all
!y::
SetKeyDelay, 25, 25
Send {Text}%Clipboard%
Return
Re: Autotype from clipboard in remote RDP session
I tried your code and a lot of codes from others at autohotkey forum but none are consisent. E.g. my first few lines.....
************************* result in this:
Code: Select all
# https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/march/powershell-managing-an-outlook-mailbox-with-powershell
Write-Host "**** This is JIT_GetFromOutlookItem-in-SubFolder.ps1" *** -ForegroundColor DarkRed -BackgroundColor Green
Write-Warning "Wait for previous Outlook process to close..."
Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue | Stop-Process -Force #!
Do { Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ; start-sleep 3 }
#While ( $Proc = (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
While ( (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
************************* result in this:
Code: Select all
://docs.microsoft.com/en-aging* Thirors tion ESS SPACE." }
Wr ) )
{ Write-Output "USELESS SPACE." }
Wr ) )
{ Write-Output "USELESS SPACE." }
Wr ) )
{ Write-Output "USELESS SPACE." }
Wr ) )
{ Write-Output "USELESS SPACE." }
Write-Host "No process Outlook.exe was found. " {#}-NoNewline ; Get-Datespace$mapi = $OutlookApplication.Go the mapi namespace$mapi = $OutlookApplication.GetNamespace("Mapi");
Re: Autotype from clipboard in remote RDP session
I wrote a tool for remote working in an RDP session, and Mikey is right: SetKeyDelay is key. I usually have delay=1, duration=0
The other thing is that if you use the RDP client, Windows key combinations are being executed locally. You can set this up in the RDP client GUI to be sent to the remote session, or edit the .rdp config file and add this line:
keyboardhook:i:0
That makes sure that even in a fullscreen RDP session, the keys are being sent to the RDP session.
My employer is very paranoid, so even copy/paste etc has been disabled. I also use my tool to get around that
To be clear: my tool runs on my local machine.
If you need more info: please shoot me a message!
The other thing is that if you use the RDP client, Windows key combinations are being executed locally. You can set this up in the RDP client GUI to be sent to the remote session, or edit the .rdp config file and add this line:
keyboardhook:i:0
That makes sure that even in a fullscreen RDP session, the keys are being sent to the RDP session.
My employer is very paranoid, so even copy/paste etc has been disabled. I also use my tool to get around that
To be clear: my tool runs on my local machine.
If you need more info: please shoot me a message!
Re: Autotype from clipboard in remote RDP session
I wrote a tool for remote working in an RDP session, and @Mikey is right: SetKeyDelay is key. I usually have delay=1, duration=0
The other thing is that if you use the RDP client, Windows key combinations are being executed locally. You can set this up in the RDP client GUI to be sent to the remote session, or edit the .rdp config file and add this line:
keyboardhook:i:0
That makes sure that even in a fullscreen RDP session, the keys are being sent to the RDP session.
My employer is very paranoid, so even copy/paste etc has been disabled. I also use my tool to get around that
To be clear: my tool runs on my local machine.
If you need more info: please shoot me a message!
(PS: Dutch?)
The other thing is that if you use the RDP client, Windows key combinations are being executed locally. You can set this up in the RDP client GUI to be sent to the remote session, or edit the .rdp config file and add this line:
keyboardhook:i:0
That makes sure that even in a fullscreen RDP session, the keys are being sent to the RDP session.
My employer is very paranoid, so even copy/paste etc has been disabled. I also use my tool to get around that
To be clear: my tool runs on my local machine.
If you need more info: please shoot me a message!
(PS: Dutch?)
Re: Autotype from clipboard in remote RDP session
Setting keyboardhook:i:0 in RDP-file seems to make a little better, but not yet there.
The # for remarks and <# #> which we use in Powershell scripts a lot are now typed correctly
The first 50 lines or so of the script are correctly typed (though each line has an extra hard returns in it which the original script does not have)
And somewhere lines 200 it more like it trying to type in Greeks:
And yes, i face same problem as you do and i speak Dutch also
The # for remarks and <# #> which we use in Powershell scripts a lot are now typed correctly
The first 50 lines or so of the script are correctly typed (though each line has an extra hard returns in it which the original script does not have)
But after lines 50, things get bit out messy, there are now a lot of spaces added before the actual text beeing typed.o { Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ; start-sleep 3 }
#While ( $Proc = (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
While ( (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
{ Write-Output ÜSELESS SPACE."}
Write-Host "No process Outlook.exe was found. "#-NoNewline ; Get-Date -UFormat %Y-%m-%d_%H:%M_uur
# Instantiate a new Outlook object
$OutlookApplication = New-Object -ComObject Öutlook.Application";
# Map to the mapi namespace
$mapi = $OutlookApplication.GetNamespace("Mapi");
Code: Select all
else
{
Write-Host "Result after second try to find '$TodayDate'...."-NoNewline
$TimeinBody = $VerifyBody | Select-String "$TodayDate"
if ($TimeinBody) {Write-Host "Success!"}
else {Write-Output No $TodayDate found - abort script;BREAK}
}
I'm now bit closer to the solution...rpung-catupgr_EI t $+EgoT(C sSaeis PEA> LectFREM(older.Fu
And yes, i face same problem as you do and i speak Dutch also
Re: Autotype from clipboard in remote RDP session
Make sure you save the script as UTF-8 BOM.
Use SendEvent instead of Send, set SetKeyDelay 10,10
Veel plezier
Use SendEvent instead of Send, set SetKeyDelay 10,10
Veel plezier
Re: Autotype from clipboard in remote RDP session
I have implemented all suggestions and besides adjusting RDP-file, Autohotkey code looks like this
It is about 97% good. E and A as Ë Ä. As long as it is not 100% i will have a hard time to read the code over again autohotkey finishes...
And if that it is fixed, next i need to try to fix same problem in a webbased-RDP session. This is the end goal, because in future direct RDP to remote server from my local machine will be prohibited.
By the way, when Autohotkey finishes, my local keyboard response intermittently. CTRL+ALT+DEL resolve the problem. Anyone knows why this happends?
Code: Select all
!y::
SetKeyDelay, 10, 10
SendEvent {Raw}%Clipboard%
Return
And if that it is fixed, next i need to try to fix same problem in a webbased-RDP session. This is the end goal, because in future direct RDP to remote server from my local machine will be prohibited.
By the way, when Autohotkey finishes, my local keyboard response intermittently. CTRL+ALT+DEL resolve the problem. Anyone knows why this happends?
Re: Autotype from clipboard in remote RDP session
Without the code+the clipboard contents there is not much more I can do....
Re: Autotype from clipboard in remote RDP session
I spoke too soon. I did not convert to UTF-8 correctly. Now i have and its nearly perfect 99% correct. And for each new line, there is an extra hard returns somehow. But that's ok, i only need this code once as i don't want to save the code on the server.
Now my next project is to make it work in an webbased-RDP session also. And since i can't adust RDP-file e.g. in this case, it gonna be harder to get it work. To be continued.
Now my next project is to make it work in an webbased-RDP session also. And since i can't adust RDP-file e.g. in this case, it gonna be harder to get it work. To be continued.
Re: Autotype from clipboard in remote RDP session
It's possible that carriage returns are the "extras". You could try deleting them.
Re: Autotype from clipboard in remote RDP session
It depends what kind of web-based RDP it is?Topsport wrote: ↑24 Nov 2022, 15:39I spoke too soon. I did not convert to UTF-8 correctly. Now i have and its nearly perfect 99% correct. And for each new line, there is an extra hard returns somehow. But that's ok, i only need this code once as i don't want to save the code on the server.
Now my next project is to make it work in an webbased-RDP session also. And since i can't adust RDP-file e.g. in this case, it gonna be harder to get it work. To be continued.
And generally, UTF-8 BOM is to be preferred over UTF-8
Re: Autotype from clipboard in remote RDP session
@pervect66 UTF-8 with BOM - got it.
Background: one of my customers will be using Cyberark (PAM) and restrict us to using webbased-RDP to access their servers. And they do not allow copy+paste text from my local workstatoin to the remote server. I have source codes from a lot of different places where normally i can access from my own computer without problem. But when i logon the the remote server, it is actually a shared session. I dont want to leave my cookies for others to grab. And i certainly do not want to leave my credentials in the profile because the next time another person automatically get my session/profile and well the rest you know.
And you guys were asking about my original code, here is a snippet:
My original code looks like this
After pasting in a RDP-session it looks like this:
and the WEB-RDP version looks like this:
So appearently it has trouble when a $ sign is used in in the middel of the script. the \ ) ' and so on.
Background: one of my customers will be using Cyberark (PAM) and restrict us to using webbased-RDP to access their servers. And they do not allow copy+paste text from my local workstatoin to the remote server. I have source codes from a lot of different places where normally i can access from my own computer without problem. But when i logon the the remote server, it is actually a shared session. I dont want to leave my cookies for others to grab. And i certainly do not want to leave my credentials in the profile because the next time another person automatically get my session/profile and well the rest you know.
And you guys were asking about my original code, here is a snippet:
My original code looks like this
Code: Select all
Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue | Stop-Process -Force #!
Do { Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ; start-sleep 3 }
While ( (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
{ Write-Output "USELESS SPACE." }
Write-Host "No process Outlook.exe was found. "
# Instantiate a new Outlook object
$OutlookApplication = New-Object -ComObject "Outlook.Application";
# Map to the mapi namespace
$mapi = $OutlookApplication.GetNamespace("Mapi");
Write-Host "Wait 5 secs !" -ForegroundColor Red ; Start-Sleep 5 #* 2021-12-24
$TargetMailbox = $mapi.Folders | Where-Object {$_.FolderPath -eq "\\[email protected]" }
$SelectFolder = $TargetMailbox.Folders.item(2).Folders.item(4).Folders.item('myItem')
$SelectFolder | Select FullFolderPath -ExpandProperty FullFolderPath
$Jit_file = 'C:\Users\myname'+'\export.TXT'
$Jit_temp = 'C:\Users\myname'+'\TEMP_file.TXT'
$TodayDate = Get-Date -UFormat "%m/%d/%Y"
Code: Select all
Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue | Stop-Process -Force #!
Do { Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ; start-sleep 3 }
While ( (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
{ Write-Output "USELESS SPACE." }
Write-Host "No process Outlook.exe was found. "
# Instantiate a new Outlook object
$OutlookApplication = New-Object -ComObject "Outlook.Application";
# Map to the mapi namespace
$mapi = $OutlookApplication.GetNamespace("Mapi");
Write-Host "Wait 5 secs !" -ForegroundColor Red ; Start-Sleep 5 #* 2021-12-24
$TargetMailbox = $mapi.Folders | Where-Object {$_.FolderPath -eq "\\[email protected]" }
$SelectFolder = $TargetMailbox.Folders.item(2).Folders.item(4).Folders.item('myItem')
$SelectFolder | Select FullFolderPath -ExpandProperty FullFolderPath
$Jit_file = 'C:\Users\myname'+'\export.TXT'
$Jit_temp = 'C:\Users\myname'+'\TEMP_file.TXT'
$TodayDate = Get-Date -UFormat "%m/%d/%Y"
Code: Select all
Write-Warning "ait for previous Outlook process to close..."
Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue | Stop-Process -Force #!
Do { Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ; start-sleep 3 }
While ( (Get-Process -Name OUTLOOK -ErrorAction SilentlyContinue ) )
{ Write-Output "USELESS SPACE." }
Write-Host "No process Outlook.exe was found. "
# Instantiate a new Outlook object
$OutlookApplication = New-Object -ComObject "Outlook.Application";
# Map to the mapi namespace
$mapi = $OutlookApplication.GetNamespace("api";
Write-Host "Wait 5 secs !" -ForegroundColor Red ; Start-Sleep 5 #* 2021-12-24
$TargetMailbox = 4mapi.Folders | Where-Object {-4_.FolderPath -eq "\[email protected]" }
$SelectFolder = 4TargetMailbox.Folders.item(2).Folders.item(4).Folders.item('yItem')
$SelectFolder | Select FullFolderPath -ExpandProperty FullFolderPath
$Jit_file = '"Ç:\Users\myname'+'\export.TXT'
$Jit_temp = 'Ç:\Users\myname'+'\TEMP_file.TXT'
$TodayDate = Get-Date -UFormat 'm/%d/%Y"