arkane-systems / mousejiggler

Mouse Jiggler is a very simple piece of software whose sole function is to "fake" mouse input to Windows, and jiggle the mouse pointer back and forth.
Microsoft Public License
1.06k stars 179 forks source link

Access Denied (different circumstance) #11

Closed Cthulzilla closed 4 years ago

Cthulzilla commented 5 years ago

I'm not sure if this is related to the "Access Denied" issue that is closed.

I am getting this error on both a Windows 7 machine and a Windows 10 machine.

I am accessing these machines via Remote Desktop. I was trying to use the MouseJiggler to prevent timeout.

The MouseJiggler runs fine on the Remote Desktop session, until I minimize the session window. I get the error below, for the Windows 7. The Windows 10 machine throws nearly the same error (some version numbers are a little off), but since it's happening to both machines, so I am assuming that it has nothing to do with the OS version, bu with the circumstance of the Remote Desktop sessions.

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

** Exception Text ** System.ComponentModel.Win32Exception (0x80004005): Access is denied at ArkaneSystems.MouseJiggle.Jiggler.Jiggle(Int32 dx, Int32 dy) at ArkaneSystems.MouseJiggle.MainForm.jiggleTimer_Tick(Object sender, EventArgs e) at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

** Loaded Assemblies ** mscorlib Assembly Version: 4.0.0.0 Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll

MouseJiggle Assembly Version: 1.7.5.0 Win32 Version: 1.7.5 CodeBase: file:///C:/Users/clipinski/Desktop/mouse-jiggler-1.2/MouseJiggle.exe

System.Windows.Forms Assembly Version: 4.0.0.0 Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

System Assembly Version: 4.0.0.0 Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll

System.Drawing Assembly Version: 4.0.0.0 Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

System.Configuration Assembly Version: 4.0.0.0 Win32 Version: 4.7.3062.0 built by: NET472REL1 CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll

System.Core Assembly Version: 4.0.0.0 Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll

System.Xml Assembly Version: 4.0.0.0 Win32 Version: 4.7.3190.0 built by: NET472REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll

** JIT Debugging ** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.

For example:

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.

guban commented 5 years ago

As a workaround, these exceptions can be silenced by wrapping the entire body of public static void Jiggle(int dx, int dy) with try/catch(Exception).

vinaykapadia commented 4 years ago

Could not reproduce.

Steps:

  1. Connect to Windows 10 computer via Remote Desktop
  2. Run MouseJiggler
  3. Enable jiggling
  4. Minimize Remote Desktop window
  5. Restore Remote Desktop window

No error occurs, and mouse continues to be jiggled after restoring window.

Should this be kept open, or closed? The error doesn't pop up, but I don't think the mouse is truly being jiggled while Remote Desktop is minimized.

guban commented 4 years ago

The main issue is that mouse jiggling for sure does not happen after the program crashes due to exception. Eating that exception allows it to keep running and keep trying to jiggle whenever it is possible. I don't mind if sometimes jiggling is temporarily impossible. But I do mind having to acknowledge the exception message box and restart the program on a daily basis.

I would prefer to eat the exception that might emerge from the body of public static void Jiggle(int dx, int dy), even if we don't know (and don't have time to find out) when and why those exceptions might emerge. Eating them and continuing to work is better than crashing.

vinaykapadia commented 4 years ago

That's what I'm saying. It is eating the exception. The current code just writes a debug log then continues whenever it hits the exception. Running it normally, you won't notice anything. It will just stop jiggling when minimized, then start back up when restored.

vinaykapadia commented 4 years ago

Technically it's not even an exception. Before, it was saying if the send input command returns an error code, throw. That was the exception you were seeing. Now it's saying that if the send input command returns an error code, log it and move on.

guban commented 4 years ago

Great! Thank you for clarification! As exceptions are eaten, I'm perfectly fine with closing this ticket.

cerebrate commented 4 years ago

To note, here's the actual issue here:

MouseJiggler works by using SendInput to send mouse input to the input stream, upstream of the Windows input-idle timer. (The one you can peek at with GetLastInputInfo, and that screensavers, etc., key off.) However, the input stream exists in the context of a given session/window station, and when an RDP session becomes detached, it doesn't have an input stream; only sessions that are connected to input devices (directly or via RDP connections) have those.

Thus, you get the access denied error because you can't send input events to an input stream that doesn't exist.

But also, there's a problem with the whole approach here, inasmuch as that the RDP idle timeout is a completely separate timer than the input idle timer. You can illustrate this easily enough by setting the timeouts accordingly and observing that screensavers, etc., are perfectly happy to kick in inside an RDP session if the input idle timer is shorter than the RDP idle-connection timeout.

If you want to stop the RDP session from dropping when it idles, you need to run MouseJiggler on the machine you're connecting from, not the remote machine, and position the cursor over the Remote Desktop window. This will inject mouse events in such a location that Remote Desktop will transmit them to the remote machine, thus keeping the connection alive. Unfortunately, you can't do this with the Remote Desktop window minimized.

(You could probably achieve that by posting appropriate window messages to the Remote Desktop window rather than using SendInput, but that's both speculative and out of scope for this project.)