pywin32

Converting Python win32evtlog objects to xml

不羁岁月 提交于 2019-12-02 04:10:37
问题 I have a app that uses win32evtlog to get and display different events and I would like to limit the display to events of a specific level but win32evtlog doesn't return this. It seems that you can convert an event to XML and then pull this info but I can't work out how you get the event from a loop to XML. I can get up to the following and use it to display data the LogObject has such as LogObject.TimeGenerated Log = win32evtlog.OpenEventLog('localhost', 'Application') while 1: LogObjects =

How to set process priority using pywin32 and WMI?

非 Y 不嫁゛ 提交于 2019-12-02 03:36:38
问题 from win32com.client import GetObject for proc in GetObject("WinMgmts:{impersonationLevel=impersonate,(IncreaseBasePriority,Debug)}").InstancesOf("Win32_Process"): if proc.CommandLine == "<my-command-line>": proc.SetPriority(4) # fails I have tried passing a priority class (0x40) as well as an actual priority (4), but both fail with the following message: File "test.py", line 5, in <module> proc.SetPriority(0x40) File "C:\Progs\Python26\lib\site-packages\win32com\client\dynamic.py", line 505,

How to set process priority using pywin32 and WMI?

自作多情 提交于 2019-12-01 23:21:23
from win32com.client import GetObject for proc in GetObject("WinMgmts:{impersonationLevel=impersonate,(IncreaseBasePriority,Debug)}").InstancesOf("Win32_Process"): if proc.CommandLine == "<my-command-line>": proc.SetPriority(4) # fails I have tried passing a priority class (0x40) as well as an actual priority (4), but both fail with the following message: File "test.py", line 5, in <module> proc.SetPriority(0x40) File "C:\Progs\Python26\lib\site-packages\win32com\client\dynamic.py", line 505, in __getattr__ ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1) pywintypes.com_error: (

How to simulate string keyboard input using Python?

非 Y 不嫁゛ 提交于 2019-12-01 14:06:08
I'm using windows 8 and have the windows api module I am trying to create a method: TypeInput(argument) #argument is a string with the objective that my method simulates the typing of the argument if the argument is a string. Unfortunately, I currently simulate typing using: win32api.keybd_event(win32con.KEYCODE, MS KEYCODE, 0, 0) And i don't know how to abstract this so that I can plug in arbitrary characters. My initial guess was to do unicode conversions but it seems the problem is worse for example ord('f') = 102 = 66 in hex but the Windows code for 'f' is 0x046 and 46 isn't 66... so i'm

How to optimize conversion from PyCBitmap to OpenCV image

旧巷老猫 提交于 2019-12-01 13:58:58
I've got this bit of code, and it works... But it runs very slow: hwin = win32gui.GetDesktopWindow() width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN) height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN) left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN) top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN) hwindc = win32gui.GetWindowDC(hwin) srcdc = win32ui.CreateDCFromHandle(hwindc) memdc = srcdc.CreateCompatibleDC() bmp = win32ui.CreateBitmap() bmp.CreateCompatibleBitmap(srcdc, width, height) memdc.SelectObject(bmp) memdc.BitBlt((0, 0), (width, height

How to optimize conversion from PyCBitmap to OpenCV image

别等时光非礼了梦想. 提交于 2019-12-01 13:44:19
问题 I've got this bit of code, and it works... But it runs very slow: hwin = win32gui.GetDesktopWindow() width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN) height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN) left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN) top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN) hwindc = win32gui.GetWindowDC(hwin) srcdc = win32ui.CreateDCFromHandle(hwindc) memdc = srcdc.CreateCompatibleDC() bmp = win32ui.CreateBitmap() bmp

Removing windows from the taskbar, Windows 7

本小妞迷上赌 提交于 2019-12-01 13:36:40
I have a little Tkinter application here, as well as a handle to the Tkinter window. What I'm trying to do is remove the window from the taskbar using some combination of Windows API calls. Basically I don't want the window to show up in the task bar. import Tkinter as tk import string import win32ui import win32con root = tk.Tk() handle = string.atoi(root.wm_frame(), 0) winhandle = win32ui.CreateWindowFromHandle(handle) root.mainloop() I hope this helps, or at least guides you somehow. I'm not sure how to do this in python, but speaking for the winapi part, this has to do with the window ex

Getting last opened MS Word document object

爷,独闯天下 提交于 2019-12-01 11:54:06
I have a python script called from a VBA AutoNew() sub in a MS Word 2003 template (.dot) - so it runs every time a document is created from this Word template. A third-party application creates documents from this template. There are a number of formatting issues with how the third-party application sets up the document, thus my script to tweak it once the third-party script has finished running. (I originally wrote the script in VBA, but problems with the VBA timer cause it to crash a significant fraction of the time. The python version works flawlessly.) I want the script to work with just

LVITEM for windows 64 bit

喜你入骨 提交于 2019-12-01 11:35:47
For a long time I tried to use the LVM_GETITEMW message with LVIF_TEXT mask to get the text of a ListView. My program worked in 32 bit but not in 64 bit architecture. I discovered that the problem was at the LVITEM struct. Shortly, my question is which struct is the appropriate one for 64 bit and why. The struct I used as the LVITEMW struct had the following fields: ('mask', c_uint32), ('iItem', c_int32), ('iSubItem', c_int32), ('state', c_uint32), ('stateMask', c_uint32), ('pszText', c_uint32), ('cchTextMax', c_int32), ('iImage', c_int32), ('lParam', c_uint64), ('iIndent', c_int32), (

pywin32 / pywinauto not working properly in remote desktop when it is minimized

蹲街弑〆低调 提交于 2019-12-01 11:30:24
I have a Jenkins pipeline that executes a program in a remote server that uses pywin to manipulate an application for functional tests. My application works great while I have the remote desktop oppened but when I close the remote desktop and run it from Jenkins, the app gets lost. What I do is to open the app and send an enter key. This is my app: os.startfile("C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe") time.sleep(5) handle = win32gui.FindWindow(0, "SAP Logon 740") keyboard = Controller() keyboard.press(Key.enter) So I tried to add focus to the app to force the focus