pywin32

Ask for admin access for a Python function in Windows

天大地大妈咪最大 提交于 2019-12-14 03:44:13
问题 I want to copy a list of files to the Windows system directory (C:\Windows) using a Python function. I have a function: import shutil def copy_list(src_list, dst): for file in src_list: shutil.copy(file, dst) And I want to call it like this: def copy_as_admin(): #... some code to obtain user elevation ... copy_list(files_list, "C:\\Windows\") How can I achieve this? PS: I'm using Python3, I tried solutions in this thread, How to run python script with elevated privilege on windows but those

SendMessage Return Error

我与影子孤独终老i 提交于 2019-12-13 21:04:45
问题 I'm working on a python script to interact with a program using wm_copydata, but am having trouble with reading the return data. I've turned a few examples into the following: import win32con, win32api, win32gui import ctypes, ctypes.wintypes FindWindow = ctypes.windll.user32.FindWindowW SendMessage = ctypes.windll.user32.SendMessageW class COPYDATASTRUCT(ctypes.Structure): _fields_ = [ ('dwData', ctypes.wintypes.LPARAM), ('cbData', ctypes.wintypes.DWORD), ('lpData', ctypes.c_char_p)

pywin32 programming error on Win7 with shell.SHGetDesktopFolder,desktop.BindToObject,desktop.GetDisplayNameOf

孤街浪徒 提交于 2019-12-13 19:42:25
问题 When running the following code on WinXP , all is fine , from win32com.shell import shell def launch_file_explorer(path, files): folder_pidl = shell.SHILCreateFromPath(path,0)[0] desktop = shell.SHGetDesktopFolder() shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder) name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item) for item in shell_folder]) to_show = [] for file in files: if file not in name_to_item_mapping: raise Exception('File: "{}" not

CreateCompatibleDC fails after calling it exactly 4,984 times

断了今生、忘了曾经 提交于 2019-12-13 19:28:03
问题 I've encountered a strange bug in my program. It's a little odd, as it occurs on exactly the 4984th call to the function. I've been tweaking this all day, and without fail, that's the number at which it fails. The code in question is a small convenience function which creates and returns a DC and Bitmap. The context of this little function is that it's a piece in my stab at a screen recorder, so it's getting called tons and tons of times. When I first noticed the error, after some sleuthing

Python 64 bit DLL COM Server Registration Problem on 64 bit Windows 7

五迷三道 提交于 2019-12-13 17:44:44
问题 I am trying to create a simple COM server using Python 2.7 on 64 bit Windows 7, but I can't get the DLL registered successfully. I am able to do this successfully using Python 2.6 on 32 bit Windows XP. I am also able to register my class directly from Python. This is my module, heikki.py, based on the pywin32 COM tutorial: class Heikki: _reg_clsid_ = '{F4C7D945-BF6B-4BF8-BCBB-EA021FCCE623}' _reg_desc_ = "Heikki" _reg_progid_ = "Heikki.TestServer" _public_methods_ = ['Hello'] def __init__(self

Implement timeout in windows filecopy

喜欢而已 提交于 2019-12-13 08:00:02
问题 I want to copy a list of files on windows using python. When doing that manually, I see timeouts in some files, therefore the copy process fails. I need a way to implement the timeout check in python. So far I use the win32 API: import win32file files = {'source_a' : 'dest_a', 'source_b' : 'dest_b'} for f in files.keys(): win32file.CopyFileW(f,files[f],0) In some cases, the CopyFileW function doesn't return in "reasonable time", for the sake of this discussion, let's say 5 seconds. How can I

pywin32 and pyttsx error, trouble combining the two

╄→гoц情女王★ 提交于 2019-12-13 06:31:46
问题 i have pywin32 in my site packages and my pyttsx is in a separate folder. Is this the reason why i am getting the following error? import win32api, sys, os ImportError: DLL load failed: The specified module could not be found The code is as follows, import pyttsx def onStart(name): print 'starting', name def onWord(name, location, length): print 'word', name, location, length def onEnd(name, completed): print 'finishing', name, completed engine = pyttsx.init() engine.connect('started

Tell reboot from shutdown on Windows Server 2008

一世执手 提交于 2019-12-13 04:31:23
问题 As per MSDN, it is not possible to determine, whether reboot or shutdown occurred using WM_ENDSESSION Message. I've found the only way to do this, but it's quite ugly and works only for Windows 2000 Server, not for 2008 Server. The reason I'm asking is that I'm in process of porting Linux daemon to Windows as System Service. This daemon acts differently on reboot and system shutdown events. I am also using python with pywin32 in project if it somehow helps to answer. 回答1: You need to

how to control mouse/cursor/pointer speed using python? [closed]

萝らか妹 提交于 2019-12-13 03:55:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have a tkinter GUI ,and I would like to control the speed of the cursor inside my programme (as if you would set it up using windows control panel by adjusting the mouse settings there) . I guess I can use pywin32 but all I can find is setting the position of the cursor on the screen but what I really want is

Write image to Windows clipboard in python with PIL and win32clipboard?

不问归期 提交于 2019-12-13 01:15:51
问题 I'm trying to open an image file and copy the image to the Windows clipboard. Is there a way to fix this: import win32clipboard from PIL import Image def send_to_clipboard(clip_type, data): win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(clip_type, data) win32clipboard.CloseClipboard() clip_type = win32clipboard.CF_BITMAP filepath = 'c:\\temp\\image.jpg' im = Image.open(filepath) data = im.tobitmap() # fails with valueerror: not a bitmap # data =