Re: [python-win32] How to set value with PyIPropertyStore

2019-10-14 Thread Tim Roberts

Peng Chen wrote:


I'm working on a script to shift video media creation time.

I can see there is a function
PyIPropertyStore.SetValue(key, value) and PyIPropertyStore.Commit()
to write the date back, but I'm not sure how to construct the value 
because it requires PyPROPVARIANT type.
I can't figure out any where to import this type and doesn't know how 
to construct it.


PyPROPVARIANT is generally a return type.  In a case like this, I would 
expect that you would simply pass the datetime value, and the interface 
code would convert it into a variant.  Have you tried that?  Did you get 
an error?


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Word Application saving to PDF

2019-10-09 Thread Tim Roberts
On Oct 8, 2019, at 9:58 AM, Holland, James via python-win32 
 wrote:
> 
> I’m trying to open some rtf files to Word and then save as PDFs.
> ...  
> Traceback (most recent call last):
>  
>   File "", line 15, in 
> doc.SaveAs2(output_dir + '/' + 'rtfTest.pdf', FileFormat = wdFormatPDF)
>   File 
> "C:\Users\CMTHOL~1\AppData\Local\Temp\gen_py\3.6\00020905---C000-0046x0x8x7\_Document.py",
>  line 461, in SaveAs2
> , CompatibilityMode)
> com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 
> 'Command failed', 'wdmain11.chm', 36966, -2146824090), None)

Did you do any web searching for this?  -2146824090 is 0x80A1066, which is a 
security issue.  Do you have permission to write into that directory?  Are you 
able to do this same action if you do it by hand?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Calling Methods of an object returned by an COMObject method

2019-09-20 Thread Tim Roberts
On Sep 19, 2019, at 10:51 AM, Andreas Merl  wrote:
> 
> I am trying to automate CST Studio.
> ...
> As example “Quit()”
> When I try to call this method nothing happens
> mws.Quit()
> It should quit the project.
> What happens:
> Nothing
>  
> For me it looks as the methods of mws are never called.

Have you tried the other methods, or are you basing that conclusion on exactly 
1 sample?

How can you tell it didn’t quite the project?  Does the app open a new instance 
when you call EnsureDispatch?  Excel, for example, is perfectly happy to run in 
the background as a COM server, so there’s no visible change when you quiet.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dispatch command hangs

2019-08-15 Thread Tim Roberts
On Aug 15, 2019, at 9:28 PM, Joel Gross  wrote:
> 
> Yeah I'm calling CoInitialize. I can give CoInitializeEx a shot, but there's 
> no clear-cut way to set a priority for Dispatch? I'm not sure how these 
> objects are handled internally, is it just a regular queue?

Is this an out-of-process server, so you’re receiving requests from other 
processes?  If so, then I think you’re seeing RPC (Remote Procedure Call), 
which marshals the parameters back and forth, and I believe those are all 
first-come first-served.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dispatch command hangs

2019-08-15 Thread Tim Roberts
On Aug 14, 2019, at 6:12 PM, Joel Gross  wrote:

> I have a multi-threaded application that receives a large number of messages 
> (COM objects) in sudden bursts. During this time, I've noticed that if my 
> other thread attempts to create a new COM object via the Dispatch call, that 
> call seems to hang until the messages have been processed. This can take more 
> than a minute sometimes. 
> I am wondering if this is because the win32 side of things is still trying to 
> churn through all the messages? Is there a way to preempt this behavior to 
> ensure that the object I'm trying to create gets created immediately?
> 
This is a complicated topic.  Are you calling CoInitialize?  By default, that 
will create a “single-threaded apartment”, where actions get handled by a 
single thread.  You can try calling CoInitializeEx with COINIT_MULTITHREADED 
and see if that helps.

But even then, you bang up against the Python interpreter lock, which only 
allows the interpreter to handle one thread at a time.  I wouldn’t think you’d 
have to wait for the whole set of object requests to drain, but threading in 
Python is always tricky.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] DoAction problem

2019-07-28 Thread Tim Roberts
On Jul 26, 2019, at 8:05 AM, sylvain.fe...@ville-ge.ch wrote:
> 
> My photoshop action is doing : 
> - Open 
> - Smart sharpen 
> - Convert to Profile current document 
> - Save 
> - Close 
> 
> If Pillow is also able of "smart sharpening" and "converting to Profile 
> current document", your suggestion is very promising.

Did you even look?  Pillow includes both a tunable “sharpen” filter and an 
“unsharp mask” filter, as will every competent graphics library.

The color profile conversion isn’t really necessary.  My guess is you’re not 
really sure what it does anyway.


> Is there any place on the Web where I can find reference to psApp tasks like 
> "DoAction", "Export", the parameters they need, etc.? It seems that it is not 
> so easy. Well, this is maybe again a very naive question. 

Those are Photoshop questions.  Adobe has documentation on the Photoshop APIs, 
and they have their own user forums.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] DoAction problem

2019-07-25 Thread Tim Roberts

sylvain.fe...@ville-ge.ch wrote:

Some little progress :
Problematic code modified :
psApp.DoAction('jpg_q8','Default Actions') # where 'jpg_q8' is the 
recorded action and 'Default Actions' the folder where the action is 
saved.


Right -- the "action set" in Photoshop terms.


No more error message, but... no result : my tif files are not 
transformed to jpg files.


The Python part is now working.  WE have no way of knowing what your 
Photoshop action is doing.  Is it actually doing the save, or do you 
need to call psApp.Export?


And, by the way, if ALL you need to do is convert TIF to JPG, you 
certainly do not need to launch the Photoshop behemoth for that. Just 
use pip to install "pillow", the Python Imaging Library, and all you 
need is this:


    from PIL import Image
    Image.open('myfile.tif').save('myfile.jpg')

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] DoAction problem

2019-07-25 Thread Tim Roberts

sylvain.fe...@ville-ge.ch wrote:


New in Python and coding.

My goal :
Apply recorded actions in Photoshop to many folders and subfolders 
containing images.


My inspiration :
Web page explaining a Python code using pywin32 : 
https://vsfxryan.com/portfolio/python-photoshop-action-scripts/, but I 
do not want to define functions, I am too much beginner for this.


Problematic code :
#run action script which opens the file, convert it to jpg, save and 
close it.

psApp.DoAction( actionScript, 'jpg_q8')

Error message :
NameError: name 'actionScript' is not defined

Could you please help me solve this?


Functions are fundamental to programming in general and Python in 
particular.  You need to understand them if you're going to get anything 
done.  Otherwise, you'll end up typing the same code over and over and over.


In this case, it looks like you are trying to run this code outside of 
the function it was defined in.  The error is pretty much 
self-explanatory; you're trying to pass the value of the variable 
"actionScript" to the DoAction function, but there is no variable called 
"actionScript".  Look at the code itself.  You'll see that 
"actionScript" was passed in to the function as a parameter, because he 
wanted to be able to trigger different actions with the same code.


It should be clear that what you need to pass here is the action you 
want to take.


However, if you really need to script common actions to images and 
folders, I strongly suggest you take a look at the ImageMagick package.  
It is an incredible powerful photo manipulation tool that is all driven 
from the command line.  It can be a bit tricky to set up the command 
lines, but once you do, it works the same way, time after time.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem reading a shortcut (.lnk) with cPython 3.7 (32 bit)

2019-06-18 Thread Tim Roberts

David Hughes wrote:


I'm in the process of upgrading my software from Python 2.7 to 3.7 now 
that wxPython has been migrated to 3. As part of a procedure for 
upgrading an end user's own installation I check for it's location via 
the desktop shortcut that Innosetup created during the original 
installation.


That's not a particularly good method in the general case.  I don't find 
much use for the desktop icon, so I suppress it.  You might be better 
served to use the registry, in 
HKEY_LOCAL_MACHINE\Software\Python\PythonCore.  32-bit installations 
will be in HKEY_LOCAL_MACHINE\Software\WOW6432Node\Python\PythonCore (if 
you're reading from a 64-bit app).



I have a procedure for doing this that worked/works fine with Python 
2.7 that is very similar to the one published in 
/http://timgolden.me.uk/python/win32_how_do_i/read-a-shortcut.html/. 
Neither mine nor Tim's works under Python 3.7 (I haven't checked any 
other version of 3). With Tim's version, when the line


    name, _ = link.GetPath (shell.SLGP_UNCPRIORITY)

is executed, after a delay it responds with /aborted (disconnected)/ 
and the program terminates, as does mine.


Is it possible you have installed a 32-bit Python on a 64-bit system?  
Theoretically, you should be able to use CLSID_ShellLink from either 
one, but I'm trying to narrow things down.  Tim's code works fine for me 
with Python 3.7.2 (64 bit) on Windows 10.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Retrieve Windows Notifications With pywin32

2019-06-06 Thread Tim Roberts
On Jun 5, 2019, at 2:25 PM, DAI VU  wrote:
> 
> Thank you for the response. I need to deal with toast notifications. I am not 
> sure if that answer your question.

Well, I was really going for a philosophical point.  Most toast notifications 
are things that the user needs to deal with.  There are many things that would 
be inappropriate for you to dismiss.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Retrieve Windows Notifications With pywin32

2019-06-02 Thread Tim Roberts
On Jun 2, 2019, at 6:06 PM, DAI VU via python-win32  
wrote:
> 
> ]I am new to python/pywin32. I have a task to check/retrieve/click on some 
> notifications in the "Action Center" posted by a particular windows app. Can 
> I use python/pywin32 for this? Are there sample codes that I can take a quick 
> look? Also, where can I find the DOC for pywin32?

Well, here is the Microsoft repository of samples related to toast 
notifications and the action center.  The examples are all C# and JavaScript, 
but they can be translated.

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Notifications
 
<https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Notifications>

There are lots of APIs for creating notifications, but I'm not aware of APIs to 
manipulate and respond to those notifications.  Those notifications are there 
for a reason, and they are expected to be handled by a human user.  What kind 
of notifications are you trying to dismiss?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] connecting to labview executable

2019-05-12 Thread Tim Roberts
On May 12, 2019, at 12:53 PM, c.kristu...@hoc.net wrote:
> 
> I think what he is saying that he can connect to the LabView IDE but he
> cannot connect to the stand-alone executable once it is built. LabView
> is an interpreter which comes with a compiler to build stand-alone
> binaries.

Yes, you are right.  Do we know whether the standalone executable is SUPPOSED 
to act as a COM server?  Somebody somewhere would have to register it.  I would 
not be surprised at all if that only works with the IDE.  That's probably a 
question for the LabView support forum.


> Anyway, LabView can do socket comunication so I think this is the way do
> go rather than reading LabView controls via pywin32.

Agreed.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.



smime.p7s
Description: S/MIME cryptographic signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] connecting to labview executable

2019-05-12 Thread Tim Roberts
On May 9, 2019, at 11:50 PM, Kálózi Zsolt  wrote:
> 
> So this continously reads out the value from the frontpanel of the .vi, that 
> is called 'power'.
> Unfortunatelly this only works if the .VI is running in the LabView IDE. 
> That is okay for the test environment but not okay in the real environment.
>  
> I will have an .EXE file that was generated from the .VI, so I need to access 
> that one. How can I do that with this library? Because simply changing the 
> path to the executable path doesn't work.
> Under 'advanced' I also tried to enable and give a name to the ActiveX 
> server, when I generate the executable, and give that name to the Dispatch, 
> but that didn't work either.

I'm trying to interpret what you've said here.  Are you saying that the 
win32com.client.Dispatch statement only connects to LabView if your executable 
is already running?  If so, then all you should have to do is use os.spawn or 
subprocess.Popen to launch the executable.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.



smime.p7s
Description: S/MIME cryptographic signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] getvireference issue

