Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep Remote Desktop Session alive / preven RDP timeout 1

Status
Not open for further replies.

lameid

Programmer
Jan 31, 2001
4,212
US
Long story short, I have a small Access application started on a Remote Desktop Connection that reads data on the client side of the connection and puts it in a table on the server side and the server (Windows 2008 R2) is domainless with all users set to timeout after an hour of inactivity which as I understand it makes it impossible to configure a different user timeout.

In short I really need to prevent the timeout in code. The code that is running is running on in the timer event of a startup form. I thought I had a sendkeys command keeping the session alive but alas I think I must have done something stupid like test with an admin account that does not timeout.

I am off to dig on the internet... with a cold...

 
I did not use all the code but kept it in case it would prove useful later.

Reportedly calling MouseJiggle defined below seems to keep the session alive... On the other hand, it also reportedly stopped working after an hour so I need to play some more to find out for sure.

Code:
Option Compare Database
Option Explicit

'Digested from [URL unfurl="true"]http://wellsr.com/vba/2015/excel/vba-mouse-move-and-mouse-click-macro/[/URL]

'Declare mouse events

'SetCursorPos sets the mouse position relative to the top left corner which is 0,0 in pixels.
#If Win64 Then
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#Else
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As LongPtr
#End If

#If Win64 Then
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
#Else
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
#End If

Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub LeftClick()
    'Left click is pushing the left mouse button down and releasing it by using up
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 'Push down
    Sleep 50 '50 millisecond pause
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0   'Release
End Sub

Public Sub RightClick()
    'Right click is pushing the Right mouse button down and releasing it by using up
    mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 'Push down
    Sleep 50 '50 millisecond pause
    mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 'Release
End Sub

Public Sub MouseJiggle()
    SetCursorPos 0, 0
    Sleep 50
    SetCursorPos 10, 0
    Sleep 50
    SetCursorPos 10, 10
    Sleep 50
    SetCursorPos 0, 10
End Sub
 
>calling MouseJiggle defined below seems to keep the session alive

I'd be surprised, to be honest
 
That does not seem to fix it when I test personally...

I did create the below key and set it to 2. That should allow the session to allow active for such automated updates.

HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\RemoteDesktop_SuppressWhenMinimized
REG_DWORD

Anyone have the silver bullet for this one or at least some other though on simulated input that may help?
 
No fixes...

Additional reading suggests that the only solution may involve sending input to the Remote Desktop Application on the client machine.

When I ask someone with more experience in such things than me, I got the answer give up.

So unless someone has a great idea, I am calling it. I think the only real solution that has merit is on the server side and involves adding a domain controller to the mix in order to support group policy so timeouts are not a global setting. I only mention this as the possible alternative to a code solution.
 
> may involve sending input to the Remote Desktop Application

Doesn't seem to work. The input idle does not seem to be how RDP times things
 
On the one hand I think, good job Microsoft that is secure. On the other hand I think, shame on you Microsoft requiring a domain to configure this for different users/groups. But other reading I have done suggest standalone RDS has gone the way of the Dodo in versions past Win Server 2008 R2... I smell license fees.

Of course I am assuming the server can't handle AD too... On the other hand; if it doesn't work, there really is not an alternative other than adding hardware / hosted VM to the mix.

Failing the Access workaround, that is probably far enough off topic to go.

Thanks for having a look at the Remote Desktop Application.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top