rajeevrra Posted June 5, 2021 Share Posted June 5, 2021 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 comment Share on other sites More sharing options...
Developers Solution Jos Posted June 5, 2021 Developers Solution Share Posted June 5, 2021 (edited) Ensure your script runs at the same Credential level, so add @RequireAdmin at the top of the script an try again. Jos Edited June 5, 2021 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 comment Share on other sites More sharing options...
JockoDundee Posted June 5, 2021 Share Posted June 5, 2021 4 hours ago, Jos said: ...so add @RequireAdmin at the top of the script an try again. I believe Jos meant to write #RequireAdmin, not @RequireAdmin... Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Subz Posted June 5, 2021 Share Posted June 5, 2021 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 comment Share on other sites More sharing options...
rajeevrra Posted June 5, 2021 Author Share Posted June 5, 2021 (edited) Thanks a bunch for your replies - @Jos, @JockoDundee and @Subz. Your help and support is appreciated. I will check and revert as needed. Take Care Edited June 5, 2021 by rajeevrra Link to comment Share on other sites More sharing options...
rajeevrra Posted June 5, 2021 Author Share Posted June 5, 2021 Code is working now.. Thanks again. and stay safe Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now