Selenium hover action with IE doesn't work if RDP never connected to Jenkins slaves - windows

We create a bunch of windows Jenkins slaves on Amazon EC2, and make them autologon after they are provisioned.
Once logged on, we use connect the slaves back to master via java web start by execute "ps", with all of this, we can run selenium perfectly with IE except we can't get a higher resolution than 1024*768. We got screenshot, we can see the browser running on the GUI if connected with RDP, just like running on a physical PC.
But a flaw is that, the hover action doesn't work on IE unless we connect to the slave through remote desktop one time before the test starts, just connect once, nothing else, I can even close the RDP session.
I guess something triggered by the RDP connection, just can't figure out what is that.

You can try to adapt your test scripts to have them make an RDP connection before you start your tests, if there is none. This is the code I used for one of our projects to ensure an RDP connection is active:
REM check if user has an RDP session. Will store the session ID of the user in the SESSION variable
call :getsession computername username SESSION
if "%SESSION%" EQU "" (
REM initiate an RDP connection to 'computername', wait, and disconnect by killing the process
mstsc.exe /v:computername & ping -n 5 1.1.1.1 & taskkill /F /IM mstsc.exe
)
REM check again the session
call :getsession computername user SESSION
if %SESSION% NEQ "" (
echo start your tests
)
:getsession
for /F "tokens=1,2,3,4" %%i in ('query session /SERVER:%1 ^| findstr %2') do if %%j EQU %2 (SET %3=%%k) else (SET %3=%%j)
goto :eof
Note that the automatic connection will only be made if you save credentials on the machine from which you start the remote desktop:
cmdkey /generic:computername /user:rdp_username /pass:rdp_password
After executing this once the mstsc.exe will be able to connect to the machine without user interaction.

Related

Could not connect sessionID 1 to sessionname console, Error code 7045

I have created a self-hosted agent machine in an interactive mode (Windows 10) to run the unit tests. To disconnect from the Remote Desktop Connections while Running Automated Tests I am executing the below command from a command-line task (from Azure DevOps). This is working fine when the user logged into the agent machine. But getting an error If there is no user logged into that agent machine.
Is this expected behavior? Can we bypass this?
%windir%\System32\tscon.exe 1 /dest:console
Error:
Could not connect sessionID 1 to sessionname console, Error code 7045
Error [7045]: The requested session access is denied.
I tried with the other options as well like creating a batch file with the below code and executing it while running the pipeline.
This one is also giving the same error
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
Command query user %USERNAME% will return the session even if the user is not currently logged in.
You can run command query user ^| find "Active" to query the active login users only.
See below:
for /f "tokens=3" %%s in ('query user ^| find "Active" ') do (
%windir%\System32\tscon.exe %%s /dest:console
)

Stuck in cmd script loop

I'm using a script that, upon logging in, loads Remote Desktop Protocol (RDP) and pushes the user to a Virtual Desktop Environment (VDI), along with their credentials. The script does not allow the next command 'Shutdown /l' to run until it is finished running.
The problem I'm having is that once in the VDI, RDP tries to load up again. How do I prevent this from happening? Thank you in advanced.
start /wait \\ph-vda\C$\VDI_Users_RDP\%username%.rdp /multimon /noConsentPrompt
Shutdown /l
I think what you're describing is that the same script is running when the user logs in, even when they log into the VDI. You don't want the script to run in the VDI. If that's right, here's one idea.
#echo off
if exist "%userprofile%\in_vdi" goto :eof
type nul >"%userprofile%\in_vdi"
start /wait \\ph-vda\C$\VDI_Users_RDP\%username%.rdp /multimon /noConsentPrompt
del "%userprofile%\in_vdi"
Shutdown /l

Windows remote connection looping MSTSC