2019-05-09 Thread Tim Roberts
On May 9, 2019, at 4:53 AM, Kálózi Zsolt  wrote:
> 
> I'm writing this mail by hoping someone could help. I have pywin32-224 
> installed on my computer. 
> The following code doesn't seem to work:
> import win32com.client
> 
> labview = win32com.client.Dispatch("LabView.Application")
> VI = labview.getvireference(r'Controller.vi')
> I get the following error:
> 
> AttributeError: ' instance at 0x43780248>' object has no attribute 'getvireference'

The actual spelling is GetVIReference.  Does that work?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] hook the left mouse button down event on any window

2019-03-30 Thread Tim Roberts
On Mar 29, 2019, at 8:39 PM, Zhao Lee  wrote:
> 
> import win32gui
> import win32ui
> import win32con
> 
> def onMousePressed(self):
> print('onMousePressed', win32gui.GetCursorPos())
> 
> def listener():
> windowHandle = win32gui.WindowFromPoint(win32gui.GetCursorPos())
> clickedWindow = win32ui.CreateWindowFromHandle(windowHandle)
> clickedWindow.HookMessage(onMousePressed, win32con.WM_LBUTTONDOWN)
> # print('-registerMouseEvent', clickedWindow)
> 
> while True:
> listener()
> time.sleep(8)
> 
> what is wrong and what's the good practice ?

I TOLD you what is wrong.  Let’s follow the flow.  Every 8 seconds you call 
listener.  It does the following, very quickly:

* Fetch the window under the cursor, assuming the cursor is over a window.
* Create a Python window object around that window handle
* Install a hook to catch button down messages for that specific window
* Function exits, the window object is destroyed, and the hook is uninstalled

Then you go back to sleep.  While you are alseep, there is no hook.  The only 
time you have a hook is the few milliseconds between your HookMessage call and 
when the function returns.

The right answer is to use a package like pyHook to install a global hook.  
This is exactly what it is for.

https://stackoverflow.com/questions/165495/detecting-mouse-clicks-in-windows-using-python
 
<https://stackoverflow.com/questions/165495/detecting-mouse-clicks-in-windows-using-python>
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.



smime.p7s
Description: S/MIME cryptographic signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] hook the left mouse button down event on any window

2019-03-29 Thread Tim Roberts

Zhao Lee wrote:
I originally posted the question here 
<https://stackoverflow.com/questions/55399565/hook-the-left-mouse-button-down-event-on-any-window>, 
please help ,thank you !



I want to hook the left mouse button down event on any window, my code 
as following :
|importwin32guiimportwin32uiimportwin32condefonMousePressed(self):print('onMousePressed',win32gui.GetCursorPos())deflistener():  
 windowHandle =win32gui.WindowFromPoint(win32gui.GetCursorPos())  
 clickedWindow =win32ui.CreateWindowFromHandle(windowHandle)  
 clickedWindow.HookMessage(onMousePressed,win32con.WM_LBUTTONDOWN)# 
print('-registerMouseEvent', clickedWindow)whileTrue:  
 listener()|


However , the |onMousePressed| function was never called when clicked, 
what is wrong ?


P.S. I know some similar projects such as PyUserInput 
<https://github.com/PyUserInput/PyUserInput>, mouse 
<https://github.com/boppreh/mouse>, pynput 
<https://pythonhosted.org/pynput/keyboard.html#monitoring-the-keyboard>, 
just want to know why my code didn't work.


Your code came across badly formatted, so I can't tell exactly what you 
wrote.  You aren't actually calling listener() from within a continuous, 
tight CPU loop, are you?  This function is going to get called thousands 
and thousands of times a second. This is very poor practice, and it's 
part of the reason these other modules exist.


You attach to an external window, install your mouse message hook, then 
your function exits, the window object is deleted, and the hook is released.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ExportAsFixedFormat's ValueError

2019-03-27 Thread Tim Roberts

Kaweit wrote:


i make a question:
doc.ExportAsFixedFormat(output, 
constants.wdExportFormatPDF,|Item||=||constants.wdExportDocumentWithMarkup, 
CreateBookmarks ||=||constants.wdExportCreateHeadingBookmarks)|
     but "ValueError",the argument was wrong.  Cloud you help me? I 
think I need a Win32com Docutment.


This is not a win32com issue, it is a Word issue.  And it would have 
been easier if you had told us that you were using Word instead of 
making us guess.  We don't know were "ExportAsFixedFormat" comes from.


Why didn't you cut-and-paste us the exact error message?  Did it tell 
you which argument was wrong?  What, exactly, is "output"? It would be 
helpful to see the code leading up to this as well.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] chapter 5 : implementing com objects with python

2019-03-26 Thread Tim Roberts

Benjamin McNeill wrote:


Hello,  I am trying to get this com server to work in VBA.  I can 
register and deregister the server but I can not call it from vba.  
Any suggestions?  I am using windows 10 and office 365 with python3.7.


Remember that the bit-size must match.  I don't actually know whether 
Office 365 is a 32-bit app or a 64-bit app, but your version of Python 
must match.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to get target of folder shortcuts

2019-03-18 Thread Tim Roberts

kurt wrote:

Hello, I'm trying to get the target filename of windows shortcuts.  The
code below works great for regular shortcuts, but errors out on "folder
shortcuts".
...
The code below works great for regular .lnk shortcuts, but folder
shortcuts give me:
[...]
 persistFile.Load(fname,STGM_READ)
pywintypes.com_error: (-2147024891, 'Access is denied.', None, None)

The quirk with folder shortcuts is they have some DOS attributes set,
which I suspect could be causing me trouble.  Is there, perhaps,
something I need to do to get my IPersistFile to ignore file attributes?


Your code works for me, although the SFGAO_FOLDER bit is not set for my 
folder shortcut.  If you do a "dir" of the folder where the link lives, 
what do you see?  Is it actually a .lnk file of about a kilobyte?


There are no DOS attributes on my folder shortcut.  What do you see?

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Performing ReplyAll to outlook email message

2019-03-15 Thread Tim Roberts

Ahmed Matar via python-win32 wrote:


I am trying to perform a reply all to an email message that I have 
passed into my python script.

...

#what I would like to do now is do a “Reply all” with my reponse being 
“ResponseToEmail”



Any ideas if this is possible?


Sure, it's possible, but you have to do it all "the hard way". Create a 
new message, copy the Receipts list into the new message, set your body, 
send it.  Not a lot of code, but it's a little tedious.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM Photoshop - Exception occurred

2019-03-09 Thread Tim Roberts
On Mar 8, 2019, at 9:08 AM, Ioannis Valasakis  wrote:
> 
> ...
> Currently, that this is the error I am getting and I can't seem to understand 
> why, as I've seen online examples using the exact same code and it works.
> 
> >>> desc.putReference(cTID("null"), ref) 
> >>> desc.putBoolean(cTID("MkVs"), False)
> >>> app.executeAction(cTID("slct"), desc, 3)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516, 
> in __getattr__
> ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Adobe 
> Photoshop', u'Illegal argument - argument 1\n- Required value is missing', 
> None, 0, -2147220262), None)

Different versions of Photoshop?  Could the “slct” action refer to a plugin 
that isn’t present on your Windows 10 system?

The key point is that this is almost certainly going to end up being a 
Photoshop issue, not a Python issue.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.



smime.p7s
Description: S/MIME cryptographic signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] adodbapi: paramstyle 'named' doesn't work as expected

2019-02-20 Thread Tim Roberts

Dennis Lee Bieber wrote:


The loop is looking for the end of the parameter name by looking for a
non-alphanumeric character. But your update command just... ends -- there
is no non-alphanumeric character after the name to terminate the loop.
INSERT syntax has a closing ) to terminate.

I WOULD consider this a subtle bug in the ADODBAPI code.


You are being too kind.  This bug is not subtle in any way. Python is so 
good at string parsing -- there must be a better way to write that.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Facing issue while connecting to alm via python

2019-01-29 Thread Tim Roberts

Neeraj Chhabra wrote:


I have one requirement, in which i need to connect to HP ALM and log a 
defect in jira using python. i tried to connect to alm through 
pywin32. but getting error. please check below code snippet and error -

...
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, 
None) During handling of the above exception, another exception 
occurred: ... pywintypes.com_error: (-2147221164, 'Class not 
registered', None, None)


It's likely that you are using a 64-bit Python but your ALM installation 
is 32-bit.  An in-process COM server has to match the bittedness of the 
caller.  Do you have the option of installing a 32-bit Python to see if 
it works from there?


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Bug - Passing byref an array to a com method interpreted as a single element

2019-01-21 Thread Tim Roberts

Tim Roberts wrote:

rv...@free.fr wrote:


It seems win32client do not interpret correctly the type expected by 
the COM server, here float() instead of pointer on an array of float.




That statement is not accurate.  The fault is not in win32client. The 
root of the problem is that the function definition in your type 
library is not COM-compliant.  There are rules that need to be 
followed in order for a COM interface to work seamlessly across 
languages, and you have violated those rules.  The proper way to pass 
an array is to use a SAFEARRAY. Your definition, for example, cannot 
possibly work in an out-of-process server, because there is no way for 
the marashaling code to know how much data to send across.  The 
GetValues case is doubly hopeless.  How can the server know how large 
the buffer is?  How can the client know how much data will be 
returned?  You are simply not allowed in COM to have that be assumed.


Win32client is quite correct in interpreting your definition as it 
does.  The fact that it works in VBA is an lucky accident.  If you 
want this to work reliably, you need to change the interface.


Having said all that, you may be able to do what you need with the 
"comtypes" module, which allows lower-level access to COM interfaces.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Bug - Passing byref an array to a com method interpreted as a single element

2019-01-21 Thread Tim Roberts

rv...@free.fr wrote:


I'm trying to translate a VBA application to Python. I cannot change 
the COM Server as its works also with others programs.
It seems I have a problem with win32com.client by passing an array of 
double to a COM method.


VBA allows to pass arrays to COM server byref on the first element of 
the array

...||

From typelib COM interface

|[id(0x0007), helpstring("Méthode GetValues")] HRESULT 
GetValues([in, out] double* pValues); # pointer on array of double 
[id(0x0008), helpstring("Méthode SetValues")] HRESULT 
SetValues([in] double* pValues);|


...

It seems win32client do not interpret correctly the type expected by 
the COM server, here float() instead of pointer on an array of float.




That statement is not accurate.  The fault is not in win32client.  The 
root of the problem is that the function definition in your type library 
is not COM-compliant.  There are rules that need to be followed in order 
for a COM interface to work seamlessly across languages, and you have 
violated those rules.  The proper way to pass an array is to use a 
SAFEARRAY. Your definition, for example, cannot possibly work in an 
out-of-process server, because there is no way for the marashaling code 
to know how much data to send across.  The GetValues case is doubly 
hopeless.  How can the server know how large the buffer is?  How can the 
client know how much data will be returned?  You are simply not allowed 
in COM to have that be assumed.



Win32client is quite correct in interpreting your definition as it 
does.  The fact that it works in VBA is an lucky accident.  If you want 
this to work reliably, you need to change the interface.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Making a COM server that accepts COM objects

2019-01-09 Thread Tim Roberts

Boylan, Ross wrote:

I have a Python 3.7, 32 bit, COM server and am calling it from 32 bit Office 
2010 in VBA.  I am attempting to pass some COM objects from VBA to Python.  The 
trace collector full output appears below, but I think the key clues are 
several messages like

in ._QueryInterface_ with unsupported 
IID {0003---C000-0046} ({0003---C000-0046})


Those are not important.  The COM framework is just probing to find out 
what extras you support.  0003-etc is IMarshal and 001B-etc is 
IStandardMarshal; both can be used to help in the RPC process.




and, later,
 rst = fedb.OpenRecordset("foo")
AttributeError: 'PyIDispatch' object has no attribute 'OpenRecordset'


You can't just pass an Access database object to another process and 
expect it to work.  The support pieces aren't there.  Thus, the crux of 
your problem is this:



 _reg_progid_ = "Fahy.BST"
 # for unknown reasons the inprocess server isn't working
 _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER


That's the problem you need to chase.  You need to be an in-process 
server if you want to share state with the original code.  What happens 
when you register yourself as in-process? Note that the registry has to 
look different for this.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] python win32com.client; reverse engineer sql server timestamp

