pywin32

Unusual event.EventID numbers like -2147481364 in Python using win32evtlog from Pywin32

一笑奈何 提交于 2019-12-11 19:09:18
问题 I wrote a python(3.2) script to ban ips on certain events from the event logs on a Windows 2008 server and I was trying to test if it would ban ips from sql brute forcing attempts properly. Unfortunately so far it's not getting to that part of the code because the event ID it is looking for never appears (although it should as it's in the log file). def run_script_application_log(): eventIds = [18456] #look for these events to process for possible ip bans 18456 = failed login server =

Print PDF file in duplex mode via Python

孤者浪人 提交于 2019-12-11 18:35:46
问题 I have an script in Python that prints PDF files. The script works using win32api.ShellExecute() and everything is fine, but now, I need to print PDF files that have double sided content, user manuals in concrete. I have tried setting the duplex mode in win32print, but nothing works, the printer still print 2 pages on 2 sheets for my PDF instead of two pages on a double sided sheet. The printer works with this mode in other applications, but with the python script doesn't work well. This is

CreateProcessAsUser done! How to control the created process?

落花浮王杯 提交于 2019-12-11 10:10:25
问题 I'm trying to launch an app as another user, this works perfectly, the process is created, but I don't know how to handle the created process as I usually do with comtypes or win32com (COM interface), here is the script: import win32process import win32security import win32con import cgi import cgitb; cgitb.enable() domain = '.' username = 'me' password = 'mypwd' try: token = win32security.LogonUser ( username, domain, password, win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32

Python - Using win32com.client to accept all changes in Word Documents

余生颓废 提交于 2019-12-11 10:09:43
问题 I'm using win32com.client from the pywin32 module to accept all tracked changes in a word document (Python 3.6.4 on Windows 10 64 bit). Specifically the code I'm using is the following: import win32com.client as win32 word = win32.gencache.EnsureDispatch("Word.Application") word.Visible = False doc = word.Documents.Open(PATH TO WORD FILE) doc.Activate() word.ActiveDocument.TrackRevisions = False # Maybe not need this try: word.WordBasic.AcceptAllChangesInDoc() except TypeError: pass word

how to get firefox address bar url for python (pywin32)

白昼怎懂夜的黑 提交于 2019-12-11 09:59:41
问题 i need grab to firefox address bar. how to get address bar url for python ? (i need second part other browsers chrome and safari grabbing address bar but firefox is urgently). Thanks. 回答1: You will need to go thru all top windows, and see if title contains firefox or check window class of firefox using spy++, then go thru all child windows to find URL, as a starting point do something like this import win32gui def enumerationCallaback(hwnd, results): text = win32gui.GetWindowText(hwnd) if

How to debug a Python program running as a service?

痞子三分冷 提交于 2019-12-11 09:13:31
问题 I have a python script which works well when run in the console. However, when using pywin32 in order to let it run as a service, the service gets installed and starts okay but the desired output is not produced. So something must be going wrong -- but I can't see what's happening to find out the reason. The script does the following: Searches for *.csv files in a given input dir If no such files are found it waits 1 minute. If one is found it uses it as input for step 3. If multiple csv

Embedding text file into excel using Python

╄→尐↘猪︶ㄣ 提交于 2019-12-11 08:25:20
问题 I'm trying to embed a text file into Excel using Python: xl = win32.Dispatch('Excel.Application') xl.Visible = 1 wb = xl.Workbooks.Open("C:\inventory\INVENTORY.xls") column = wb.ActiveSheet.Range("D2:D200") i = 2 for cell in column: hostname_cell = wb.ActiveSheet.Cells(i,1).Value filename = 'C:\ioe\\' + str(hostname_cell) + '.txt' if hostname_cell is not None: print filename xl.ActiveSheet.OLEObjects().Add(FileName=filename, Link=False, DisplayAsIcon=True).Select i += 1 But I am getting this

Python win32serviceutil QueryServiceStatus: What does the return value mean?

天涯浪子 提交于 2019-12-11 07:36:30
问题 I am learning to use pywin32, and am trying to use the win32serviceutil modules on 64bit Python 3.6.4 The following code: import win32serviceutil as service serviceStatus = service.QueryServiceStatus("WinDefend") print(serviceStatus) Returns the following tuple: (16, 4, 197, 0, 0, 0, 0) I am utterly new to the windows api and pywin32, what does these 6 values mean? Any documentation on pywin32 and win32 isn't revealing anything. Edit - I'm running Windows 10 回答1: you got SERVICE_STATUS

Using ImageGrab with bbox from pywin32's GetWindowRect

筅森魡賤 提交于 2019-12-11 06:55:11
问题 I want to use PIL's ImageGrab to capture a specific window. What my code below does is that it uses pywin32's FindWindow to get the handle of my wanted window then get its size and location with GetWindowRect. I then use ImageGrab with a bbox equal to the result that I got from GetWindowRect. However, this does not capture the whole window; a big chunk of the window is not shown. What did I do wrong? Here is my code and the result I get: import win32gui import cv2 from PIL import ImageGrab

Python- How to communicate with printer

自闭症网瘾萝莉.ら 提交于 2019-12-11 05:39:48
问题 I've been searching for a few days on how to improve a program I wrote for work. The program, which uses python 3.6, simply sends pre-formatted .doc files to the printer, but I can't seem to find a way on how to signal the function to stop sending the file to print once the printer has run out of paper. The number of documents printed varies, so I can't just use a simple range function. I've looked into the win32print module and the pycups module (which won't pip install not matter what I try