Skip to main content

Collection of win32 related utils.

Project description

win32fastutils

Collection of win32 related utils.

Installed Utils

  • win32fastutils.consoleutils
    • ResetableAttachConsole
    • ReadConsoleOutputText
  • win32fastutils.guiutils
    • PostMessage
    • GetHwndsByProcessIds
    • GetExplorerHwnds
    • GetExplorerProcessIds
  • win32fastutils.py32fix
    • iswin32
    • DisableFileSystemRedirection

Usage Examples

Example 1: Read console output

examples/read_console_output.py

import uuid
import time
import subprocess

from win32fastutils import consoleutils

CMD = "C:\\Windows\\System32\\cmd.exe"

msg1 = str(uuid.uuid4())
proc = subprocess.Popen([CMD, "/C", "echo", msg1, "&&", "timeout", "2"], creationflags=subprocess.CREATE_NEW_CONSOLE)
time.sleep(1)
result = ""
with consoleutils.ResetableAttachConsole(proc.pid):
    result = consoleutils.ReadConsoleOutputText()
print(result)

result output

C:\workspace\win32fastutils>python examples\read_console_output.py
8a3d81ac-9f59-4066-8206-86cee8101f8c <Note: a lot of space here....>

等待 1 秒,按一个键继续 ...

Example 2: Press ENTER to end the timeout waiting

examples/press_enter_to_end_time_timeout_waiting.py

import uuid
import time
import datetime
import subprocess

from win32fastutils import guiutils

CMD = "C:\\Windows\\System32\\cmd.exe"

print("start", datetime.datetime.now())
msg1 = str(uuid.uuid4())
proc = subprocess.Popen([CMD, "/C", "echo", msg1, "&&", "timeout", "20"], creationflags=subprocess.CREATE_NEW_CONSOLE) # wait for 20 seconds
time.sleep(1)
hwnds = guiutils.GetHwndsByProcessIds(proc.pid)

guiutils.PostMessage(hwnds[0], "\n") # press ENTER to end the timeout waiting
proc.wait()
print("end  ", datetime.datetime.now())

result output

C:\workspace\win32fastutils>python examples\press_enter_to_end_the_timeout_waiting.py
start 2022-02-17 17:01:15.115822
end   2022-02-17 17:01:16.210102

Example 3: Using 32bit-version-python in 64bit-version-windows, we can NOT access files under folder C:\Windows\System32, How to fix the problem?

import os
from win32fastutils import py32fix

SSH = "C:\\Windows\\System32\\OpenSSH\\ssh.exe"

print("Access directly result:", os.path.exists(SSH))

with py32fix.DisableFileSystemRedirection():
    print("Access in fixed scope: ", os.path.exists(SSH))

result output

C:\workspace\win32fastutils>python examples\32bit_python_access_application_under_system.py
Access directly result: False
Access in fixed scope:  True

Releases

v0.1.0

  • First release.

v0.1.1

  • Add psutil in requirements.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

win32fastutils-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

win32fastutils-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file win32fastutils-0.1.1.tar.gz.

File metadata

  • Download URL: win32fastutils-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for win32fastutils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c0f57e8d0728fd6045bd7a13b43e0e9e4df1416b425eadfd62abf5627466847f
MD5 65bda758e21f65702ee505393a8500ed
BLAKE2b-256 1342e1b737323c16771a5a140a47855e5deb3b502c5312f83b0ea5643e7b1f9d

See more details on using hashes here.

File details

Details for the file win32fastutils-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: win32fastutils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for win32fastutils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db8e62dff2cc777503b690a10897a366fc0717e7063e0d3d4e15a8ac3aaec58f
MD5 bb0f803f278f001de5c4ecc2736fdf36
BLAKE2b-256 51c516d8011246724b3f7fada55172ba1fbc331ae82d0536c64ebf6779150093

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page