Sign in to follow this  
Followers 0
Cooperdale

AutoIt newbie has problems with command prompt

6 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Kealper

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by PhilHibbs

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!

Share this post


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
Sign in to follow this  
Followers 0