2018-12-18 Thread Tim Roberts
On Dec 18, 2018, at 1:05 PM, Anrik Drenth  wrote:
> 
> Couple of good insights there. Would you have example python code that shows 
> the Unicode-to-ASCII conversion in action?
> 
> So 0x0189CF01  to 003F49 
> 
> The current code is written in Python 2.7, its selecting the data from SQL 
> Server and writing it into Access 97.
> As Access 97 is somewhat dated we want to get rid of this code and hand 
> responsibility back to the client.
> 
> The sql server timestamp field is a rowid.  It was used back in the day under 
> the mistaken assumption it was a datetime field.  It is not, subsequently the 
> field exists but has never been used.

Aha.  Here's my alternate theory, then.  I'll bet that field in the Access 
table is declared as "AutoNumber".  In that case, Access would be assigning its 
own unique row number to the field, totally ignoring the incoming field from 
SQLServer.  That would make a certain amount of sense, but you'd have to look 
at the other values in that field to be sure.

> We still have to re-produce the same exact same value in the field on the off 
> chance it is used by the clients system.

Don't you have the code that originally created those fields?  It is absolutely 
pointless for us to guess how this was done.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] python win32com.client; reverse engineer sql server timestamp

2018-12-17 Thread Tim Roberts
On Dec 17, 2018, at 5:20 PM, Anrik Drenth  wrote:
> 
> I'm looking for the mapping table / logic that will render sql server 
> timestamp values as win32com.client does.

OK, then why did you not tell us what the win32com.client does?


> I'm currently  importing a text file into Access. The text file contains a 
> column with a timestamp value which has been extracted from sql server.  The 
> values for the (Access String 50) column look something like 
> "0x0189CF01".

That's a 32-bit integer.  You need to be storing this as a 32-bit integer, not 
as a string.  Or, best of all, as an Access date/time datatype.  Exactly which 
data type in the SQL Server column?  How was the text file generated?  In 
virtually every case, SQL Server will export date and time columns as date time 
strings (that is, "2018-12-17".  How did you get a hex representation?
 

> Using VBA I want to convert these to the exact same value that win32com 
> creates.
> 
> In python (sample code below) the timestamp value is stored as an 8 byte, 
> bytearray.  Which then gets interpreted by Access.  

Which version of Python are you using?  You are taking binary data and shoving 
it through a Unicode-to-ASCII conversion.  That produces garbage.  That's not a 
string.  It's an integer.


> Below is a sample of how the sql server timestamp value is stored in Access:
> 
> SQL Server (Timestamp) | Access (Text 50) 0x0189CF01  |  003F49  
> 0x0189D001  |  003F69  0x01B54DFF  |  003F6D  
> 0x01F74701   | 003F4E  0x0189C003   | 003F70  
> So it tries to do a mapping, sometimes 1 to 1, sometimes not as page 5 of the 
> below link demonstrates 

Right.  You're producing garbage.  The "3F" in there is the "?" character, 
which means "this character does not exist in the current 8-bit code page".  
It's not a Unicode string, don't try to treat it like one.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to obtain printer HANDLE as int in Python

2018-12-10 Thread Tim Roberts

paolo bonatti via python-win32 wrote:
I'm trying to print PDF documents with pdfix sdk utilizing win32print. 
This PDF library requires printer HANDLE value as int directly not as 
a PyObject.


Is there any way to obtain printer HANDLE value in Python code?
(attached is a sample)



   hDC.CreatePrinterDC (win32print.GetDefaultPrinter ())


If that is getting you what you need, then

    win32print.OpenPrinter( win32print.GetDefaultPrinter() )

will get you the handle to that printer.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32api.FindFiles hangs

2018-12-06 Thread Tim Roberts

Jim Bell wrote:
Maybe it's not your installation of Windows that's messed up, but just 
a third party driver. Or someone has mis-configured something on the 
server.


This net share Z: drive: what's the technology / software that's 
behind it? Is it a standard Windows share, or a third-party driver? 
(If it's a standard Windows share, is it a Microsoft server doing the 
sharing?)


Yes, this is the right direction to go.  Some NFS implementations, for 
example, are far less robust than one would really like for the 
corporate environment.  You might also try temporarily disabling your 
virus scanner and see if that alters things.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32api.FindFiles hangs (was COM registration hangs up: 32 bit Python 3.7 on 64 bit Win 7)

2018-12-05 Thread Tim Roberts

Boylan, Ross wrote:


Is this some kind of string conversion issue?  My installation is borked?
Manual debugging statements show sys.argv[0] is 'BSTImport.py'.

win32api.FindFiles('BSTImport.py')
in a python 3.7 shell (32 bit) hangs.


That's quite bizarre.  The code for win32api.FindFiles is 
straightforward.  Is this a special directory, like a net share or 
something?  If you ask for *.py, is BSTImport.py in the list you get back?


Do you code in C?  You might code up a trivial C app to run a 
FindFirstFile/FindNextFile loop with the same parameters to see if the 
same thing happens.  Of course, I'm not sure what the next step would 
be, whether that worked or failed.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-20 Thread Tim Roberts

Glenn Linderman wrote:
Of course, the GetJob is decoding the structure properly... but its 
PyBuildValue parameter strings are much more complex than the 
PyArg_ParseTupleAndKewyords parameter strings, and there is mention of 
TCHAR in the JobToPy, but not in the PyToJob, so that makes it further 
seem like my speculations above might have some chance of being the 
problem.


I should not have scoffed at your speculation, because your analysis was 
correct.  The win32print code is calling SetJobW, which expects Unicode, 
but the JOB_INFO_1 structure is filled with ANSI strings.  That's a very 
nasty bug.  I'll file a bug report.


In the meantime, I'll fix up my little C++ example to do the job for you.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-20 Thread Tim Roberts

Glenn Linderman wrote:


I looked at the win32print.cpp file. There were lots of 
Python-internals stuff there that I don't really follow well. I didn't 
see anything obviously wrong, but I got to wondering about the code 
that builds the structure... it puts in UTF-8 text strings (which 
would be same as ASCII in the cases I'm considering, but what if 
someone has a non-ASCII printer name, or document file name, or ???). 
And I'm sure the A version of the Windows API probably is happy with 
ASCII, but does the 64-bit compilation call the A version of the 
Windows API or the W version?


32 vs 64 makes no difference here.   SetJobA always expects 8-bit 
strings, SetJobW always expects 16-bit strings.  SetJob maps to one or 
the other based on the absence or presence of #define UNICODE.  The 
routines that convert Python strings to zero-terminated strings will do 
the right thing.



And would the W version be happy with ASCII? Or would that produce an 
1804 error?


If you pass ASCII strings to the W API, it just means the strings are 
interpreted as garbage.  The name will not be found.  It shouldn't cause 
1804.


I went to ReactOS and looked at the source code for SetJob. 
ERROR_INVALID_DATATYPE is returned for exactly one reason: the pDatatype 
value is not in the valid list of datatypes for the print processor for 
this job.  There's no reason for that; your structure says "NT EMF 
1.008", which is almost always valid.


This had to work at some point.  All of these things get tested. I just 
don't know what would have changed.  If I get motivated (I've already 
spent too much time on this ;), I'll see if I can get your script to 
fail here.



And then of course, I've no idea what compilation parameters were 
used, either for your program (which works), or for win32print.cpp 
(which maybe doesn't).


I built mine for non-Unicode.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-19 Thread Tim Roberts

Glenn Linderman wrote:


I've not coded up the equivalent C program, as I don't have a C 
compiler installed here, and haven't done any C coding for 8 or 10 years.


Were you able to reproduce the problem, or is your error analysis 
based on code reading?


I looked at the code.  Plus, I recognized that 1804 is a Windows errors 
code, not a Python error.  Let me see if I can write up a C++ test that 
would be useful for you.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] why do I get error 1804 from win32print.SetJob?

2018-11-16 Thread Tim Roberts

Glenn Linderman wrote:


Here is the code I'm using. Note that the variables js and rename are 
the control variables if you need to tweak this to run in your 
environment. js contains a substring of an existing document name, and 
the idea is that the document name of the first matching spool job 
having a document name containing that fragment will be changed to the 
content of the rename variable by the code.

...
Here is the error I'm getting:

{'JobId': 27, 'pPrinterName': 'HL6180dw', 'pMachineName': 
'STEPHEN', 'pUserName': 'Glenn', 'pDocument': 'duh', 'pDatatype': 
'NT EMF 1.008', 'pStatus': None, 'Status': 8210, 'Priority': 1, 
'Position': 0, 'TotalPages': 22, 'PagesPrinted': 0, 'Submitted': 
pywintypes.datetime(2018, 11, 14, 21, 1, 27, 882000, 
tzinfo=TimeZoneInfo('GMT Standard Time', True))}

Traceback (most recent call last):
  File "D:\my\py\spool.py", line 109, in 
    win32print.SetJob( phandle, res[ 1 ], 1, jobinfo, 0 )
pywintypes.error: (1804, 'SetJob', 'The specified datatype is invalid.')


That's very odd.  This is not from the Pywin32 code --  it has correctly 
parsed your structure.  That error is coming from the SetJob API itself 
(ERROR_INVALID_DATATYPE).  As an experiment, have you tried coding up 
the exact same sequence as a C program to see if you get the same error?


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Exception '-2147221164' while using win32com.client.Dispatch("SAPI.SpVoice")

2018-10-10 Thread Tim Roberts
On Oct 10, 2018, at 1:25 PM, Sai Ram  wrote:
> 
> We use Nuance's Vocalizer Expressive for voice and sapi5.dll. Also, we modify 
> the "Windows registry" to refer to this dll.

What does that mean?  Ordinarily, you would just register the DLL with regsvr32 
once and for all.  Are you making registry changes on the fly?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Exception '-2147221164' while using win32com.client.Dispatch("SAPI.SpVoice")

2018-10-10 Thread Tim Roberts

Sai Ram wrote:


   I really did not know that this value would make difference. 
Apologies for the vague question. The actual exception is "-2147352567".


That's 0x80020009, or DISP_E_EXCEPTION.  That's really telling you to 
refer to the other code for the details.



Also, we have around 5000 test scripts. Out of these, around 300 test 
scripts fails with this exception. So, I do not doubt any system 
issues here.


Did you actually install the SAPI SDK?  Do all 5,000 of the scripts use 
SpVoice?  Do the 300 that fail use some particular subset?  Are they all 
either 32-bit or 64-bit apps?


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Exception '-2147221164' while using win32com.client.Dispatch("SAPI.SpVoice")

2018-10-10 Thread Tim Roberts
On Oct 9, 2018, at 8:03 AM, Sai Ram  wrote:
> 
>We are using "win32com.client.Dispatch("SAPI.SpVoice")" for TTS to our 
> target device from a Windows 7 desktop. We are seeing many of these 
> exceptions: "Exception '-2147221164'". 
> Is there a fix for this? Basically, wanted to know the reason for this 
> exception and the fix for this.

COM exceptions are listed in hex.  -2147221164 is 0x80040154, which is 
E_CLASSNOTREG.  Have you installed SAPI 5.1?  It's not built-in.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM: control menu bar

2018-09-30 Thread Tim Roberts
On Sep 30, 2018, at 6:25 AM, Emre CETIN via python-win32 
 wrote:
> 
> Hello James. Thank you for your advice. I ran Spy++. At the logging options I 
> selected the menu bar portion of the other program. I selected WM_COMMAND 
> only and then chose  all "Additional Windows" (except for the All Windows in 
> System). Then I clicked one of the menu items I wanted: Edit | Select All. It 
> provided me with the following line: WM_COMMAND wNotifyCode:0 (sent from a 
> menu) wID:57642.
> 
> How can I use this class ID (57642) in Python to act as if it was 
> clicked/pressed?

That's not a class ID, it's a window ID.  You can trigger that by sending the 
exact same message you saw here.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Writing event handlers

