Jump to content
Sign in to follow this  
Otacon

Sending Commands to hidden CMD window?

Recommended Posts

Otacon

Hi everybody,

i'm pretty new to autoit (just discovered it this Monday) and i have banging my head on to following problem.

Everything i talk about is running on a remote Windows XP machine, which is only accessed using Remote Desktop.

I got a cmd window open, that is running a server, and want to send some keystrokes to it.

Right now i do this using the following code.

If WinExists ('windowname') Then
WinActivate ('windowname')
Send ('Hello i am some text {ENTER}')
EndIf

Which works perfectly fine, at least as long as i am logged in with Remote Desktop.

When i close Remote Desktop, the script is no longer working.

I think it is because the window can't be active when there is no RDP connection (i don't log off, i just close it so everything keeps running)

In theory, it needs be threated like a hidden window.

But ControlSend is not working, as i found out today,, it is doesn't work for CMD Windows.

Is there any way to still do what i want? Except leaving the RDP connection open.

Otherwise i would have do run that command for the server by hand every 6 hours :oops:

Share this post


Link to post
Share on other sites
Xenobiologist

Why not running an Autoit script as a service on that machnine. Then it could handle everything on its own (without dealing with windows)


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, Otacon, welcome to the forum. Depending on what command you're trying to pass to the command window, you could also simply use AutoIt's Run or ShellExecute functions, and then use PSExec (found here) to run it from your remote machine.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Otacon

Why not running an Autoit script as a service on that machnine. Then it could handle everything on its own (without dealing with windows)

I have to send the command to the existing CMD window which runs a server.

I don't want the server to run as a service, as its window is the only way to send commands to it.

Hi, Otacon, welcome to the forum. Depending on what command you're trying to pass to the command window, you could also simply use AutoIt's Run or ShellExecute functions, and then use PSExec (found here) to run it from your remote machine.

Its an already existing window to which i need to pass commands too for a Server. Things like "Stop {Enter}" or "Save {Enter}"

It won't work if i just run a shell command, otherwise it would be quite easy :oops:

Another thought of me.

If i let AutoIt start the server inside a CMD window i opened with AutoIt, would it that change things to send commands to it?

As i don't care if the server is started by a *.bat or AutoIt, because that shouldn't matter for the Server at all.

Edited by Otacon

Share this post


Link to post
Share on other sites
Otacon

Anybody else has some thoughts to this?

I still couldn't manage getting this to work ;)

Share this post


Link to post
Share on other sites
KaFu

This works for me:

$hWnd = WinGetHandle("[CLASS:ConsoleWindowClass]", "")
ControlSend($hWnd,"","","dir c:" & @crlf)

For more advanced stuff take a look at Mats Console.au3 UDF.

Edited by KaFu

Share this post


Link to post
Share on other sites
DeathRow

Its a fucntion to run pure CMD commands via CMD, do u know ?

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  

×