Jump to content

[Question] Why `WinKill` does not work?


Recommended Posts

Hi, everyone.

I have python code for kill window,  but sometimes it does not working .

My code is :

import subprocess
import time
import ctypes

au3_dll = ctypes.windll.LoadLibrary(r'D:\AutoIt\AutoItX3.dll')

def close_ie(title):
    subprocess.Popen(f"C:/Program Files (x86)/Internet Explorer/iexplore.exe https://cn.bing.com/?mkt=zh-CN")
    time.sleep(2)
    
    au3_dll.AU3_Opt("WinTitleMatchMode", 2)
    ret = au3_dll.AU3_WinKill(title, "")
    print(ret)

if __name__ == '__main__':
    title = '必应 - Internet Explorer'
    for i in range(10):
        close_ie(title)

My expectation is that all IE windows will be closed, but there will always be a few windows still there.

My env:
    win10      64bit
   python3.6.4
   autoit     v3.3.14.2

 

Any suggestions would be appreciated  :)

Link to post
Share on other sites
16 hours ago, Danp2 said:

您是否尝试过使用 ProcessClose 代替?

Sorry, I didn't.       

The information I can get is the title, and I want to operate the window that was last activated.

When the AU3_WinKill function does not work for the first time, execute AU3_WinKill again, and it will succeed. But I dont know When to succeed and when to fail···

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By noellarkin
      Readability is a Python Library that emulates the "Reading Mode" used by Browsers, ie it takes an input URL, and returns the simplified HTML. It removes headers, footers and scripts.
      I made a simple server out of it, which takes CLI arguments for server IP and server Port to start the server. Default IP and port are 127.0.0.1:8900
      Example requests that can be made:
      http://127.0.0.1:8900?url=https://google.com&output_type=TITLE
      http://127.0.0.1:8900?url=https://google.com&output_type=SHORT_TITLE
      http://127.0.0.1:8900?url=https://google.com&output_type=CONTENT
      http://127.0.0.1:8900?url=https://google.com&output_type=SUMMARY
      http://127.0.0.1:8900/health (to check if the server is running)
      import http.server import requests import re import logging import sys from readability import Document # Set up logging logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") class RequestHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): # Log the request logging.info(f"Received request: {self.path}") # Regular expression to match URLs URL_REGEX = re.compile(r"^https?://.+$") # Allowed output types ALLOWED_OUTPUT_TYPES = ["TITLE", "SHORT_TITLE", "CONTENT", "SUMMARY"] if self.path == "/health": # This is a health check request, return a 200 status code self.send_response(200) self.send_header("Content-type", "text/plain") self.send_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0") self.end_headers() self.wfile.write(b"OK") else: # Parse the query string to get the URL and output type query_string = self.path[2:] query_params = query_string.split("&") url = query_params[0].split("=")[1] output_type = query_params[1].split("=")[1] # Validate the input if not URL_REGEX.match(url): # URL is invalid self.send_response(400) self.send_header("Content-type", "text/plain") self.end_headers() self.wfile.write(b"Invalid URL") elif output_type not in ALLOWED_OUTPUT_TYPES: # Output type is invalid self.send_response(400) self.send_header("Content-type", "text/plain") self.send_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0") self.end_headers() self.wfile.write(b"Invalid output type") else: # Input is valid, proceed with processing the request try: doc = Document(requests.get(url).content) output = { "TITLE": doc.title(), "SHORT_TITLE": doc.short_title(), "CONTENT": doc.content(), "SUMMARY": doc.summary() }[output_type] # Send the response self.send_response(200) self.send_header("Content-type", "text/plain") self.end_headers() self.wfile.write(output.encode()) except Exception as e: # Log the error logging.error(f"Error: {e}") # Return an error message to the client self.send_response(500) self.send_header("Content-type", "text/plain") self.end_headers() self.wfile.write(b"An error occurred while processing the request") # Get the server IP and port from the command line arguments server_ip = sys.argv[1] if len(sys.argv) > 1 else "127.0.0.1" server_port = int(sys.argv[2]) if len(sys.argv) > 2 else 8900 # Create the server and run it indefinitely server_address = (server_ip, server_port) httpd = http.server.HTTPServer(server_address, RequestHandler) # Log an info message when the server starts logging.info("Server started") httpd.serve_forever() Note: make sure you have the readability library https://github.com/buriy/python-readability before using this
      pip install readability-lxml  
    • By noellarkin
      Yesterday I wrote a quick AutoIt script that uses the EditDistance python library by first writing the .py script and then converting it to exe, then passing arguments to it from AutoIt via command line.
      Link:
      I use AutoIt for 90% of my work, and it's quite adequate for almost anything. However, it falls short in one area: libraries related to data processing. This is fine, I understand AutoIt wasn't built to be a language for that purpose. However, it would be interesting if AutoIt would have ways of interacting with python scripts etc so existing python libraries for data analytics etc could be used. So far, the only way I've managed to do this is:
      1. Write .py script, make it accept command line arguments, and print output
      2. Compile .py into an exe file
      3. Write autoit script that uses Run() to execute the exe file, and catches the cmd console output in a variable.
      Is this the only way to go about it? This is a little inconvenient, in that I have to compile the .py into an exe every time I make changes to the python script.
    • By HoratioCaine
      Hi, I am using python to call the Autoit function. I found a interesting problem.
      env:  win10 64bit 
                python3.6.4  x86、    python3.8.6  x64
                autoit v3.3.16.0
      code:
      #filename: demo.py from ctypes import windll dll = windll.LoadLibrary(r"D:\it_tools\autoit\AutoIt3\AutoItX\AutoItX3_x64.dll") # or AutoItX3.dll dll.AU3_Send("#r", 0) Behaviour:
            (1) run with the "python.exe" 
      it will not open the run dialog, but input a "r" in the cmd window.

             (2) run with xxxxxx.exe (renamed from python.exe, you can rename whatever you like)
      work success


      I dont know why it happened.   I think it shoule be related to Python and Autoit.  So I came here...
      Can someone give me some advices.  Thanks a lot.
      (by the way, My English is not very well... I wish I  have provided the enough information... If you need more details, please contact me    )
    • By learner123
      Hi All,
       
      I am new to this AUTO IT and I have created a script that will open an app,enter pin and copy the code generated to clipboard. My java code call this autoIT script and use the copied generated code from clipboard.
      This works fine when server  window is on focus. My server is an windows server. 
      But when I minimize or disconnect the server, the script opens the app.exe but doesn't copy any value to clipboard.  
      Can anyone help me on this 😐
       
      Run("C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe")
      Local $hWnd=WinWait("abc - RSA SecurID Token") ; waits until the window is the active window
      $hWin = WinGetHandle("abc - RSA SecurID Token");
      ControlSend($hWnd,"","","1111") ; simulates pressing the Home key
      ControlSend($hWnd,"","","{ENTER}");
      ControlSend($hWnd,"","","^c");
      Sleep(1000) ;
      ControlSend($hWnd,"","","^c");
       
    • By poddex
      Hello everyone.
      I always try to work with old Windows 10 versions as much as possible because I know mane compatibility issues with Windows 10 upgrading. 
      But I couldn't do anything else (I got drivers problem), and nothing couldn't help me besides upgrading, so I upgraded from 1807 to 1903.
      And...get another problem 😃
      I use AutoitX library in external project like this.
      ObjectAutoIt=New COMObject("AutoItX3.Control");
      ObjectAutoIt.AutoItSetOption("WinTextMatchMode",2);
              While ObjectAutoit.WinExists("",WindowHeader) Cycle 
                  ObjectAutoIt.WinClose("",WindowHeader);
              EndCycle;
      After upgrade I get that this line code 
      While ObjectAutoit.WinExists("",WindowHeader)
      become extremely low - ~ 20 seconds even if 10 windows open. But before upgrade it takes 0.5 s for a max.
      And every time that this code line passes through  - it takes ~20s, (20.115, for example), not less, not more. Something pauses it to work.
      How can I diagnose, what is that?
      I tried reinstall whole AutoIt, but no results.
      Thanks to all.
×
×
  • Create New...