2018-08-30 Thread Tim Roberts

Kairen Tan wrote:


I’m trying to write some python to consume events from an Event 
Handler….without much success.


I’m using a class created using makepy, and on inspecting the file, 
there is a block of commented code like:


# Event Handlers
# If you create handlers, they should have the following prototypes:
#def OnBeforeOpen(self, oRecord=defaultNamedNotOptArg):
#def OnBeforeSave(self, oRecord=defaultNamedNotOptArg, 
bCancel=defaultNamedNotOptArg):

#def OnAfterSave(self, oRecord=defaultNamedNotOptArg):
#def OnBeforeDelete(self, oRecord=defaultNamedNotOptArg, 
bCancel=defaultNamedNotOptArg):

#def OnCloseRecord(self):
#def OnAfterDelete(self, lDatabaseID=defaultNamedNotOptArg, 
sImportID=defaultNamedNotOptArg):


*My question is simply, how do I implement this? *
*
*
I’ve tried using win32com.server.register.RegisterServer, but I’m 
stumped as to what comes after that.


It would have been helpful if you had told us what server you were 
trying to work with here.


You don't need to register yourself as a server.  Registration is only 
needed if someone else is going to look for your object by its CLSID, 
but that's not the case here.  There's really no such thing as an "event 
handler" in COM.  I'm guessing that the server you're working with wants 
you to hand it a COM interface, and it will call methods of that COM 
interface when certain events occur.


So, you need to use the magic _reg_ names so that win32com recognizes 
you as a COM object, but after that, all you should need to do is create 
an instance of your object, and pass it to whatever method your server 
uses to register the callback object.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Reg. taking folder ownership

2018-08-27 Thread Tim Roberts

Goku Balu wrote:


My use case is this. Folder1 is created by Admin1 and ACL is set by 
Admin1. Now Admin2 wants to change the ACL. I think we have two 
options here

1) Take folder ownership and the do the changes
2) Take elevated privileges for Admin2 account and add/remove ACL 
entries (Similar to "Run as Administrator" and using icalcs in cmd)


I'm trying to solve this with the first approach. After Googling 
around, here is the code I'm trying to run for taking ownership from 
Admin1 and assign it to Admin2.


The Windows file permission ecosystem makes my head hurt, so I'm going 
to avoid answering your exact question, but I would point out that 
Admin1 can change the ACL to give Admin2 the right to change the ACL.  
In the file permission dialog, that's the "Change permissions" right.  
In code, it's the "WRITE_DAC" file permission.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] LNK4197 error building c++ extension

2018-08-21 Thread Tim Roberts
On Aug 21, 2018, at 5:59 AM, Robin Becker  wrote:
> 
> C:\code\hg-repos\taggstate\REPOS\aggstate>ls build\temp.win-amd64-2.7\Release
> _aggstate.exp   _aggstate.obj   agg25
> _aggstate.lib   _aggstate.pyd.manifest
> 
> digging a bit deeper I find taht the problem comes from the exp file and the 
> linker /EXPORT. It seems that the /EXPORT:init_aggstate can be suppressed for 
> this build and the warning disappears, but something (I assume the exp) 
> supplies the export. Certainly the pyd appears to work.

Yes, the /EXPORT linker command is just an alias for the .def file.  You need 
to mention the entry point EITHER (1) in a .def file, (2) in a /EXPORT, or (3) 
with a __declspec(dll export).  One and one only.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using DirectShow API to access webcam

2018-08-17 Thread Tim Roberts

Joe wrote:


thanks for your helpful answer and the explanations.
Following up on your comment on http://videocapture.sourceforge.net/
I found that there is jaraco.video, which seems to be
"a port of the VideoCapture module in pure Python using ctypes and 
comtypes."

(https://github.com/jaraco/jaraco.video)

It is using a 'DirectShow.tlb' file, whatever that is, to get the
definitions into comtypes.


A TLB file is a "type library".  It is a compiled version of the IDL for 
a set of COM interfaces.  IDL is modified subset of C++ that is used to 
declare the functions within a COM interface, their parameters, and 
their types.  It is intended to be  a language-independent way to define 
the functions within an interface.


Looks like you're on your way.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] LNK4197 error building c++ extension

2018-08-17 Thread Tim Roberts

Robin Becker wrote:
I am not a great C++ person so as I am building my first C++ extension 
I am seeing this error which I don't understand


> _aggstate.obj : warning LNK4197: export 'init_aggstate' specified 
multiple times; using first specification
>    Creating library build\temp.win-amd64-2.7\Release\_aggstate.lib 
and object build\temp.win-amd64-2.7\Release\_aggstate

> .exp


It's not an error, it's a warning.  And this has nothing to do with 
C++.  Is this your own private project, or is it one I can go look up?



I looked in the preprecessor output(_aggstate.i) and see this single 
occurrence of aggstate_init



#line 1191 "_aggstate.cxx"
extern "C" __declspec(dllexport) void init_aggstate(void)
{
 aggstate_init();
}


is this some feature of C++ or is there a real issue here?


My guess is that you have listed "init_aggstate" in the ".def" file that 
lists the exported functions.  That's the first export specification.  
You are also using __declspec(dllexport) in the function definition, and 
that's the second export specification. When you use 
__declspec(dllexport), you don't need the ".def" file.


--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using DirectShow API to access webcam

2018-08-16 Thread Tim Roberts

Joe wrote:


I have a question an hope you can help me. I am trying to control a 
UVC webcam

using the DirectShow API, but could not get anything to work.

The question is already posted on StackOverflow:

https://stackoverflow.com/questions/51843523/accessing-webcam-via-directshow-using-com-with-python 



I am not familiar with using CLSID, IID so playing with the few 
examples I found

got my nowhere:

# IID_IAMVideoProcAmp is C6E13360-30AC-11d0-A18C-00A0C9118956
from win32com.client import Dispatch
from win32com.client.gencache import EnsureDispatch,GetClassForProgID, 
GetClassForCLSID, GetModuleForProgID, GetModuleForCLSID


iid = '{c6e13360-30ac-11d0-a18c-00a0c9118956}'

print(GetClassForCLSID(iid))
print(GetModuleForProgID(iid))
print(GetModuleForCLSID(iid))

CLSID = IID('{c6e13360-30ac-11d0-a18c-00a0c9118956}')
print(CLSID)

print(Dispatch(CLSID))

pywintypes.com_error: (-2147220990, 'CONNECT_E_CANNOTCONNECT', 
None, None)


Could someone of you point me in the right direction and maybe put
together a few lines to get me started?


I am not entirely convinced it is possible to control DirectShow from 
Python, but I'll give you some general information.


An "interface" in COM terms, described by an IID, is just a set of 
functions declarations.  It defines the things you can do with an 
object, but it is not actually an object.  A "CLSID", on the other hand, 
defines a COM object.  The CLSID doesn't tell you what the object can 
do, it's just a way of creating an object.  Once you have used a CLSID 
to create an object, you can ask it for an interface.


So, you can't just create IID_IAMVideoProcAmp.  You have to ask an 
existing object for its IAMVideoProcAmp interface.  You would create 
your camera object, and then query the camera object for IAMVideoProcAmp.


Creating a DirectShow graph is a multi-step process.  You create a 
filter graph, you add your camera to the graph, you tell the graph to 
render the stream (which means it automatically fills in the other 
filters), and you control it.  Here is some sample code that does this:


    https://gist.github.com/dust8/3890196

This is actually more complicated than it needs to be, because it's 
trying to handle TV devices with tuner and audio filters as well. You 
don't need that.  Once you have a device from VideoInputDeviceCategory, 
you don't need the video decoder or the audio.  You can just render the 
graph at that point.


Alternatively, it looks like this package might be more applicable:

    http://videocapture.sourceforge.net/

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.




smime.p7s
Description: S/MIME Cryptographic Signature
___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Issue on getting activesheet on win 8 and Win 8+ OS systems

2018-07-24 Thread Tim Roberts
Aravind wrote:
> Issue on getting activesheet on win 8 and Win 8+ OS systems
>
>    We are facing issues on getting active sheet values while running
> python3 code using win32.
>
>  
>
> Problem occurs only running on windows 8 and Windows 8+ OS PC's.
>
>  
>
> Here I attached the screenshot of my error and piece of code which i
> execute.
>

Are you actually opening a file?  Does the file open correctly?  Is it
possible the workbook isn't open yet by the time you query it?  Are you
running as the logged in user, or is this a service?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using WMI to listen to window creation and destruction

2018-07-18 Thread Tim Roberts
Ram Rachum wrote:
> "Are you really looking to monitor the creation of new top-level
> windows, which means the creation of new processes?"
>
> Does that apply to explorer windows? (i.e. when you open a new
> folder.) Because that's what I'd like to listen to.

No.  Those are just subwindows opened within the Explorer process.

What are you REALLY trying to do?  What's the overall goal?  Explorer
has an extensive shell extension interface that let you participate in
many actions, but opening new folders is not one of them.

    https://msdn.microsoft.com/en-us/library/windows/desktop/cc144067

Remember, you can open a new folder without opening a new window

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using WMI to listen to window creation and destruction

2018-07-18 Thread Tim Roberts
Ram Rachum wrote:
>
> I'd like to use the `wmi` module to be notified on the events of a
> window being created or destroyed. Is this possible? I looked at the
> tutorial and cookbook and could find many interesting things, but not
> that.

I don't think WMI provide information about windows, although admittedly
I've underestimated WMI in the past.  If you have evidence to the
contrary, please correct me.

However, I'm pretty sure what you said is not really what you meant. 
Remember that every control, every button, every textbox, every icon --
really, every visible thing is a separate window.  You'd get thousands
of hits.  Are you really looking to monitor the creation of new
top-level windows, which means the creation of new processes?  Because
WMI DOES provide information about processes.

If you do want to find out about windows, you'd need to use a Windows hook.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dispatch multi instance of the some com server

2018-07-17 Thread Tim Roberts
Matteo Boscolo wrote:
> we have an issues with our com server (exe) .
>
> we dispatch it with dispatchEx to be sure that every time we dispatch
> it a new instance of the com server will be created.
>
> but it dose not work.
>
> when we dispatchex it the program get the live instance instead of
> creating a new one.
>

Why?  I know you weren't asking for a design review, but it seems like a
serious design flaw if you cannot handle multiple requests with a single
instance.  That's a big part of COM -- an easy way to have a server that
handles multiple clients.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to get actual FILETIME from PyTime

2018-06-28 Thread Tim Roberts
Rob Marshall wrote:
> Thank-you. I also figured out that if I want the "actual" FILETIME I can do:
>
>>>> get_filetime = lambda i: ((i & 0x),(i - (i & 0x))>>32)
>>>> get_filetime(13174227726000)
> (905689856L, 30673639L)
>>>> low,high = get_filetime(13174227726000)
>>>> (high<<32)+low
> 13174227726000L

A FILETIME is just a 64-bit integer, and you can always pass it to APIs
that way.  The only reason the structure has it in two parts is because
the Microsoft C compilers of the early 1990s did not have a 64-bit type.

Another way to do the unpacking is
    struct.unpack('II',struct.pack('Q',i))
and the reverse:
    struct.unpack('Q','strict.pack('II',low,high)[0]

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to get actual FILETIME from PyTime

2018-06-27 Thread Tim Roberts
Rob Marshall wrote:
> Is there a way to get the actual FILETIME value from a PyTime?

PyTime isn't actually a type.  It's just a set of conversion routines
that produce standard datetime values.  So, your question really is "how
to convert a datetime to a Windows FILETIME"?  And here's a Python
module that can do that:

   
https://gist.github.com/Mostafa-Hamdy-Elgiar/9714475f1b3bc224ea063af81566d873

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] opening a url in browser, when user clicks on windows notification

2018-06-17 Thread Tim Roberts
On Jun 16, 2018, at 2:52 PM, santosh sahu  wrote:
> 
>I want to open a pop up notification on the web browser when a user 
> clicks on the pop up notification. Right now I am able to show the 
> notifications on windows10. Below is the link to the question asked on 
> .Stackoverflow question 
> <https://stackoverflow.com/questions/50891538/open-contents-in-a-browser-when-user-clicks-on-a-notification-in-python>
>Could you please provide the api's and any documentation which would 
> solve the problem.

I don't understand what you're asking.  You have a script that shows a pop-up 
desktop notification.  There's nothing web-based here at all.  How is a browser 
getting involved?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dispatching something that requires elevation

2018-06-11 Thread Tim Roberts
Simon McConnell wrote:
>
> Sorry, I'm not sure what you mean by spawn the COM access in a
> separate process.  This is my first time dabbling with COM objects.

All I meant was creating a second Python process to do all the COM
stuff.  I think you said that the COM access works from a non-elevated
process, but that you need elevation for other parts of your app.  Thus,
if you put the COM access into its own (non-elevated) process, you might
be able to make things work, although you'd need a way to communicate
between your two processes.  Still, it doesn't make sense to me that the
COM server would care that its client was elevated.  There are aspects
to this that I don't understand.


> Is there a neat way to kill all the tasks that you've started when
> your script fails without hitting the application's Quit call?

This is all up to the COM server.  There's no COM-specific magic here.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dispatching something that requires elevation

2018-06-09 Thread Tim Roberts
On Jun 8, 2018, at 10:11 PM, Simon McConnell  wrote:
> 
> I am trying to dispatch a COM interface of a program that is set to "Run as 
> Administrator" in the Compatibility Settings of its properties.  Running the 
> script w/o elevation results in a 'requires elevation' error.  Running the 
> script with elevation results in a 'server execution failed' error, which I 
> understand to be "I can't find that thing". 

No, actually.  That's 0x80080005, which is a DCOM "access denied" error.  Are 
you quite sure this account has the privileges needed to run this software?


> Removing the "Run as Administrator" from the Compatibility settings and 
> running the script w/o elevation works, but unfortunately, this program needs 
> to be run as administrator.

So, are you saying you don't need elevation to call this server, you only need 
it for other parts?  Can you spawn the COM access into a separate process?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] get MAPI session from OOM

