From 2938617010 at qq.com Tue Apr 10 04:43:57 2018 From: 2938617010 at qq.com (=?ISO-8859-1?B?U2FtTGVl?=) Date: Tue, 10 Apr 2018 16:43:57 +0800 Subject: [python-win32] win32clipboard.GetClipboardData does not return latest data after using type_keys('^C') Message-ID: Dear pywin32 group: Recently i bump into a case where i cannot get text from a window field directly. So i try to type ctrl+a and ctrl+c , and then use win32clipboard to read data from clipboard However, i always get data from the previous "ctrl+a ctrl+c", not the latest one In order to get the latest clipboard data , i have to perform "ctrl+a ctrl+c" in another thread Should this be a bug? FYI ,I'm using Windows10 , Python 3.6.4rc1 def chooseAndCopyResult(app,windowName,editIdx): allEdits = app.window(title_re='.*{}.*'.format(windowName)).children(control_type='Edit') allEdits[editIdx].set_focus().type_keys('^A').type_keys('^C') #this one does not return the latest clipboard but the previous clipboard def readResultFromOCR(app,windowName,editIdx): chooseAndCopyResult(app,windowName,editIdx) win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() return data # this one works, and get the latest data from clipboard def readResultFromOCRWorking(app,windowName,editIdx): thread = Thread(target=chooseAndCopyResult,args=(app,windowName,editIdx)) thread.start() thread.join() win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() return data -------------- next part -------------- An HTML attachment was scrubbed... URL: From k3ops at free.fr Tue Apr 10 06:55:20 2018 From: k3ops at free.fr (k3ops at free.fr) Date: Tue, 10 Apr 2018 12:55:20 +0200 (CEST) Subject: [python-win32] Service stucks in Starting state In-Reply-To: <1700248297.321400253.1523357635813.JavaMail.root@zimbra31-e6> Message-ID: <311222457.321407187.1523357720833.JavaMail.root@zimbra31-e6> Hi all, I am new to 'pywin32' but I was able to create very quickly a new Windows service for my purpose thanks to your work! Unfortunatelly when I install and then start my service, it gets stucked in Starting state and then I have no chance to stop or remove it except by restarting the computer. Here is the code I used, could you help me on this one? I added this line self.ReportServiceStatus(win32service.SERVICE_RUNNING) in SvcDoRun function compared to your example but it did not change anything. Thanks #!/usr/bin/env python3 import win32service import win32serviceutil import win32event import servicemanager class MyClass(win32serviceutil.ServiceFramework): # you can NET START/STOP the service by the following name _svc_name_ = "My_CLASS" # this text shows up as the service name in the Service # Control Manager (SCM) _svc_display_name_ = "MY_CLASS" # this text shows up as the description in the SCM _svc_description_ = "MY_DESC" def __init__(self, args): # create Windows Service win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) # create an event to listen for stop requests on def SvcDoRun(self): self.ReportServiceStatus(win32service.SERVICE_RUNNING) win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) def SvcStop(self): # tell the SCM we're shutting down self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # fire the stop event win32event.SetEvent(self.hWaitStop) if __name__ == '__main__': win32serviceutil.HandleCommandLine(MyClass) From timr at probo.com Tue Apr 10 16:35:34 2018 From: timr at probo.com (Tim Roberts) Date: Tue, 10 Apr 2018 13:35:34 -0700 Subject: [python-win32] Service stucks in Starting state In-Reply-To: <311222457.321407187.1523357720833.JavaMail.root@zimbra31-e6> References: <311222457.321407187.1523357720833.JavaMail.root@zimbra31-e6> Message-ID: <0fd097f9-e23b-75e8-324a-97c6d7d7fa8e@probo.com> k3ops at free.fr wrote: > Unfortunatelly when I install and then start my service, it gets stucked in Starting state and then I have no chance to stop or remove it except by restarting the computer. How do you know this?? How did you start the service?? How are you monitoring the state? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From k3ops at free.fr Thu Apr 12 04:19:16 2018 From: k3ops at free.fr (k3ops at free.fr) Date: Thu, 12 Apr 2018 10:19:16 +0200 (CEST) Subject: [python-win32] Service stucks in Starting state In-Reply-To: <840043384.330995940.1523519277815.JavaMail.root@zimbra31-e6> Message-ID: <1434839174.331172427.1523521156462.JavaMail.root@zimbra31-e6> Hi Tim, > How did you start the service?? I run it with the following command line: python MyService.py install python MyService.py start > How do you know this? How are you monitoring state? When I go to Windows Services list its state is "Starting" instead of "Running" so I cannot do any actions on it (e.g Stop) I managed to get the proper state "Running" by removing the following line from SvcDoRun function: self.ReportServiceStatus(win32service.SERVICE_RUNNING) since it's already called from parent function SvcRun from win32serviceutil.ServiceFramework that calls SvcDoRun. But when typing "python MyService.py start", my Service gets stuck in "Running" state. Here is the updated code, am I missing something to notify the service as stopped? class MyClass(win32serviceutil.ServiceFramework): # you can NET START/STOP the service by the following name _svc_name_ = "My_CLASS" # this text shows up as the service name in the Service # Control Manager (SCM) _svc_display_name_ = "MY_CLASS" # this text shows up as the description in the SCM _svc_description_ = "MY_DESC" def __init__(self, args): # create Windows Service win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) # create an event to listen for stop requests on def SvcDoRun(self): win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) def SvcStop(self): # tell the SCM we're shutting down self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # fire the stop event win32event.SetEvent(self.hWaitStop) From johnaherne at rocs.co.uk Thu Apr 12 10:04:10 2018 From: johnaherne at rocs.co.uk (John Aherne) Date: Thu, 12 Apr 2018 15:04:10 +0100 Subject: [python-win32] Service stuck in starting state Message-ID: Have you looked in the event log to see if there are any messages to tell you what might have happened. Regards -- *John Aherne* *www.rocs.co.uk * 020 7223 7567 -------------- next part -------------- An HTML attachment was scrubbed... URL: From k3ops at free.fr Thu Apr 12 11:25:31 2018 From: k3ops at free.fr (k3ops at free.fr) Date: Thu, 12 Apr 2018 17:25:31 +0200 Subject: [python-win32] Service stuck in starting state In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: From thomas.calvo at gmail.com Wed Apr 18 04:56:27 2018 From: thomas.calvo at gmail.com (Thomas Calvo) Date: Wed, 18 Apr 2018 10:56:27 +0200 Subject: [python-win32] _GetDescInvokeType regression on dynamic.py Message-ID: Hi all, as suggested I created a pull request for this regression, concerning this issue . All the details are in the comment, where I explain that some parts of the puzzle are still missing, so this may require some discussion. Kind Regards, Thomas. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ram at rachum.com Wed Apr 25 08:26:37 2018 From: ram at rachum.com (Ram Rachum) Date: Wed, 25 Apr 2018 15:26:37 +0300 Subject: [python-win32] Wait for process to be started Message-ID: I'm writing a Python program on Windows 7. I want the program to patiently wait for a process to be started that has a certain name, and then do an action after it was started. I can easily write the program using polling, i.e. checking every second whether the process is active, but I want to be more efficient and wait on the system event that is generated when a process is started. Is that possible? I was told that the `wmi` module is the way to go, but does anyone know how to make it do what I described above? Thanks, Ram. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ram at rachum.com Wed Apr 25 09:50:38 2018 From: ram at rachum.com (Ram Rachum) Date: Wed, 25 Apr 2018 16:50:38 +0300 Subject: [python-win32] Wait for process to be started In-Reply-To: References: Message-ID: Awesome, looks like what I need is wmi.WMI().Win32_Process.watch_for('creation', name='notepad.exe') Thanks! On Wed, Apr 25, 2018 at 4:27 PM, Dennis Lee Bieber wrote: > On Wed, 25 Apr 2018 15:26:37 +0300, Ram Rachum declaimed > the following: > > > > >I was told that the `wmi` module is the way to go, but does anyone know > how > >to make it do what I described above? > > > > And what have you searched on? > > https://bsmadhu.wordpress.com/2012/06/28/monitor-process- > startupshutdown-using-wmi-powershell/ > (PowerShell and C# examples) > > http://timgolden.me.uk/python/wmi/tutorial.html (introduction to WMI > module; with example that triggers on process startup -- though it triggers > for ALL process starts, not just one by name) > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Apr 25 15:58:36 2018 From: timr at probo.com (Tim Roberts) Date: Wed, 25 Apr 2018 12:58:36 -0700 Subject: [python-win32] Wait for process to be started In-Reply-To: References: Message-ID: <386b29f3-9a58-ef69-7fcc-31458c857593@probo.com> Ram Rachum wrote: > > I'm writing a Python program on Windows 7. I want the program to > patiently wait for a process to be started that has a certain name, > and then do an action after it was started. > > I can easily write the program using polling, i.e. checking every > second whether the process is active, but I want to be more efficient > and wait on the system event that is generated when a process is > started. Is that possible? Is this a process you are starting?? If YOU start the process, you get a handle that you can wait on -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc.