I am try to simulate mouse event on Win7, and my application using an open source project "Windows Input Simulator" on website http://inputsimulator.codeplex.com/ which internally use codes below to simulate mouse event:
My application runs perfectly when I debug it with Visual Studio 2010. The left button click event, right button click event and mouse move event are ok. But the click events not send when I start my application from Explorer by double click the .exe application excutable file. Only the mouse move event is OK, if I try to simulate left button click or right click, my application will receive an exception and exit.
I have found the exception is throw by codes below:
That says UIPI blocked the SendInput(...). So I Google this topic, and get some advises.
1) Add uiAccess="true" to my application's manifest
2) Create a test certificate and add this certificate to local machine Trusted Root Certification Authorities certificate store and the Trusted Publishers certificate store.
3) Sign my application with previous digital signature
I think I have done all things to satisfy UIPI requirements, but the problem still not solve after I start my application and agree the UAC prompt. Only mouse move event is ok.
PS: if I don't sign my application with test certificate and only add "requestedExecutionLevel" with uiAccess="true" in manifest, application will not start and Windows show a dialog with message "A referral was returned from the server.". If I signed my application with test certificate, UAC will work when I start my application. The application will work until I call SendInput to simulate click event and then exception threw.
I have read the requirements about "Interface Privilege Isolation (UIPI) and integrity" at http://msdn.microsoft.com/en-us/library/bb625963.aspx, but after doing all this, still not work.
Any one can help me about this?
[DllImport("user32.dll", SetLastError = true)]
public static extern UInt32 SendInput(UInt32 numberOfInputs, INPUT[] inputs, Int32 sizeOfInputStructure);
My application runs perfectly when I debug it with Visual Studio 2010. The left button click event, right button click event and mouse move event are ok. But the click events not send when I start my application from Explorer by double click the .exe application excutable file. Only the mouse move event is OK, if I try to simulate left button click or right click, my application will receive an exception and exit.
I have found the exception is throw by codes below:
public void DispatchInput(INPUT[] inputs) { if (inputs == null) throw new ArgumentNullException("inputs"); if (inputs.Length == 0) throw new ArgumentException("The input array was empty", "inputs"); var successful = NativeMethods.SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof (INPUT))); if (successful != inputs.Length) throw new Exception("Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information."); }
That says UIPI blocked the SendInput(...). So I Google this topic, and get some advises.
1) Add uiAccess="true" to my application's manifest
<requestedExecutionLevel level="requireAdministrator" uiAccess="true" />
2) Create a test certificate and add this certificate to local machine Trusted Root Certification Authorities certificate store and the Trusted Publishers certificate store.
MakeCert -r -pe -ss PrivateCertStore -n "CN=Test Certificate - For Internal Use Only" testcert.cer CertMgr.exe /add testcert.cer /s /r localMachine root CertMgr.exe /add testcert.cer /s /r localMachine trustedpublisher
3) Sign my application with previous digital signature
SignTool sign /v /s PrivateCertStore /n "Test Certificate - For Internal Use Only" /t http://timestamp.verisign.com/scripts/timestamp.dll MyApplication.exe4) Install my application to "C:\Program Files" folder which is one of the secure locations on my computer.
I think I have done all things to satisfy UIPI requirements, but the problem still not solve after I start my application and agree the UAC prompt. Only mouse move event is ok.
PS: if I don't sign my application with test certificate and only add "requestedExecutionLevel" with uiAccess="true" in manifest, application will not start and Windows show a dialog with message "A referral was returned from the server.". If I signed my application with test certificate, UAC will work when I start my application. The application will work until I call SendInput to simulate click event and then exception threw.
I have read the requirements about "Interface Privilege Isolation (UIPI) and integrity" at http://msdn.microsoft.com/en-us/library/bb625963.aspx, but after doing all this, still not work.
Any one can help me about this?