2018-05-31 Thread Tim Roberts
On May 30, 2018, at 11:23 AM, ckk...@hoc.net wrote:
> 
> 
> Any ideas? Do you think it will help to do a fresh install of office 2016?

In addition to just installing Outlook, have you configured Outlook?  You can't 
access MAPI unless you have incoming and outgoing servers configured and 
authenticated.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Wait for a window with a specified title

2018-05-27 Thread Tim Roberts
On May 27, 2018, at 10:19 PM, Ram Rachum <r...@rachum.com> wrote:
> 
> Oh, that sounds heavy. I guess I'm back to polling. Any idea how to do this 
> with polling? 

It would be easy with polling.  You'd use EnumWindows to go through the list of 
all top-level windows, GetWindowText to get the window title, 
GetWindowThreadProcessId to convert the window handle to a process ID.

You may not actually need the process ID.  You could just send a WM_CLOSE 
message to the window.  Unless the process is trying to protect itself, that's 
usually enough.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Wait for a window with a specified title

2018-05-27 Thread Tim Roberts
On May 27, 2018, at 6:36 AM, Ram Rachum <r...@rachum.com> wrote:
> 
> I'd like to use the `wmi` module to detect when a window with the title "Foo 
> Bar" was created, and then kill the process that created this window. Is this 
> possible?

Not with WMI, no.


> (I can do the killing without `wmi`, I just need to ID the process.)
> 
> Note that I don't want to be periodically polling for that window, I want to 
> be listening to an event so there wouldn't be a big delay.

I don't know how much overhead you are willing to impose, but you can always 
install a WH_CALLWNDPROC window hook and look for WM_CREATE messages.  That 
injects a DLL into every process in the system, so I'm not convinced it can be 
done with Python.  You may need to write a C++ DLL and have it communicate with 
your Python process.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] get MAPI session from OOM

2018-05-26 Thread Tim Roberts
On May 26, 2018, at 5:21 AM, ckk...@hoc.net wrote:
> 
> on a 64bit windows 7 machine with pywin32 221 I used to get a pointer to the 
> MAPI session like this
> 
> outlook.GetNamespace('MAPI').Session.MAPIOBJECT.QueryInterface(mapi.IID_IMAPISession)
> 
> on a fresh windows 10 machine with pywin32 221 this fails with
> 
> pywintypes.com_error: (-2147467259, 'Unknown error', None, None)

Is this a fresh Windows 10 machine that includes a copy of Microsoft Outlook?
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] large buffer with GetOpenFileNameW

2018-05-24 Thread Tim Roberts
Andrew Ziem wrote:
> When I select a few files, the dialog works, but when I select many
> files, I get the following error. Do you have any advice?
>
> error: (12291, 'GetOpenFileNameW', 'No error message is available')
>
> Error 12291 is FNERR_BUFFERTOOSMALL

Yes.  The code in win32gui.i only allocates a buffer of 1,024
characters.  If you select more than that, you'll get FNERR_BUFFERTOOSMALL.

There may be a slimy way to work around this.  The code allocates the
larger of 1024 characters or the size of the File parameter.   You could
try something like
    win32gui.GetOpenFileName( None, File='\x00' * 2048, Flags=... )

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM Automation: Problem Accessing Property of Object

2018-05-22 Thread Tim Roberts
Emre CETIN wrote:
>
> Finally I got it to work! Here it is:
>
> |importwin32com.client srf
> =win32com.client.gencache.EnsureDispatch('Surfer.Application')Plot=srf.Documents.Add(1)srf.Visible=TrueMapFrame1=Plot.Shapes.AddImageMap(GridFileName="C:/test.grd")ImageLayer1=MapFrame1.Overlays(1)ImageMap1
> = win32com.client.CastTo(ImageLayer1, "IImageLayer") # the property
> was under IImageLayer ImageMap1.ShowColorScale = True|
>

For future maintenance purposes, you might consider changing the names
to match the interfaces:

    Shape1 = MapFrame1.Overlays(1)
    ImageLayer1 = win32com.client.CastTo(Shape1, "IImageLayer" )

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM Automation: Problem Accessing Property of Object

2018-05-22 Thread Tim Roberts
Emre CETIN via python-win32 wrote:
> Hi, I've been looking for a solution to this question for some time
> now. Hopefully you could help me out. There's a program (Golden
> Software Surfer) that I have successfully automated using Python COM.
> I normally am able to control every portion I need. The part I have
> trouble accessing is under its "Property Manager". Even though I am
> using the description provided in the software's documents & help
> files I get an error saying:
>
> AttributeError: ' instance at 0x2327715907232>' object has no attribute 'ShowColorScale'
>
> "ShowColorScale" is just an example of one property/method in the
> Property Manager window.
>
> Here is the example code I have been working with:
> |importwin32com.client srf
> =win32com.client.gencache.EnsureDispatch('Surfer.Application')Plot=srf.Documents.Add(1)srf.Visible=TrueMapFrame1=Plot.Shapes.AddImageMap(GridFileName="C:/test.grd")ImageLayer1=MapFrame1.Overlays(1)ImageLayer1.ShowColorScale=True#
> this is where i get the error|

The problem here, I think, is that ShowColorScale is a property of the
IContourMap interface, but you've been given an IShape interface.  One
of the issues about COM is that some objects implement many different
interfaces, and you have to know which interface to ask for to get the
methods and properties you want.

The answer, as the old poster suggested, is to query the IShape object
for its IContourMap interface.  It shouldn't be very much more
complicated than this:

    ImageMap1 = ImageLayer1.CastTo( "IContourMap" )
    ImageMap1.ShowColorScale = True

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Raise exception for printers

2018-05-02 Thread Tim Roberts
Schoeni, Yann wrote:
>  
>
> I’m trying to get error informations from my printer.
>
>  
>
> The job is sending from a web application, the application use the php
> function « Shell_exec » to call the python CLI and passe the arguments
> to the python script.
>
>  
>
> Anyway, I first tried to raise an exception if the printer isn’t turn
> on, but it’s harder than I thought, is there an easy way to do it ?
>
>  
>
> I tried to do it by using the command « GetPrinter » but nothing seems
> to point the power state of the printer.
>

The "Status" value tells you some of that information.  The bits are
defined here:
    https://msdn.microsoft.com/en-us/library/cc244854.aspx

Power state is a tricky thing for the system to handle.  The spooler
wants to allow you to submit print jobs even if the printer is off or
offline, because it will probably come back at some point.  I suspect
you will find PRINTER_STATUS_SERVER_OFFLINE in that case.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Wait for process to be started

2018-04-25 Thread Tim Roberts
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, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Service stucks in Starting state

2018-04-10 Thread Tim Roberts
k3...@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, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] More info about Microsoft Foundation Classes (MFC)

2018-03-29 Thread Tim Roberts
Thomas Pietrowski wrote:
> Ok, so basically the same I know from Linux.
> But how likely is it that Python 2.7.14 (which is currently the latest
> version) is linked against old libraries?
> Isn't the Python Foundation updating their build system regularly, too?

No.  In the past, the policy has been whatever build system is used for
2.7.0 will be used for all 2.7.x releases.  If they upgrade their Visual
Studio, then all users have to upgrade, too, and in the Windows world
that costs money.


> At the moment I'm quite convinced that the choice of an MFC version
> does not depend on Python, but on which version you built PyWin32.
> However, this is only my current feeling.

Right.  The core interpreter has no UI, and does not link to MFC.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] More info about Microsoft Foundation Classes (MFC)

2018-03-29 Thread Tim Roberts
Thomas Pietrowski wrote:
>
> I have general questions about MFC and hope you can answer them.
> When compiling PyWin32 for Py2.7 and Py3.x I get successful builds,
> but setup.py can't find the MFC libraries,
> which are specified here:
> https://github.com/thopiekar/pywin32/blob/master/setup.py#L1059
> for Python 2.7, Python 3.3 and Python3.4. This happens while using
> Appveyor and I contacted them about these "missing" files.
> One of the developers contacted me back and asked, whether mfc90*.dll
> is really needed for Python2.7.
> I think the question is quite eligible: Why are exactly these versions
> of MFC libraries strictly specified here?
> Isn't it possible to take the latest version, which is available?
> (Which is there for Python3.5 and 3.6.)

No.  It may not be obvious, but Python itself it entirely implemented in
a DLL.  (Note that the "python.exe" command is only a couple dozen
kilobytes.)  That DLL links to the dynamic version of the C run-time
library.  To avoid conflicts in shared state and such, all of the DLLs
it calls must either use a static C run-time library, or the same
dynamic version that Python itself uses.  The same applies to MFC.  When
an application or DLL links with MFC, it links to a specific version
(e.g., mfc90.dll).  You can't substitute another.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Future of PyWin32

2018-03-28 Thread Tim Roberts
Thomas Pietrowski wrote:
>
>
> (2) Syntax fixes and code-style.
>
> If I'm not wrong I saw mixed usage of tabs, 2-whitespace and
> 4-whitespace indents. Of course, I can be wrong and we are using
> 4-whitespaces everywhere, but I remember that I saw files using tabs
> and 2-whitespaces.
> It is boring work, but I can imagine, that people, who see this mixed
> usage, might get frightened.
> Also when it comes to code-style I would like to make everything well
> ordered. Eg. splitting long lines and splitting multiple options, so
> you can read the code without scrolling vertically too much.

Remember that much of PyWin32 is automatically generated.  Automatically
generated code is almost never pleasant to read.


> (3) Self-explaining variable names
>
> Some variables are using abbreviations. Instead, I would like to use
> full words, so the code is readable like a written book. Personally, I
> like this a lot because the source actually tells you what it is doing
> without any guesses.

Again, much of PyWin32 is automatically generated from the Win32 C API. 
The names need to match the API, as terse as they may be.

I am sympathetic to your plea, but renaming efforts like this are
fraught with dangers.  It's awfully easy to cause duplicates or screw up
the comments through an overactive search-and-replace.


