Sign in to follow this  
Followers 0
Nova

WinWait 4 hidden window

8 posts in this topic

The following code is just an example of something im trying to do, so do not advise me on an easier way to shutdown mycomputer becasue thats now what im after, its the method im intrested in.

The following code waits untill a cmd window is active and then it sends the command shutdown -s

Run(@SystemDir & '\cmd')
    
WinWaitActive(@SystemDir & '\cmd') 
Sleep(250)
ControlSend(@SystemDir & '\cmd', "", "", "shutdown -s{Enter}")
    
while 1
      sleep (10)
WEnd

I want this to happen inhidden mode so for example

Run(@SystemDir & '\cmd', "", @sw_hide)
    
WinWaitActive(@SystemDir & '\cmd') 
Sleep(250)
ControlSend(@SystemDir & '\cmd', "", "", "shutdown -s{Enter}")
    
while 1
      sleep (10)
WEnd

It appears the problem is WinWaitActive dose not detect hidden active windows.

Dose anyone have a work around for this ?

Share this post


Link to post
Share on other sites



are you using opt("WinDetectHiddenText",1) ?

WinDetectHiddenText Specifies if hidden window text can be "seen" by the window matching functions.

0 = Do not detect hidden text (default)

1 = Detect hidden text


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

are you using opt("WinDetectHiddenText",1) ?

Just tested the below script with your above idea !

opt("WinDetectHiddenText",1)

Run(@SystemDir & '\cmd',"",@SW_HIDE)
    
WinWaitActive(@SystemDir & '\cmd') 
Sleep(250)
ControlSend(@SystemDir & '\cmd', "", "", "shutdown -s{Enter}")
    
while 1
      sleep (10)
WEnd

Its still not working. :lmao:

Edited by Nova

Share this post


Link to post
Share on other sites

A hidden window CAN be active but that's not always the case especially if the user is clicking while the script is running.

This is probably how you want it.

Run(@ComSpec & " /k TITLE HideCmd","",@SW_HIDE)
    
WinWait('HideCmd') 
Sleep(250)
ControlSend('HideCmd', "", "", "shutdown -s{Enter}")

This is what I would do.

Run(@ComSpec & " /c shutdown -s", @SystemDir, @SW_HIDE)

Share this post


Link to post
Share on other sites

This is probably how you want it.

Run(@ComSpec & " /k TITLE HideCmd","",@SW_HIDE)
    
WinWait('HideCmd') 
Sleep(250)
ControlSend('HideCmd', "", "", "shutdown -s{Enter}")
Thats perfect, just what I wanted, but can u explain how it works ?

I want to do the same with other shell windows.

For example what im actually trying to do is start a netcat session on my computer which connects to another computer on my network.

Once the connection is made I geta remote CMD prompt for that computer

So I want my script to wait for the netcat shell window to become active in hidden mode, and send the command shutdown -s, which should shutdown the remote computer.

Thats why the following wont work :lmao:

This is what I would do.

CODERun(@ComSpec & " /c shutdown -s", @SystemDir, @SW_HIDE)

Taking your above example, how would that apply to the following code ?

Ive tryed many different versions of your example and cannot get it to work for this situation.

Run(@ScriptDir & '\Utilities\Netcat.exe Comp2 4444')   

WinWait(@ScriptDir & '\Utilities\Netcat.exe)

Sleep(250)

ControlSend(@ScriptDir & '\Utilities\Netcat.exe', "", "", "shutdown -s{Enter}")

while 1

      sleep (10)

WEnd

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Three scripts you can test out.

;Test 1
Run(@ComSpec & ' /c TITLE HideCmd & "' & @ScriptDir & '\Utilities\Netcat.exe" Comp2 4444')    

WinWait('HideCmd') 
Sleep(1000)
ControlSend('HideCmd', "", "", "shutdown -s{Enter}")

while 1
      sleep (10)
WEnd

;Test 2
Run(@ComSpec & ' /c TITLE HideCmd && "' & @ScriptDir & '\Utilities\Netcat.exe" Comp2 4444') 

WinWait('HideCmd') 
Sleep(1000)
ControlSend('HideCmd', "", "", "shutdown -s{Enter}")

while 1
      sleep (10)
WEnd

;Test 3
Opt("WinTitleMatchMode", 2)
Run(@ComSpec & ' /c "' & @ScriptDir & '\Utilities\Netcat.exe" Comp2 4444')    

WinWait('Utilities\Netcat.exe)
Sleep(1000)
ControlSend('Utilities\Netcat.exe, "", "", "shutdown -s{Enter}")

while 1
      sleep (10)
WEnd

Let us know if th above examples work for you.

Once it works, you can add the @SW_HIDE parameter.

Edited by SlimShady

Share this post


Link to post
Share on other sites

Let us know if th above examples work for you.

The first 2 work flawlessly :"> the 3rd one however dosent work.

Tnx a million slim. :lmao:

Share this post


Link to post
Share on other sites

I'm glad. No problem, you're welcome.

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