Jump to content

AUTOIT Send Keys not working in CMD. - Command Prompt - Administrator mode


Go to solution Solved by Jos,

Recommended Posts

Greetings AutoIT Support,

   I am unable to send keys in CMD when I am in CMD- Administrator mode, but Send Keys is working fine in regular (Non-Admin ) mode.

 

Below is the code snippet:

 

Sleep(2000)
Send('{LWIN}')
Sleep(2000)
Send("cmd")
Sleep(2000)
Send ('{SHIFTDOWN}')
Send('{CTRLDOWN}')
Send('{ENTER}')
Send('{CTRLUP}')
Send('{SHIFTUP}')
Sleep(3000)
WinActivate ( "Adminstrator: Command Prompt" )
Sleep(2000)
Send("ping www.speedtest.net")             ' This is where the error is'
Sleep(2000)
Send('{ENTER}')
Sleep(200)

 

Please help and support.

 

Thanks

  Rajeev RA
 

Link to post
Share on other sites
  • Developers
  • Solution
Posted (edited)

Ensure your script runs at the same Credential level, so add @RequireAdmin at the top of the script an try again.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

It's generally better to use ControlSend where possible or just use Run/RunWait functions, example:

#RequireAdmin

Global $g_iPidCmd = Run(@ComSpec & " /k ping www.speedtest.net")
;~ Sending Additional Commands
;~ Get Command Prompt Window Handle from process above
Global $g_hWndCmd = _ProcessGetHandle()
;~ Sleep is not required but for demo purposes
Sleep(5000)
;~ Run additional command
ControlSend($g_hWndCmd, "", "", "IPCONFIG /ALL{Enter}")

Func _ProcessGetHandle()
    Local $aWinList = WinList()
    For $i = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$i][0]) = $g_iPidCmd Then Return $aWinList[$i][0]
    Next
EndFunc

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...