> (6) Focusing more on Python3 compatibility
>
> The end of life of Python2 is at 2020 and therefore I would suggest
> investing time into making the code compatible to Python3 asap.

PyWin32 has been Python 3 compatible for many years.  To what are you
referring?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Get errors 7000 and 7009

2018-03-26 Thread Tim Roberts
Chang Dacool wrote:
>
> The service will fail to start when we reboot the OS in some
> computers, when this happens we will get error code 7000 and 7009 in
> the event viewer.
> 7000: The ServiceName service failed to start due to the following error:
> The service did not respond to the start or control request in a
> timely fashion.
> 7009: A timeout was reached (3 milliseconds) while waiting for The
> ServiceName service to connect.
>
> We checked our program, the Service timeout was before launching our
> program.
>

I can't tell what you mean.  Are you saying your service sometimes takes
more than 30 seconds to launch?  If so, then you need to figure out why
it takes so long.  If you are waiting for some event during your
startup, perhaps you can reorganize your code so that you defer some of
your initialization until after you enter the main service loop.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] com_error creating VSS shadow copy (running as windows service)

2018-03-26 Thread Tim Roberts
Gerardo García Urtiaga wrote:
>
>
> We have an application that launch a VSS (volume shadow copy), when
> the application is running as administrator user, the shadow copy is
> made correctly, but when the application is running as windows service
> the application has a crash:

Under what user are you running the service?  If you are using
LOCAL_SYSTEM, then you should have administrator privilege, but if you
are using a regular user, then you do not.


> com_error: (-2147221020, 'Sintaxis no v\xe1lida', None, None)
>

That's MK_E_SYNTAX, meaning the string could not be parsed in the
current context.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com + Brother Printer + Django

2018-03-25 Thread Tim Roberts
On Mar 23, 2018, at 9:44 AM, Scott Vitale <sc...@spigotlabs.com> wrote:
> 
> I'm looking for some win32com help... I have a simple Python script that 
> creates a `Dispatch` object for a `bpac.Document` type (it's a Brother 
> printer SDK class).  It works perfectly fine in a standalong script, but as 
> soon as I attempt to call this code from Django, it hangs on creating the 
> `Dispatch` objectso bizarre.
> 
> I've tried calling `CoInitialize` in a variety of ways, no difference in 
> behavior.
> 
> The other oddity is that I can create `bpac.Printer` objects with no issue.  
> It's only the `bpac.Document` type that hangs.  Unfortunately I don't have 
> access to the library source and I'm not sure how to debug why it's hanging.

How are you running your Django app?  Is it running as a service?  Is it 
networked, or directly connected?  Microsoft does not recommend printing from 
Windows services, in parts because of security considerations.  Your service is 
running as a special Windows user (unless you've configured it), and that 
special user needs permissions to use the printer.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Advice about usinf win32com

2018-03-20 Thread Tim Roberts
Marchand, Pascal wrote:
>  
>
> I'm trying to discuss with a Zebra RFID/bar code scanner using the WMI
> provider as recommended in dev guides, it runs fairly well with
> properties, I got method names and parameters too, but I didn't reach
> to make run method with byref parameter e.g. method(inpar, outpar)
> both parameters are strings (xml message), the function returns a
> status code correctly, see code below.
>

Python cannot do "out" parameters at all.  In the win32com world, when a
call has one "in" and one "out" parameter, instead of this:
    status = function( in, out )
it gets written like this:
    (status, out) = function( in )

There are some cases when the win32com machinery can't detect that, but
usually it works.  Give that a shot.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] pywintypes.error: (5, 'RegSetValueEx', 'Access denied')

2018-03-15 Thread Tim Roberts
Robin Kluth wrote:
>
> I use Python 2.7 on win10 and pywin32 223. I want to log messqages to
> the EventLog:
>
> dllname = os.path.dirname(__file__)
> ntl = NTEventLogHandler("Python Logging Test", dllname=dllname)
> logger = logging.getLogger("")
> logger.setLevel(logging.DEBUG)
> logger.addHandler(ntl)
>
> logger.error("This is a '%s' message", "Error")
>
> But I get:
> ...
> pywintypes.error: (5, 'RegSetValueEx', 'Zugriff verweigert')
>
> If I run the script with Admin privs, it is working.
>
> How to log as "normal" user? Am I missing something?

You can't.  If you want to log to the event log, you'll need
privileges.  Each app must register as an "event source".  Doing so
requires writing to the HKEY_LOCAL_MACHINE part of the registry, and
write requires admin privileges.

Technically speaking, it would be possible to register that source once
in an elevated process and then use it without re-registering, but the
current code does not support that.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel / Word: setting properties

2018-03-02 Thread Tim Roberts
On Mar 2, 2018, at 12:07 AM, Niemann, Hartmut <hartmut.niem...@siemens.com> 
wrote:
> 
> print ('%r' % workbook.BuiltinDocumentProperties)
> 
> gives me 
> 
> >
> 
> What can I do with such an object?

Are you checking the Word object model?  The BuiltinDocumetProperties method 
returns a DocumentProperties object.  I believe that is a collection of 
DocumentProperty objects.  So you should be able to say something like

for prop in workbook.BuiltinDocumentProperties:

— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel / Word: setting properties

2018-02-28 Thread Tim Roberts
Niemann, Hartmut wrote:
>
>  
>
> I create an excel document using the COM interface.
>
>  
>
> Now I need to set two properties to be compatible with a new company rule:
>
>  
>
> “[the tool] uses MS Office standard (‘Keyword’) and custom (‘Document
> Confidentiality’) properties. so if your code is able
>
> to preset values to these properties [everything should work]”
>
>  
>
> How do I set the [Excel workbook] standard property “Keywords” to
> “C_Restricted” and the user property “Document Confidentiality” to
> “Restricted”?
>

The Document object should have a BuiltinDocumentProperties collection
and a CustomDocumentProperties collection that you can query and
manipulate.  You'll have to discover whether the properties you need to
tweak are builtin or not.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Pywin32 outlook email organizer

2018-01-31 Thread Tim Roberts
Samantha Mait wrote:
>
>  
>
> I am reaching out as I am trying to use the pywin32 package for python
> 2.7 to automate sending an outlook calendar invite. The package is
> awesome and is able to do everything I would like except for one
> piece. I am trying to send the email from a separate email address. Is
> there any way that I can do this?
>
>  
>
> Ideally, I would like the email to be able to generate the script on
> my computer, but have the sender be someone else like you can do in
> python’s email package via sendmail(from_addresss, [to_address],
> msg.as_string()).
>

Remember that Python is just a gateway into Outlook.  You can't do
anything that Outlook wouldn't ordinarily do, and Outlook doesn't allow
you to override the sender address.  You can set up multiple identities
in Outlook, and then use Python to choose which identity to use when
sending.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python - connexion to serial port

2018-01-15 Thread Tim Roberts
Schoeni, Yann wrote:
>   
>
> I thought it would be a great idea to keep it open during the
> application life time for one reason.
>
>  
>
> My webserver (running on windows) got a Velleman VM8090 module plugged
> in with a usb cable, my serial port is virtual.
>
>  
>
> 7)  Sometimes, the script return « The Serial port is already
> open », and a *delay is identified*. Below the function that open the
> port : 
>
> 8)  Because of this delay I was just thinking about keeping the
> serial port open while the application is running.
>
>  
>
> What do you guys think ? $
>

There are two possible solutions.

The only time the port should be open is if you are already processing
another request.  No matter what you do, there's always going to be a
delay in that case.  Your problem, then, is to serialize access to the
serial port, to ensure there's only one request at a time.

Your proposed solution is certainly workable.  You could create a
long-running "serial server" that keeps the serial port open and accepts
requests from your web server.  The other solution is to change your
script so that IT keeps retrying until it's able to open the port, with
a short delay between each attempt.  That way, the web server would
always see success.

The delay with the two solutions should be about the same; you're always
going to have to wait for request A to finish before request B starts,
but the second solution would be easier, from where you are now.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python - connexion to serial port

2018-01-12 Thread Tim Roberts
Schoeni, Yann wrote:
>  
>
> « is the Python script persistent (is it running continuously in the
> background) or launched for each transaction? »
>
>  
>
> -   Currently, the script is launched for each transaction. As I
> understand your proposition, when the web page is open,
>
>    an ajax request should call a python script which open a thread
> between the machine and the serial peripheral, right ?
>

I'm still not clear what problems you are seeing with the
open/send/close paradigm.  What leads you to make a change?  The
open/send/close model is usually easier to handle, because the process
starts with a clean slate every time.  Once you go to a long-running
process, you have more things to keep track of.

Dennis is not necessarily proposing a new thread.  Consider, for
example, a server application using one of the frameworks, like Flask or
CherryPy or Django.  Such an application gets launched once, and sits
idle waiting for to send it things to do.  When it gets a request
(either from a socket or routed from Apache), it reads input, takes
action, sends output, then waits for more things to do.

Dennis' proposal is the same.  Have a Python script running
continuously.  When an Ajax request comes in (either from a socket or
from Apache), you communicate with the serial port and send your
response.  The serial port can remain open, because the application does
not close.

But I'm not convinced that complexity is needed.  The open/send/close
model should work just fine.


> -   Even if I find a way to open a thread with the serial port or
> to keep it open with a loop, is it possible to send it orders ?

Why wouldn't it?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Recycle bin deletion date - mixing shell and winshell?

2018-01-11 Thread Tim Roberts
Durumdara wrote:
>
> The winshell module
> (https://winshell.readthedocs.io/en/latest/recycle-bin.html) retreives
> recycle bin files for me, I can see the deletion date, but not the
> real filename in filesystem (to I can delete the older ones).

The documentation does not describe it, but if you look in the source
code (which should always be your fallback for True Answers), you'll see
that the ShellRecycledItem object has a real_filename() method that
returns the information you want.

The documentation is on github, if you want to submit a fix.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python program to consolidate the.eml files

2018-01-09 Thread Tim Roberts
sahhithi sangitapu wrote:
>
> I would like to write a program in python to read the whole contents
> with images from the outlook email which has been saved in local drive
> and form an single email message from all the outlook message from the
> local drive

Your request is a little confusing.  EML files are basically plain text
in RFC 822 format, like the Unix "mbox" format.  The easy way to
transport them is just to combine them into a zip file and send the zip
file.  What do you plan to do with these messages?  Why do you think you
need to convert them to a single email?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using COM Event. A problem

2017-12-06 Thread Tim Roberts
NIcola Montecchiari wrote:
>
> I am trying to create a call back for som events generated by a COM
> server that I connect.
> Looking at some posts apparently related to the same topic, I wrote
> this sample code to test:
>
> import win32com.client as com
> from win32com.client import gencache
> ...
> mod = gencache.EnsureModule('{B4955EC7-F7F2-11D2-AA9C-44455354}',
> 0, 1, 0)
> ob = mod.Application()
> objCybio = com.DispatchWithEvents(ob, Eventi)
>
> When I run this code, it starts the connection, but soon after it is
> stopped with the following error:

Do you get the same result if you replace those three lines with this?

    objCybio = win32con.client.DispatchWithEvents("Maxim.Application",
Eventi)

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32 printer

2017-11-29 Thread Tim Roberts
Richard Peeters wrote:
>
> Tks for reply , but decided to go other way.
> The following code prints "Hello world" about an inch down on page at
> left margin.
> I can change the hoirizontal position from left to right but the
> vertical only a few inches down the page.
> What are the coordinates to cover a complete page?

width = hDC.GetDeviceCaps( win32con.HORZRES )
height = hDC.GetDeviceCaps( win32con.VERTRES )

That returns you the surface size in pixels.  If you plan to work in
twips, you'll have to convert it.

widthtwips = hDC.GetDeviceCaps(win32con.HORZRES ) * 1440 /
hDC.GetDeviceCaps(win32con.LOGPIXELSX)
heighttwips = hDC.GetDeviceCaps(win32con.VERTRES ) * 1440 /
hDC.GetDeviceCaps(win32con.LOGPIXELSY)

By the way, you wrote:

    INCH = 1440  # twips - 1440 per inch allows fine res

Working in twips doesn't increase the resolution in any way.  You can't
get any finer than pixels.  It's just a little more convenient.  If
you're going to use the "INCH" constant anyway, you could just leave the
mapping mode alone, and do

    INCH = hDC.GetDeviceCaps(win32con.LOGPIXELSX)

Now positive Y increases going down, which is a bit more natural.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32 printer

2017-11-28 Thread Tim Roberts
Richard Peeters wrote:
>  
> I'm new to Python and this list.
> I installed pypiwin32 , 
> and demo runs without errors but nothing is printing. I checked and
> nothing in cue
> Os is windows7.

It depends on your printer.  Your script works fine on my Brother laser
printer, but many laser printers don't understand raw text.  If your
printer is native Postscript, for instance, it will throw away your raw
input, because that's not a Postscript program.  Some of the cheapest
laser printers don't have any fonts at all -- they rely on a Windows
driver to turn the text into a big bitmap.  Same for the thermal label
printers.  What printer are you using?


> BTW is there a simple method to just print text (as lprint in basic)?

LPRINT was created when the computing world was a very different place. 
It relies on DOS and BIOS calls to send text to the default printer, but
that's default in the BIOS sense, meaning a parallel printer hooked up
to a parallel port on your computer.  If you don't have a parallel port
printer, then LPRINT doesn't work, either.  If you do have a parallel
port printer, you can simulate LPRINT by opening the special file "PRN"
or "LPT1" and writing to it:

    lpr = open("PRN","w")
    lpr.write( "Hello, world!" )

If you're just trying to do logging to a printer, that's tedious but not
terribly difficult in Windows.  You just have to maintain your Y
position, do TextOut calls, and end the page when it is full.  It's
usually way easier to log to a file and print it afterward using
something like Notepad.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] a question about and error