I built a program that will connect to a list of remote machines through Windows. The only issue I'm having is that after it connects to the Remote Desktop the Windows command prompt is in a "frozen state" until I disconnect from the remote. At the point it loops the code back where you can select another machine.
I want it to be able to loop back without having to disconnect so I can connect to multiple machines.
Here is my code:
:deployCode
cmdkey /generic:"SERVERNAME" /user:"user" /pass:"password"
mstsc /v:"SERVERNAME"
cls
goto :machinelist
It doesn't step through the cls clear command and go back to my machine list (goto :machinelist) until I close the server I connect to.
I tried using "&" to join the two commands but that did not work.
i.e mstsc /v:"SERVERNAME" & goto :machinelist
How can I step to cls and goto :machinelist without having to disconnect after mstsc?
mstsc does not return if within a script. Prefix by "start" it will work (just tested here)
:deployCode
cmdkey /generic:"SERVERNAME" /user:"user" /pass:"password"
start mstsc /v:"SERVERNAME"
cls
goto :machinelist

Automatically connect to wifi network when no internet detected

EDIT: Found a fix without using Task Scheduler.
#echo off
:loop
set addresses=192.168.1.1
for %%a in (%addresses%) do ping %%a -n 1 > nul || netsh wlan add profile filename=C:\User\path\to\wireless\xml\profile.xml user=all
timeout /t 5
goto :loop
it repeats every 5 seconds
I am halfway there but have become stuck. I already have a batch file that can connect the laptop back to the network when manually run but wanted it to run when no internet is detected. So I went ahead and bound it to Task Scheduler with the Trigger being the "Microsoft-Windows-NetworkProfile/Operational" with an ID of 10001 (which is the Disconnect ID) but have no luck with it.
I believe it only triggers when it manually gets disconnected from the internet, not when the wireless card drops the signal on its' own. Any ideas as to what I can do?
OS: Windows 8.1
Wireless Interface: Cable Matters AC600 Dual Band Wireless dongle (doesn't allow Auto Connect to SSID and keeps dropping the connection for unknown reasons)
Found a solution!
#echo off
:loop
set addresses=192.168.1.1
for %%a in (%addresses%) do ping %%a -n 1 > nul || netsh wlan add profile filename=C:\User\path\to\wireless\xml\profile.xml user=all
timeout /t 5
goto :loop
What this does is ping an address once (in this case an internal address so I don't get DDoS threats from sites) and if it responds back with an error, it will load a wifi profile.
To get the profile first you will need to type
netsh wlan show profiles
to see what profiles you have (it only loads profiles for the wireless card currently in use). After seeing the names of the profiles you can download the profile by typing
netsh wlan export profile name=[profile name]
I believe it will save to the desktop and from there you can change the code listed at the top of this comment to match the filepath of the xml file to suit your needs.
Cheers!
What about a batch script that regularly performs pings and you inspect the result?
ping some.host > pinged.txt
find "some string which occurs if the network went down" pinged.txt
If %errorlevel% is 0 than the string was found and the connection went down.

RDP kill a program specifically

I know that you can use tskill to kill processes in a batch file, among other things, but...I have users that remote desktop into a Windows Server 2003 box to run a Microsoft Access program. Occasionally, if someone RDPs in the Access Program will already be open (meaning they have entered someone else's session). This means they are using someone else's Access log on and I have certain forms that record that info and use it to autoemail people reminders. Since everyone uses the same program only on the server, I have all rdp login as the same user. When I tried to do a tskill batch program for msaccess.exe, it killed the Access of everyone logged in--doh! I can't see making everyone log in when they rdp in, so I am hoping the answer isn't make a log in for everyone in the enterprise and then get to their computers to change their save rdp log on information. Is there a way to run something like tskill for ONLY the current session? The batch command I was using is taskkill /f /im msaccess.exe . Thank you in advance for your time and your replies.
I believe this script will do the trick.
:: Find the current session.
FOR /F "tokens=3 delims= " %%F IN ('query session %USERNAME%') DO SET SESSIONID=%%F
:: Kill all msaccess processes *in this specific session*.
taskkill /FI "SESSION eq %SESSIONID%" /IM msaccess.exe /F

Resources