Cooperdale Posted March 17, 2010 Share Posted March 17, 2010 Hello, I have a problem with this script (which is my first AutoIt script, by the way). What I want to do is automate a psexec command which will hibernate my other pc from remote. The command works, but since the other pc has no password, it prompts me for one. So I was trying to make AutoIt simulate the "enter" key to skip the password request. The script basically works, but the strange thing is, it opens two instances of the command prompt, each of them executes the psexec command but only one of them receives the simulated keystroke. Here is the script: Run(@ComSpec & " /c " & 'c:\Utility\Utilities\Pstools\psexec \\FUZZEEMADDER-PC -u Fuzzeemadder Rundll32 Powrprof.dll,SetSuspendState Sleep', "") Send ("{ENTER}") Sleep (30000) ProcessClose ("psexec.exe") ProcessWaitClose ("psexec.exe") ProcessClose ("cmd.exe") Can somebody help me? What am I doing wrong? Link to comment Share on other sites More sharing options...
Kealper Posted March 17, 2010 Share Posted March 17, 2010 (edited) I haven't tried it, as I do not have AutoIt or pstools on this computer, but I believe you could just run psexec.exe with RunWait("c:\Utility\Utilities\Pstools\psexec.exe \\FUZZEEMADDER-PC -u Fuzzeemadder Rundll32 Powrprof.dll,SetSuspendState Sleep") I cannot try it out, but that would probably work just fine; It should run it, and wait for it to close. Also, welcome to AutoIt Edited March 17, 2010 by Kealper Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 17, 2010 Share Posted March 17, 2010 I haven't tried it, as I do not have AutoIt or pstools on this computer, but I believe you could just run psexec.exe with RunWait("c:\Utility\Utilities\Pstools\psexec.exe \\FUZZEEMADDER-PC -u Fuzzeemadder Rundll32 Powrprof.dll,SetSuspendState Sleep")I cannot try it out, but that would probably work just fine; It should run it, and wait for it to close.Also, welcome to AutoIt Then the Send("{ENTER}") would not then work, as it would still be waiting for a program to finish. Link to comment Share on other sites More sharing options...
PhilHibbs Posted March 17, 2010 Share Posted March 17, 2010 (edited) Can somebody help me? What am I doing wrong? I think the {Enter} is not going to the Command Prompt window, it is probably going to the Explorer window that you are running the script from, and is activating the script a second time, and by the time the second script is running, the first Command Prompt has come to the foreground and gets the {Enter} keystroke from the second script. So your script needs to wait for the Command Prompt to actually be in the foreground before sending the {Enter}. *Update*: You need something like this: WinWaitActive("c:\WINDOWS\system32\cmd.exe") Or, if you get rid of the @comspec like Kealper suggests... WinWaitActive("c:\Utility\Utilities\Pstools\psexec") Adjust WinTitleMatchMode to taste. Edited March 17, 2010 by PhilHibbs Link to comment Share on other sites More sharing options...
Cooperdale Posted March 17, 2010 Author Share Posted March 17, 2010 Guys, thank you very much. I had already tried RunWait, but it actually stopped the Send command to kick in. PhilHibbs, I still have to try it out but it really sounds right. I will try and report back. Link to comment Share on other sites More sharing options...
Cooperdale Posted March 20, 2010 Author Share Posted March 20, 2010 It worked. The only trouble was with capital letters, the window title must be the same and it is caps-sensitive. Here is the full code: Run(@ComSpec & " /c " & 'c:\Utility\Utilities\Pstools\psexec \\FUZZEEMADDER-PC -u Fuzzeemadder Rundll32 Powrprof.dll,SetSuspendState Sleep', "") WinWaitActive("C:\Windows\system32\cmd.exe") Send ("{ENTER}") Sleep (30000) ProcessClose ("psexec.exe") ProcessWaitClose ("psexec.exe") ProcessClose ("cmd.exe") Thanks a lot! 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