2017-11-15 Thread Tim Roberts
On Nov 14, 2017, at 11:00 AM, Elitsa Hineva <elitsa.hin...@abv.bg> wrote:
> 
> I am trying to run a GIS model for wind fetch calculation but it didn't work. 
> Instead I have received the following note:
> 
> : (-2147467259, 'Unspecified error', None, None)
> Failed to execute (fetch_jjr).
> 
> What do i need to do to solve this problem?

You need to contact the people who wrote your GIS interface.  That is 
0x80004005, which is the very generic error E_FAIL.  The only people who can 
help you are the authors of the module.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] datetime values in adodbapi

2017-11-06 Thread Tim Roberts
On Nov 6, 2017, at 2:47 PM, Max Slimmer <maxslim...@gmail.com> wrote:
> 
> Coincidentally I ran into this issue last week. From what I could gather the 
> MS SQL data type can accept values with no more than millisecond precision. 
> This is true using parameterized statements through adodbapi and also T-SQL 
> and implicit conversion from char to datetime. The type accepts up to seven 
> places (nano seconds).
> 

Your post is not exactly correct, and the difference is critically important.  
The adodbapi happens to display time strings with 7 decimal digits, but that is 
TOTALLY unrelated to the precision with which the underlying database engine 
stores its date/time values, or the precision returned by the NOW() function in 
your database engine.  This is not specified by the standard.  By default, for 
example, the MySQL DATETIME time does not store fractional seconds at all.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] PyWin32 API

2017-10-22 Thread Tim Roberts
On Oct 20, 2017, at 7:58 AM, Josh Clayton <jcla...@gmail.com> wrote:
> 
> Just following up since I have not heard back.

Heard back on what?  I sent a long and detailed message on Thursday including 
demonstration code.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Quest for memory scanner

2017-10-21 Thread Tim Roberts
On Oct 20, 2017, at 12:54 PM, Michael C <mysecretrobotfact...@gmail.com> wrote:
> 
> Hello Tim, everyone:
> 
> I actually have a semi-working scanner, but I can't figure out why it doesn't 
> return
> nearly as many addresses as Cheat Engine does.(for scan run #1)  Let's say I 
> am scanning the Calculator that comes with Windows.

The Windows calculator uses an arbitrary-precision math library to store its 
numbers.  It does not store them as double-precision floats.

You are only looking at PAGE_READWRITE memory.  Processes also have read-only 
memory that you can scan, but not change.

When I suggested using a buffer, what I meant is that you should allocate a 
buffer of about a megabyte, then read a megabyte at a time from the other 
process, and scan through that memory in your code.  That's much faster than 
making millions and millions of kernel calls.  You may not be aware of what 
goes on behind the scenes when you do ReadProcessMemory.  At any given time, 
only one process at a time (per CPU) can have its memory space in the page 
tables, and if it's not in the page tables, it can't be accessed.  Thus, when 
you call ReadProcessMemory, the kernel has to switch to that other process as 
if it were going to start running, load its page tables, copy the memory into 
kernel space, switch back to your process and load its page tables, copy the 
data back to you, then start you running again.  That's a lot of overhead.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] PyWin32 API

2017-10-20 Thread Tim Roberts
Michael C wrote:
>
> I am wrestling with my life right now, but I'll post more hopefully by
> tomorrow.
>
> Also, I am trying to write my own 'Cheat Engine' or just a memory
> scanner in general, 
> I am just looking for simple values such as a int or a double.

Wrong thread.

Here is C++ code that does what you asked, based on a StackExchange
article that was trying to cheat on games by increasing the money
level.  This one scans my gvim editor process looking for the "cpp"
extension.  It finds several hundred occurrences:
    https://pastebin.com/BbyrXxsf

It's possible to convert that to Python, but you're using ctypes so much
that you're basically writing C code in Python.  Further, Python doesn't
worry about representations in memory.  If you're searching for a
specific floating point value, then you need to know exactly how it was
stored, bit for bit.  Is it single precision?  Double precision?  Scaled
integer?  Are you sure?

And if you do find the value, you can't change it unless you're sure
it's not a false positive.  You're likely to find any 4-byte random
value somewhere in a process, perhaps even as bytes of machine code. 
You don't want to change it unless you're sure it's a numeric constant
and not, say, a pointer.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] PyWin32 API

2017-10-19 Thread Tim Roberts
Josh Clayton wrote:
>
> I've been reading the documentation and had a question. 
>
> How would I create a custom tag in the details tab of a file then set
> it, and read it?
>
> If creating it is not possible, would it then be possible just set an
> already existing tag and then read it? My end goal is to try and
> metatag a large group of files to avoid having to open them to read
> them.  I'd rather just use a script to blast through 10,000 files and
> understand what files are in my folder structure.

The answer is quite complicated.

The Details tab in Explorer is exposing whatever metadata the underlying
file format supports.  If you look at a JPG, for example, the JPG format
has the ability to add "tags".  If you change the tag list while you're
looking at that tab, Windows modifies the file to add that to the tag
list in the JPG file.  Similar, a Word document supports metadata like
"DocTitle" and "Author", and Explorer understand the Word file format
and how to modify it.  There is no generic "hidden store" for these
properties.

You can get access to these properties using the Shell object model. 
Theoretically, this should do it, but this returned "None" for all of
the properties I tried.  I wish you luck.  If Tim Golden is listening,
he may have a better idea.

Note that the Shell.NameSpace API is one of the very few places in
Windows where the path MUST be specified with backslashes.  It will not
accept forward slashes.

from win32com.client import Dispatch
shell = Dispatch("Shell.Application")
y = shell.NameSpace(r"c:\tmp\pvt")
print( y.Title )
for z in y.Items():
    print( z.Path )
    print( z.ExtendedProperty("Author"),
    z.ExtendedProperty("Date"),
    z.ExtendedProperty("Tags"))

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] XLSM to CSV/XLS conversion

2017-10-18 Thread Tim Roberts
sridhar vr wrote:
>
> Anyone can tell me, how I can convert XLSM to CSV/XLS using python.

Not sure what you mean by CSV/XLS.  It's quite useful to convert XLSX to
CSV, but I don't know why you'd want to automate XLSX to XLS conversion.

For XLSX to CSV, there are two basic paths.  One is to use COM to
control Excel itself, load the file, and do the save.  That's not too
many lines of code, but it requires that you have Excel installed, and
it takes time to launch the app.

The other path is to use one of the existing Python packages to read
Excel files directly. like openpyxl.  Check the list here:
    http://www.python-excel.org/

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Question about Python script

2017-10-17 Thread Tim Roberts
Schoeni, Yann wrote:
>  
>
> I don’t see anything about color depth in the script, do you think I
> should define it somewhere ?
>
>  
>
> I did this to check that everything was correct before the image was
> draw :
>
>  
>
> bmp = Image.open (file_name)
>
> print(bmp.mode)
>
>  
>
> The return value is : RGB
>
> In the PIL documentation I’ve found : RGB (3x8-bit pixels, true color)
>
>  
>
> Which means 24-bits depth, correct ?
>

Correct.


> Now I need to create the device context as a 24-bits.
>
>  
>
>
>   i've done some research but, I didn’t find how to set the depth
>   color manually ..
>
>
>    
>
>
>   If I do :
>
>
>    
>
>
>   NUMCOLORS = 0
>
>
>    
>
>
>   hDC = win32.CreateDC()
>
>
>   hDC.CreatePrinterDC (printer_name)
>
>
> colorDepth = hDC.GetDeviceCaps(NUMCOLORS)
>
> print("colorDepth : ", colorDepth);
>
>  
>
> The return value is : colorDepth : 1539
>

Where did you get "NUMCOLORS = 0"?  That's wrong:

/* Device Parameters for GetDeviceCaps() */
#define DRIVERVERSION 0 /* Device driver version    */
#define TECHNOLOGY    2 /* Device classification    */
#define HORZSIZE  4 /* Horizontal size in millimeters   */
#define VERTSIZE  6 /* Vertical size in millimeters */
#define HORZRES   8 /* Horizontal width in pixels   */
#define VERTRES   10    /* Vertical height in pixels    */
#define BITSPIXEL 12    /* Number of bits per pixel */
#define PLANES    14    /* Number of planes */
#define NUMBRUSHES    16    /* Number of brushes the device has */
#define NUMPENS   18    /* Number of pens the device has    */
#define NUMMARKERS    20    /* Number of markers the device has */
#define NUMFONTS  22    /* Number of fonts the device has   */
#define NUMCOLORS 24    /* Number of colors the device supports */
etc

So, your 1539 result says that the driver's version is 0x0603.  You
don't need to hardcode these numbers at all.  Most Windows constants are
in win32con.  Plus, the important number is BITSPIXEL.  If that is 8,
then you can look at NUMCOLORS.  If it is not 8, then NUMCOLORS is not
meaningful.
 import win32con
 print( hDC.GetDeviceCaps(win32con.BITSPIXEL))
 print( hDC.GetDeviceCaps(win32con.NUMCOLORS))

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] VirtualQueryEx/ReadProcessMemory

2017-10-17 Thread Tim Roberts
On Oct 16, 2017, at 4:39 PM, Michael C <mysecretrobotfact...@gmail.com> wrote:
> 
> >>>Did you acquire the SeDebugPrivilege before calling?
> 
> Eh, no. I don't know what that is! How do I get it?

https://www.programcreek.com/python/example/80627/win32con.TOKEN_ADJUST_PRIVILEGES
 
<https://www.programcreek.com/python/example/80627/win32con.TOKEN_ADJUST_PRIVILEGES>


> >>>That's a screwed up way of doing it.  If you want buffers of 8 bytes,
> then make a buffer of 8 bytes.
> 
> So like this?
> 
> ReadProcessMemory(Process, i, ctypes.byref(buffer), 8, ctypes.byref(nread))

I would probably use ctypes.c_buffer to create the buffer.  You can experiment 
by reading your own process before you start reading other processes.


> Bummer... I thought with what I did, I was building a simple memory scanner.
> See, I thought with my ReadProcessMemory line I was retrieving values in the 
> size of doubles.
> 
> I thought by doing what I did, by reading 8 bytes at a time, (the size of 
> doubles) I was effectively looking for values in my memory. I thought a
> 
> for(start,end,8)
> 
> would give me all the values of doubles since I believed that doubles exist 
> in the memory in the positions of   base, base+8, base+16, base+24, and so 
> forth.

You would get the memory, 8 bytes at a time.  8-byte integers are often stored 
aligned on 8-byte boundaries, because it's slightly more efficient, but it's 
not required.  It depends on what you're looking for, which you still haven't 
told us.


> would achieve the same thing. I would store the address containing the 
> doubles I want in a list() called hit_pool.  And then the incorrect values 
> would be flushed out anyway, when I run a another run of comparing the 
> address found with target value. like this
> 
> for n in hit_pool:
> readprocessmemory(process, n,  ctypes.byref(buffer), 8, 
> ctypes.byref(nread))

Well, you wouldn't pass your "hit_pool" values to ReadProcessMemory.  You would 
read the memory, then scan through it locally looking for your hit_pool.

However, you'e always going to be fighting the language.  This kind of 
low-level machine-dependent processing is always going to be much faster and 
easier to code in C or C++.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] VirtualQueryEx/ReadProcessMemory

2017-10-17 Thread Tim Roberts
On Oct 16, 2017, at 5:06 PM, Michael C <mysecretrobotfact...@gmail.com> wrote:
> 
> Supposed by using Openprocess and VirtualQueryEx, I have the locations of all 
> the memory the application is using, wouldn't this to be true?
> 
> Say, a 8 byte data is somewhere in the region i am scanning. Ok, I know by 
> scanning it like this
> for n in range(start,end,1)
> 
> will read into another variable and mostly nothing, but unless a variable, 
> that is, one number, can be truncated and exist in multiple locations like 
> this
> 
> double = 12345678

You keep using the word "double".  A "double" is a floating-point number.  Are 
you actually referring to an 8-byte integer?


> 123 is at x001
> 45 is at x005
> 678 is at x010
> 
> unless a number can be broken up like that, wouldn't I, while use the silly 
> 'increment by one' approach,  actually luck out and get that value in it's 
> actual position?

I can't tell what your x001 notation is trying to say.  If you have the decimal 
value 12345678 stored somewhere in memory in a 64-bit value, the consecutive 
bytes in memory will look like this:
   4E 61 BC 00 00 00 00 00

If you actually mean the floating point value 12345678.0, it will be stored in 
8 bytes like this:
  00 00 00 c0 29 8c 67 41

It will take you forever to search another process 8 bytes at a time.  You're 
probably going to want to fetch a page at a time and scan the page locally.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] VirtualQueryEx/ReadProcessMemory

2017-10-16 Thread Tim Roberts
Michael C wrote:
>
> I am working on my own memory scanner. It uses Windows API, VirtualQueryEX
> and ReadProcessMemory. I am not sure I put down the following properly:
>
> I am sure 
>
> Process =
> Kernel32.OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, False,
> PID)
>
> ran properly, because it didn't return a 0.

Did you acquire the SeDebugPrivilege before calling?

> Lastly, ReadProcessMemory:
>
> 1st Question: The setup.
>
>     buffer = ctypes.c_double()
>     nread = SIZE_T()
>
> ReadProcessMemory(Process, i, ctypes.byref(buffer),
> ctypes.sizeof(buffer), ctypes.byref(nread))
>
>
> I used ctypes.c_double() to determine the size of the buffer, so does
> this mean
> that the value I retrieve would be doubles? As in, I know I want to
> scan for double
> values, therefore what I do is what I did here, ask ReadProcessMemory to 
> read 8 bytes at a time?

That's a screwed up way of doing it.  If you want buffers of 8 bytes,
then make a buffer of 8 bytes.


> Lastly, I don't understand this part about the memory:
>
> if I used VirtualQueryEx to find out if a region of memory is ok to
> scan, and it
> says it's ok, are the values in the region arranged like this:
>
> short,int,double,long,char, double, short in
>
> as in, random?

I have no idea what you're asking.  What you get back from
ReadProcessMemory is an untyped set of bytes.  There is no way to find
out anything about the type.  It might be strings, it might be machine
code, it might be header info, it might be floats, it might be images. 
It could be ANYTHING.


> I am asking this because, if it's random, then I'd have to run
> ReadProcessMemory
>  by increasing  the value of of my loop by ONE (1) at a time, like this 
>
> for i in range(start_of_region, end_of_region, 1):
>       ReadProcessMemory(Process, i, ctypes.byref(buffer),
> ctypes.sizeof(buffer),             ctypes.byref(nread))
>
> Is that correct?

No.  What are you hoping to learn here?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Question about Python script

2017-10-06 Thread Tim Roberts
Schoeni, Yann wrote:
>
> I’ve recently start to work with Python.
>
>  
>
> I’m developing a managment software for a swimming pool, this software
> needs to print stuff directly from the website.
>
>  
>
> I’m using Ajax request and shell exec to call a Python script which
> launch the print job.
>

Now, do you understand that this will print on the machine where the web
server runs, NOT the web browser?  Many people, when they click on a
"print" button, expect it to print on their local machine, where they
clicked.  Since you have already had results, I assume you are aware of
this.


> The script to print an image works fine with a standard printer but,
> I’ve to print on a card printer (FARGO-DTC1250^e ).
>
>  
>
> When I launch a print job from the website, the python script launch
> the job on the printer, that’s ok.
>
>  
>
> The probleme is that I have a substantial quality deterioration ..The
> image printed on the card looks bad.
>

Can you show us an example? Do you see the whole image, approximately
scaled, but at poor resolution?  Have you tried doing other graphics to
see if it really is a pixel count issue?  Like, if you draw a rectangle
100x100 pixels, does it really appear to be 1/3"?


> I’m sure the problem is about the Python script, I’ve tried to start
> the print job directly from Windows, the image quality is perfect.
>

When you say "start the print job directly from Windows", what do you
mean?  Do you mean, through some mechanism other than the Python script?


>  
>
> I don’t know anymore where to search, eventually when the script draw
> the image ? In this part of the code ?
>
>  
>
> dib = ImageWin.Dib (bmp)
> scaled_width, scaled_height = [int (scale * i) fori inbmp.size]
> x1 = int ((printer_size[0]- scaled_width) / 2)
> y1 = int ((printer_size[1]- scaled_height) / 2)
> x2 = x1 + scaled_width
> y2 = y1 + scaled_height
> dib.draw (hDC.GetHandleOutput (), (x1, y1, x2, y2))
>

This is probably relying on the printer's driver to do the image
resizing, and many printer drivers don't do a good job.  You may need to
scale the image using other PIL features and send a correctly-sized
bitmap to the printer.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to deploy pywin32 when using embedded instance of Python?

2017-08-09 Thread Tim Roberts
Norman Hadfield wrote:
> We currently use the standard Python and Pywin32 installers but to make our 
> win32 application,) which uses Python to execute dynamically generated 
> expressions including instantiating COM servers and hence the need to 
> pywin32), easier to install and support multiple versions side by side etc we 
> want to switch to using an embedded version installed in a sub-folder of our 
> application.
>
> This will allow simple xcopy deployment plus allow us to package our 
> application using project centennial as a Windows store App.

This is EXACTLY what tools like py2exe and cx_Freeze and pyinstaller
do.  You don't need to reinvent this wheel.


> 1. I now want to trim the pywin32 files down to the minimum so presumably I 
> can just delete the pip*, pkg*, setuptools* folders and also the demo, test 
> sub-folders, help files etc - is that correct?

py2exe (and the rest) do that.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Screenshot a given window instead of the whole desktop

2017-05-01 Thread Tim Roberts
On Apr 28, 2017, at 5:40 PM, Michael C 
<mysecretrobotfact...@gmail.com<mailto:mysecretrobotfact...@gmail.com>> wrote:

I have my own code that samples pixel colour,
https://pastebin.com/4EMd765h

 and now I am trying to add the feature of saving the Device Context to a .bmp 
file, so I found this code

https://books.google.ca/books?id=9MS9BQAAQBAJ

however there is one problem: The book example screenshots the whole desktop 
and I only want a screenshot of a given window. Is there a way to modify the 
black hat example into something that only screenshot a window given its handle?

It would have been easier to help if you had showed us the code you're trying 
to modify.

I assume the code you're copying does GetDC(0) to grab a DC for the desktop.  
If you instead pass the window handle of the window you want to snapshot, just 
pass that to GetDC.  You'll want to use GetWindowRect to find the size of the 
window.
—
Tim Roberts, t...@probo.com<mailto:t...@probo.com>
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] manual for pywin32

2017-04-28 Thread Tim Roberts
Michael C wrote:
> Hi all, is there a manual for this module? I can't seem to find any!

I'm skeptical that you looked at all.  Google "pywin32 documentation".

Pywin32 is very large, since it is trying to expose most of the
incredibly vast Win32 API.  Was there something specific you were after?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] To control commercial software CST through python

2017-04-28 Thread Tim Roberts
On Apr 27, 2017, at 11:17 PM, gowri shankar <gowrishankarman...@gmail.com> 
wrote:
> 
> I checked both the ways without any success. By the by, mws.EigenmodeSolver() 
> works perfectly in MATLAB. Does the object name changes with different 
> language.

It's not impossible.  You're using late binding here, which has to find the 
entry points by doing a text search.  However, the web seems to indicate that 
your spelling is correct.


> Can you please suggest any literature or source where i can learn more on COM 
> .

There are an infinite number of books and websites on COM; the technology has 
been around for more than 20 years.  However, the different language bindings 
do have different requirements and implications, so a C++-based book will be 
good background information, but won't help specifically with Python.

As an experiment, you might try using EnsureDispatch instead of just Dispatch.
from win32com.client.genache import EnsureDispatch
That creates and saves a Python module to interface to the object.  Sometimes 
having that module can be helpful in debugging.
— 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] To control commercial software CST through python

2017-04-28 Thread Tim Roberts
On Apr 27, 2017, at 12:02 PM, gowri shankar 
<gowrishankarman...@gmail.com<mailto:gowrishankarman...@gmail.com>> wrote:

Thanks for bringing out my inadequacies.  By the by i am using Python 2.7.8 
|Anaconda 2.1.0 (64-bit).
Here are the error codes for the same:

import win32com.client
cst = win32com.client.Dispatch("CSTStudio.Application")
#Opens a new CST file
mws=cst.OpenFile('D:\Gowrishankar\PDF\cuboid.cst')

That string is still wrong, by the way.  You NEED to fix the backslashes.
—
Tim Roberts, t...@probo.com<mailto:t...@probo.com>
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] To control commercial software CST through python

2017-04-27 Thread Tim Roberts
gowri shankar wrote:
>
> Thanks for bringing out my inadequacies.  By the by i am using Python
> 2.7.8 |Anaconda 2.1.0 (64-bit).
> Here are the error codes for the same:
>
> import win32com.client
> *cst* = win32com.client.Dispatch("CSTStudio.Application")
> #Opens a new CST file
> *mws*=*cst*.OpenFile('D:\Gowrishankar\PDF\cuboid.cst')
> ##
> *mws.StoreParameter('len2',10.1)
> *
> *mws.StoreParameter("s",5)*
> ##I don't get any error message for them. And usually this should
> store a variable and its values in CST but it didn't do
> *Esolver=mws.EigenmodeSolver()*
> *### I got the following error message*
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Anaconda\lib\site-packages\win32com\client\dynamic.py",
> line 192, in __call__
> return
> self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
> pywintypes.com_error: (-2147352573, 'Mitglied nicht gefunden.', None,
> None)

That's 0x80020003, DISP_E_MEMBERNOTFOUND, meaning that it did not find
the name in its dispatch table.  Are you absolutely sure you have the
spelling correct?  Could it be EigenModeSolver, for example? 
Capitalization matters.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


  1   2   3   4   5   6   7   8   9   10   >