Author Topic: SendkeysTo Issue  (Read 13871 times)

bettman

  • Newbie
  • *
  • Posts: 42
SendkeysTo Issue
« on: November 11, 2013, 10:07:17 am »
Greetings,

I am attempting to create a script using WinWaitExist and SendKeysto and am having a problem. If I run the script on Windows XP/7, it works great but doesn't function on Windows 8.1. From what I can tell, the script can "see" the window it's supposed to send the keys to but nothing happens. I've tried using SendkeysTo, SendKeysCHild and even Sendkey with no success. Is there something additional I need to do in my script for this to work on Windows 8.1?

ChuckC

  • Sr. Member
  • ****
  • Posts: 333
Re: SendkeysTo Issue
« Reply #1 on: November 11, 2013, 11:34:04 am »
Greetings,

I am attempting to create a script using WinWaitExist and SendKeysto and am having a problem. If I run the script on Windows XP/7, it works great but doesn't function on Windows 8.1. From what I can tell, the script can "see" the window it's supposed to send the keys to but nothing happens. I've tried using SendkeysTo, SendKeysCHild and even Sendkey with no success. Is there something additional I need to do in my script for this to work on Windows 8.1?


1)  Is UAC enabled or disabled on Windows 7 and Windows 8.1, respectively?

2)  If UAC is enabled, how were both the script process and the application process [that owns the target window] launched w/respect to elevation [e.g. "run as administrator]?

bettman

  • Newbie
  • *
  • Posts: 42
Re: SendkeysTo Issue
« Reply #2 on: November 11, 2013, 11:35:18 am »
UAC is disabled on both machines

td

  • Tech Support
  • *****
  • Posts: 3985
    • WinBatch
Re: SendkeysTo Issue
« Reply #3 on: November 12, 2013, 06:46:01 am »
Disabling UAC on Windows 8 or Windows 8.1 doesn't really disable it.  All it does is turn off the security elevation prompt. What that means is that if you are using an administrator group account, most applications are running with a restricted access token but WinBatch is executing with the full admin access token.  To test if UAC is the cause of your problem, change your script's file extension from ".wbt" to ".wbt_af" and then see if the  ".wbt_af" version has the same problem. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

bettman

  • Newbie
  • *
  • Posts: 42
Re: SendkeysTo Issue
« Reply #4 on: November 12, 2013, 08:39:32 am »
What does changing the file extension do? I am running compiled scripts (exe's) on the machines and not scripts from within Winbatch Studio.

ChuckC

  • Sr. Member
  • ****
  • Posts: 333
Re: SendkeysTo Issue
« Reply #5 on: November 12, 2013, 09:29:32 am »
What does changing the file extension do? I am running compiled scripts (exe's) on the machines and not scripts from within Winbatch Studio.

The different script file extensions are associated with different builds of the WIL Interpreter that have different manifests for UAC.  This allows you control the degree of elevation/escalation and UI protection that is required when executing your script directly through the interpreter.  However, when you compile a script, you can specify the same types of manifest options to be placed into the EXE file that the WinBatch+Compiler produces as output.

The whole reason for asking about UAC has to do with the situation where your script is running as a normal user or as a restricted administrator, while the window being targeted by the SendKey*() functions is owned by a process that is running elevated.  In such a situation, you will find that the UI protection of the elevated process prevents your script from sending simulated keystrokes to the specified window.


bettman

  • Newbie
  • *
  • Posts: 42
Re: SendkeysTo Issue
« Reply #6 on: November 12, 2013, 09:40:16 am »
Could you please tell me how I would set the UAC settings in the script such that the Sendkeys function will work?

td

  • Tech Support
  • *****
  • Posts: 3985
    • WinBatch
Re: SendkeysTo Issue
« Reply #7 on: November 12, 2013, 10:24:36 am »
The whole reason for asking about UAC has to do with the situation where your script is running as a normal user or as a restricted administrator, while the window being targeted by the SendKey*() functions is owned by a process that is running elevated.  In such a situation, you will find that the UI protection of the elevated process prevents your script from sending simulated keystrokes to the specified window.

As of Windows 8 attempting UI access from an elevated process to a standard or restricted administrator process can run afoul of UAC restrictions as well.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

ChuckC

  • Sr. Member
  • ****
  • Posts: 333
Re: SendkeysTo Issue
« Reply #8 on: November 12, 2013, 10:40:00 am »

As of Windows 8 attempting UI access from an elevated process to a standard or restricted administrator process can run afoul of UAC restrictions as well.


That's an unpleasant complication of things. 

td

  • Tech Support
  • *****
  • Posts: 3985
    • WinBatch
Re: SendkeysTo Issue
« Reply #9 on: November 12, 2013, 10:44:11 am »
Could you please tell me how I would set the UAC settings in the script such that the Sendkeys function will work?

You can change the UAC settings for compiled scripts by launching the Configuration Settings dialog form the 'Settings..." button in the compiler.  However, it is not possible to tell you exactly which of the UAC settings you should use because there are several different UAC related scenarios that could be causing the problem.  If fact, it is not even certain that UAC is the cause of your problem.  Using uncompiled scripts with several different extensions is a good way to quickly test the hypothesis.  Of course that approach doesn't work as well if you don't have a machine with both the targeted application and WinBatch installed.  In that case, you would need to compile with different UAC settings to see if UAC is the cause of the problem.

Here is tech. db article that explains the relationship between UAC settings and script file extensions.

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/Vista+Manifests~In~WinBatch~Explained.txt
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

bettman

  • Newbie
  • *
  • Posts: 42
Re: SendkeysTo Issue
« Reply #10 on: November 13, 2013, 04:43:54 am »
I tried something a little different by putting a Windows hotkey combination (Ctrl-Esc) into the script and it worked so it doesn't appear to be blocked. The dialog I'm attempting to send the keystrokes to appears to have the same title and process on Win7 and Win8. I've tried hardcoding the title of the dialog into a Sendkeysto statement and also using WinItemProdIC(ProdID, 0,1) to get the Title name with no success. Is there another way to send keystrokes to a process dialog?

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: SendkeysTo Issue
« Reply #11 on: November 13, 2013, 08:17:41 am »
At this point it might be helpful to see the failing code and the actual error. I recommend using DebugTrace. Simply add DebugTrace(@on,"trace.txt") to the beginning of the script and inside any UDF, run it until the error or completion, then inspect the resulting trace file for clues as to the problem

Feel free to post the trace file here ( removing any private info) if you need further assistance.
Deana F.
Technical Support
Wilson WindowWare Inc.

bettman

  • Newbie
  • *
  • Posts: 42
Re: SendkeysTo Issue
« Reply #12 on: November 13, 2013, 08:25:53 am »
Here is the code in question:

   list=tListProc()

   Lookfor = ItemlocateWild('msra*',List,@tab,1)
   ProcString=ItemExtract(Lookfor,List,@tab)
   ProcStringLen = StrLen(ProcString)
   ProcID=StrSub(ProcString,6,ProcStringLen)

   Title = WinItemProcID(ProcID,0,1)
   Winactivate(Title)
   Timedelay(2)
   SendKeysTo('%Title%~','{TAB 2}')
   Timedelay(2)
   SendKeysto('%Title%~','{Enter}')
   TimeDelay(2)

Thank you for your help.

bettman

  • Newbie
  • *
  • Posts: 42
Re: SendkeysTo Issue
« Reply #13 on: November 13, 2013, 09:03:32 am »
This is a dump of the debug trace file:


************************************************************

*** Debug Initialized ***

==============================
Wed 11/13/2013 12:01:11 PM
WinBatch 32 2013C
WIL DLL 6.13cmc
\\dtemgmt1p\upload\Scripts\RemoteAssistancePrompt.exe
Windows platform: NT, version: 6.2, build: 9200
ErrorMode: @OFF
Valid Code Signature: No
UAC Manifest Settings: level="asInvoker" uiAccess="false"
UAC Elevation Level: Admin Not Elevated
==============================

Platform="Unknown"
(16) VALUE STRING => "Unknown"

Timeout = 60
(16) VALUE INT => 60

If v=="2-5-1" ;"Windows XP"
(16) ELSE DO==>TRUE

AgentRunning = AppExist('msra.exe',1,120)
(688) VALUE INT => 1

If AgentRunning == @false
(688) ELSE DO==>TRUE

list=tListProc()
(750) VALUE STRING => "Idle|0   System|4   smss|316   csrss|404   csrss|464   wininit|472   winlogon|516   services|564   lsass|572   svchost|632   svchost|660   dwm|756   LogonUI|772   svchost|804   svchost|848   svchost|892   svchost|952   ClassicShellService|336   svchost|384   spoolsv|940   svchost|1040   ccSvcHst|1284   vmtoolsd|1388   TPAutoConnSvc|1760   svchost|1864   dllhost|1916   WmiPrvSE|1964   msdtc|2232   Smc|2600   unsecapp|2904   csrss|2148   winlogon|2864   dwm|3056   ClassicStartMenu|3192   TPAutoConnect|3224   conhost|3236   ccSvcHst|3276   rdpclip|3284   taskhostex|3296   explorer|3508   svchost|3780   SearchIndexer|3956   vmtoolsd|3212   svchost|3696   regedit|2652   cmd|1484   conhost|736   cmd|2108   conhost|1172   msra|1344   audiodg|3140   RemoteAssistancePrompt|3340"

Lookfor = ItemlocateWild('msra*',List,@tab,1)
(750) VALUE INT => 50

ProcString=ItemExtract(Lookfor,List,@tab)
(750) VALUE STRING => "msra|1344"

ProcStringLen = StrLen(ProcString)
(750) VALUE INT => 9

ProcID=StrSub(ProcString,6,ProcStringLen)
(750) VALUE STRING => "1344"

IntControl (35, 2000, 0, 0, 0)
(750) VALUE STRING => "25"

Title = WinItemProcID(ProcID,0,1)
(750) VALUE UNICODE => Windows Remote Assistance

SendKeysTo('Windows Remote Assistance~','{TAB 2}')
(2860) VALUE INT => 0

SendKeysto('Windows Remote Assistance~','{Enter}')
(4922) VALUE INT => 0

exit
(4922) VALUE INT => 0

--- Normal termination ---

;;;END OF JOB;;;

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: SendkeysTo Issue
« Reply #14 on: November 13, 2013, 09:50:00 am »
Ok. I see you are running a compiled script called RemoteAssistancePrompt.exe. The following DebugTrace  header indicates:
Code: [Select]
ErrorMode: @OFF
Valid Code Signature: No
UAC Manifest Settings: level="asInvoker" uiAccess="false"
UAC Elevation Level: Admin Not Elevated

First ErrorMode should only be turned OFF for a single line of code. Please see: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch+Two~Minute~Lecture~on~ErrorMode~No-Nos.txt. I recommend removing ErrorMode(@off) while debugging. Otherwise it can turn a five minute debugging session into a week long nightmare.

First try recompiling the script using the requireAdmin UAC manifest Setting. Test the newly compiled exe. Success?

If not successful...I see the code is not code signed and the UI access is set to false.

I wonder if the code needs the following settings, on a Windows System with UAC enabled :
  • Manifest  uiAccess set  to TRUE
  • EXE is 'Code Signed'
  • EXE is installed in or under the "Program Files" folder or in the "Windows\System32" folder

You can test this theory by running a uncompiled script ( this assumes WinBatch is installed on this system) . All uncompiled scripts meet this criteria.






Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: SendkeysTo Issue
« Reply #15 on: November 13, 2013, 01:31:15 pm »
We have confirmed that SendKey/SendKeysTo will fail if a WinBatch script runs AsInvoker and your are attempting to send keys to an elevated process ( a process run with admin privileges). This is expected behavior. You will need to Run Your script at the same integrity level as the running application that you want to send keystrokes to.

I suspect your 'msra.exe' process is running elevated, therefor you will need to specify RequireAdministrator UAC manifest setting when compiling your script. You can change the UAC settings for compiled scripts by launching the Configuration Settings dialog from the 'Settings..." button in the compiler. Set the "requested execution level" to  RequireAdministrator  and "UI Access" to FALSE.
Deana F.
Technical Support
Wilson WindowWare Inc.

kdmoyers

  • Sr. Member
  • ****
  • Posts: 448
Re: SendkeysTo Issue
« Reply #16 on: November 15, 2013, 05:23:29 am »
This sounds like a nice info tidbit to add to the standing "about UAC" articles in the database.
The mind is everything; What you think, you become.

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: SendkeysTo Issue
« Reply #17 on: November 15, 2013, 08:27:10 am »
This sounds like a nice info tidbit to add to the standing "about UAC" articles in the database.

I agree. I created the following tech article that hopefully explains the situation. http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/UAC+SendKey~and~UAC.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 3985
    • WinBatch
Re: SendkeysTo Issue
« Reply #18 on: November 15, 2013, 09:06:10 am »
The tech article isn't quit actuate for Windows 8.whatever because on Windows 8.whatever almost all processes run with medium integrity level even for administrator accounts with UAC prompting turned off. 

This is unlike Windows 7 where almost all processes run with high integrity level for administrators with UAC prompting turned off.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: SendkeysTo Issue
« Reply #19 on: November 15, 2013, 10:06:41 am »
The tech article isn't quit actuate for Windows 8.whatever because on Windows 8.whatever almost all processes run with medium integrity level even for administrator accounts with UAC prompting turned off. 

This is unlike Windows 7 where almost all processes run with high integrity level for administrators with UAC prompting turned off.

Tony,

I get the same results from my test code on Window 8.1, logged in admin, with either Default UAC setting or UAC set to Never Notify.

Code: Winbatch
;WORKS: Logged in as Admin, Script with default .WBT extention (HighestAvilable)
;WORKS:  Logged in as Admin, Script with .WBT_AF extention (RequireAdministrator)
;EXPECTED FAIL:  Logged in as Admin, Script with .WBT_IF extention (AsInvoker)
uaclevel = "Error or unsupported platform.;Process is default (UAC is disabled or standard user).;Process is running elevated.;Process is not running elevated (user is in Administrators group)."
Pause('UacElevationLevel of Script',ItemExtract(UacElevationLevel()+1,uaclevel,";"))

;Launch an Elevated Process
ShellExecute("cmd.exe", "", "", @NORMAL, "RunAs")

parentwindowname = "Admin"
ret = WinWaitExist( parentwindowname, 5 )
if ret == 0
  Pause("Notice","Unable to access specified window")
  Exit
endif

;Attempt to sendkeys
SendKeysTo( parentwindowname, "Hello World." )
Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 3985
    • WinBatch
Re: SendkeysTo Issue
« Reply #20 on: November 15, 2013, 01:04:15 pm »
That's my point. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

  • Tech Support
  • *****
  • Posts: 3985
    • WinBatch
Re: SendkeysTo Issue
« Reply #21 on: November 15, 2013, 01:39:43 pm »
To clarify, it is the 'With User Account Control (UAC) fully enabled' clause that is not correct or at least misleading with regard to Windows 8.  On Windows 8 UAC does not need to be fully enabled.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade