Re: [python-win32] GetModuleFileName requires Process or Thread handle?

2008-08-12 Thread Tim Golden

Walter Decker wrote:
Can someone help me diagnose why the following fails to retrieve the 
'exe' name KillByName?


Do you mind if I sidestep your question altogether
and point out that this is one of those things
which WMI makes a fair bit easier? Obviously,
if what you want is an insight into Win32
process handles and so on, then say so, and
I'll try to oblige. But just in case you
really want to kill a named process, try this:


import os, sys
import time
import wmi

c = wmi.WMI (find_classes=False)

def kill_by_name (name):
  for process in c.Win32_Process (Caption=name):
process.Terminate ()

def start_a_process (name):
  c.Win32_Process.Create (CommandLine=name)

if __name__ == '__main__':
  start_a_process (sys.argv[1])
  time.sleep (5)
  kill_by_name (sys.argv[1])




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


Re: [python-win32] help with parsing email

2008-08-14 Thread Tim Golden

Ahmed, Shakir wrote:
I need to grab/parse numeric numbers such as app number from incoming 
emails stored in Microsoft Outlook (Microsoft Exchange server) with 
specified subject line.



The email body is like this

 


myregion ; tst ; 11-Aug-2008

http://my.xyz.com//content/ifs/apps/myDocFolder/NoticeOfapplication/080612-21_test_337683.pdf 




I need to extract 080612-21 _ number from above line from incoming emails.



You're underspecifying this a bit. Are you asking for
help with reading emails? Or with finding a number in
a load of text?


The answer to the first is: use COM to automate Outlook/CDO.

The answer to the second is probably to use a simple regex.
Unless the format is so simply specified that you can
just use split () and string slicing.

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


Re: [python-win32] Accessing properties of share on DFS

2008-08-27 Thread Tim Golden

Michael Kesper wrote:

Until now I'm using win32net.NetSessionEnum to list sessions users have
open. Now homes will be migrated to Distributed Filesystem (DFS).
As far as I understood msdn I should access that via win32wnet.
But now, I have some troubles to figure out how this really works.
The following script gives me an error 87, "wrong parameter" at the call
of WNetOpenEnum:


You might be able to get there with WMI. The following
works on my own machine, but I'm not sure what machine
you'd need to access to list the DFS shares. I'll see
if I can persuade a friendly admin here to let me try
things out:


import wmi

c = wmi.WMI ()

for share in c.Win32_Share (Type=0):
 print share.Caption, share.Path
 for session in share.associators (
   wmi_result_class="Win32_ServerConnection"
 ):
   print "  ", session.UserName, session.ActiveTime



or you could come from the other end and enumerate
the Win32_ServerConnection collection to start with.

As I say, I'll try to get one of our admins let me
have a go with a DFS share to see if I can get
something working.

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


Re: [python-win32] How can I use GetKeyboardLayout in python?

2008-08-27 Thread Tim Golden

Dror Cohen wrote:
Hi everybody, for a long time I'm trying to get my current typing 
language in windows.
At the moment I'm thinking about using either GetKeyboardLayout or 
ITfInputProcessorProfiles that holds the **GetCurrentLanguage* 
 function.
It seems that using GetKeyboardLayout will be a lot easier but I just 
can't find this function in the win32api functions list.


I freely admit I know next to nothing about this aspect of
Windows, but to help you along, it's nearly trivial to
access this function via ctypes:


import ctypes

print ctypes.windll.user32.GetKeyboardLayout (0)



You then have the issue of what to do with the result,
but I'm sure you're up to that challenge.

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


Re: [python-win32] Accessing properties of share on DFS

2008-09-01 Thread Tim Golden

Michael Kesper wrote:

Hi,

* Tim Golden <[EMAIL PROTECTED]> [2008-08-27 14:35:37 +0100]:
 

You might be able to get there with WMI. The following
works on my own machine, but I'm not sure what machine
you'd need to access to list the DFS shares. I'll see
if I can persuade a friendly admin here to let me try
things out:


Thanks for your answer. I try to try it. ;)
I can access the DFS share properties via mmc from one special server,
so I think I'll need to run my scripts there.
As you probably guessed, there's no python installed there.


That's not problem. The great thing with WMI is
that it's installed *everywhere* and by the glory
of DCOM (!) using it is a breeze. Just take that code
snippet and change the line:

 c = wmi.WMI ()

to:

 c = wmi.WMI ("other-machine-with-dfs")

and Bob's your Uncle.

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


Re: [python-win32] Internet Explorer constants

2008-09-05 Thread Tim Golden

Gabriel Genellina wrote:

Hello

I want to control Internet Explorer. This is what I have so far:

import win32com.client
from win32com.client.gencache import EnsureDispatch
url = "..."
IE = EnsureDispatch("InternetExplorer.Application")
IE.Navigate(url)
IE.Visible = 1

It works fine and shows the requested page. Now I want to use the "Save 
As" command. Looks like I should call the
IWebBrowser2.ExecWB method, passing IDM_SAVEAS as the command and 
MSOCMDEXECOPT_DONTPROMPTUSER in the options. But I don't know how to 
obtain the value for such constants... I could dig into the C header 
files looking for them, but is there some other way?


The ExecWB method is documented here 
http://msdn.microsoft.com/en-us/library/aa752117(VS.85).aspx


The usual way to get at constants after a Dispatch
is via the win32com.client.constants object. In this
case, the constant you want is OLECMDID_SAVEAS which...


import win32com.client

IE = "InternetExplorer.Application"
ie = win32com.client.gencache.EnsureDispatch (IE)

print win32com.client.constants.OLECMDID_SAVEAS 





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


Re: [python-win32] Handling COM events in a python thread

2008-09-05 Thread Tim Golden

Ujjaval Suthar wrote:

Hi all,

I have a COM control which fires a status event called 
ProcessingDataAvailable(). The COM control has a method call AddData() 
with some data parameters.


Using python, in a simple program, I can instantiate COM object via 
Dispatch and call AddData() method successfully.


Now, I want to have a thread which keeps running and listening for 
ProcessingDataAvailable() event and do some processing in my program.


Can somebody please give me a simple example code that shows how it can 
be done? I'm very new to this kind of programming.



Well here's a crude example to get you going. It uses the
MSAgent thingy which I imagine is installed (if little used)
on most Windows machines. Notice that it's launching a thread
to pick up events from a Queue -- the standard Python structure
for communicating between threads.


import win32com.client
import pythoncom
import Queue
import threading
import time

events = Queue.Queue ()

def do_things_with_events (events):
 while True:
   event = events.get ()
   open ("c:/temp/events.log", "a").write (str (event) + "\n")

class AgentEvents:
 def OnHide (self, character_id, cause):
   events.put (("hide", character_id, cause))

#
# Agent.Control.1 - Win2K characters
# Agent.Control.2 - Office2K characters
#
agent = win32com.client.DispatchWithEvents ("Agent.Control.2", AgentEvents)
agent.Connected = True

def start (name, filename=None, show_immediately=True):
 filename = filename or ("%s.acs" % name)
 agent.Characters.Load (name, filename)
 this_agent = agent.Characters (name)
 this_agent.Show ()

if __name__ == '__main__':
 import time
 threading.Thread (target=do_things_with_events, args=(events,)).start ()
 start ("merlin")
 while True:
   pythoncom.PumpWaitingMessages ()
   time.sleep (0.1)



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


Re: [python-win32] how to obtain list of connected IP/port pairs on user's computer?

2008-09-08 Thread Tim Golden

Patrick Li wrote:
I'm interested in writing a function that returns me the list of IP/port 
that the user's machine is connected to.  The most naive way is to run 
netstat -na on the user's computer and just parse the stdout.  Are there 
libraries I can call to achieve this as opposed to running an external 
command?


There was a thread about this a couple of months ago;
might help:

http://mail.python.org/pipermail/python-win32/2008-June/007786.html

TJG

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


Re: [python-win32] Adding an exe to startup...

2008-09-16 Thread Tim Golden

John Bunting wrote:
I've been having some trouble finding information on how to add an exe 
that I have created to the startup of my windows box.  I would like to 
know how I should go about adding the exe to the startup menu, without 
using the gui interface.  I want to be able to automate this because I'm 
also going to be giving out some of this code to different users and I 
don't want to have to have them manually add the exe.



The startup menu is basically a folder which you can put
shortcuts into in the normal way. For simplicity's sake,
I recommend using (my) winshell module:

http://timgolden.me.uk/python/winshell.html

but it's only a very simple wrapper around the pywin32
extensions so you might prefer to roll your own. At
least you can look at the source. The following code
will do what you want (assuming you want Python to
start up automatically!)


import os, sys
import winshell

startup = winshell.startup () # use common=1 for all users
print startup

winshell.CreateShortcut (
 Path=os.path.join (winshell.startup (), "Python.lnk"),
 Target=sys.executable,
 Icon=(sys.executable, 0),
 Description="Python"
)



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


Re: [python-win32] Win32 Python Extensions Outlook.Application Question

2008-09-17 Thread Tim Golden

Pramod Vaidyanathan wrote:
The problem comes down to this.  I have an email that I have received in 
Microsoft Outlook that contains characters outside of the ascii set.  I 
was able to use your library to traverse through my outlook folders and 
select the appropriate emails etc.  There are characters in the email 
that are ascii, extended ascii, and other.  The problem I 
am having is when I read the "item.Body" into body, the characters 
"\xe2\x85\x9b", "\xe2\x85\x9c", "\xe2\x85\x9d", "\xe2\x85\x9d" become 
unknown characters (question marks).  These characters have unicode 
equivalents of u215b, u215c, u215d, and u215e.  They are the fractions 
1/8, 3/8, 5/8, 7/8 respectively. 


I'm not sure whether you're confused or I am.
Just to clarify: the Body attribute of an Outlook
MailItem is returned to Python as a unicode object.

In my case (having sent myself an email containing the
characters you mention) it looks like this:

u'\u215b\u215c\u215d\u215e'

Exactly how these chars will be output will depend on your
console, locale settings etc. If you want to replace
those as decimals, you can simply do this, eg:

body = message.Body.replace (u"\u215b", u"0.125")

You don't need to encode it to anything unless
you have some other reason to do that.

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


Re: [python-win32] Win32 Python Extensions Outlook.ApplicationQuestion

2008-09-17 Thread Tim Golden

Vaidyanathan, Pramod wrote:

Thanks Tim,

Unfortunately my resutls are still as follows.  I still have question
mark characters.  Is it possibly a microsoft outlook versioning issue?

u' \xbe \xbc \xbd \xbd \xbd \xbd\r\n\xbe \xbc \xbd \xbd \xbd \xbd
\xbd\r\n\xbe \xbc\r\n\xbe \xbc
\r\n
\r\n? \r\n? \xbd ? \xbe\r\n'



Must admit I'm mystified, if that's the result of running the
code I gave. You're clearly getting a unicode object, so the
only reason there should be question mark characters in there
would be if the text contained question mark characters. You
haven't done any kind of encoding for unknown-replacement to
occur.

To confirm: that output above is the result of doing:

print repr (message.Body)

Anyone else got any ideas?

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


Re: [python-win32] Win32 Python ExtensionsOutlook.ApplicationQuestion

2008-09-17 Thread Tim Golden

Vaidyanathan, Pramod wrote:

Yes,

Print repr (message.Body)

I am using Microsoft Outlook (2000).  Are you using outlook 2003 by
chance?  


Yep.


I just discovered that when I do the exact same thing in Outlook 2003,
the problem disappears. I believe it's some sort of settings issue in my
version of Outlook 2000.  You wouldn't know what that might be would
you?  If not, I'm sure I can dig it up by comparing.


I don't know of anything, I'm afraid.


Thanks again for all of your help - turned out to be something stupid as
it often is.   


Glad to be of help. And thanks for keeping the list updated;
it often helps when trawling the archives looking for
similar problems to one's own.

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


Re: [python-win32] Drag and drop of files (CF_HDROP)

2008-09-21 Thread Tim Golden

mir amicitas wrote:

I have been trying to implement drag and drop of files in python.  My
application will written in PyQt4 but they I want to use the native drag and
drop for windows as PyQt only supports mime based dragging, which does not
work for some of the windows applications that I want to connect with.

I have made a certain amount of progress getting this to work using pywin32,
however I have gotten stuck.

So far I have been able to implement dragging of text (CF_TEXT or
CF_UNICODETEXT).  This basically took reimplementing the IDropSource &
IDataObject objects, wrapping them using win32com.server.util.wrap() and
then calling pythoncom.DoDragDrop().  For some of this I have been able to
follow allong with the code in testClipboard.py that is included with the
pywin32 installaiton.

The next thing that I want to do is to use CF_HDROP as the format type with
a list of file locations.  I am getting stuck at the point when I actually
add the list of file locations to the pythoncom.STGMEDIUM() object.


From what I can gather this data needs to be placed into a DROPFILES

structure (msdn page on CF_HDROP &
DROPFILES).
So my questing is how to I create this structure in pywin32?


Any help on this would be appretiated, particularly since I can't find
documentation for a lot of this stuff (I have resorted to greping the source
code to find stuff).  I am totaly new to win32 programming so this has been
a bit more that I meant to bite off.



Can you have a look at this thread from earlier this
year to see if it helps to answer you question:

http://mail.python.org/pipermail/python-win32/2008-April/007409.html

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


Re: [python-win32] idle detection on system?

2008-09-23 Thread Tim Golden

Patrick Li wrote:

Hi,
Does anyone know how I can detect if a system is idle?  By idle I am
referring to a user being away from the computer (no keyboard or mouse
movement) for X minutes.  Tried searching around but I haven't found
anything that mentions how I can hook into these two events.



I knew there had been some discussion about this in the
past, but my attempts at searching the archives were
frustrated by the huge number of posts about "IDLE"!

In short: you can use the Scheduled Tasks API to trigger
something when the system has been idle for x minutes:

http://mail.python.org/pipermail/python-list/2005-May/323848.html

Alternatively, the GetLastInputInfo API might be what you want:

http://msdn.microsoft.com/en-us/library/ms646302(VS.85).aspx

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


Re: [python-win32] Invalid or corrupted installer...

2008-09-23 Thread Tim Golden

Andrea Gavana wrote:

Hi All,

I am having few problems in downloading and installing the release
212 of PyWin32 (and all the other releases as well) from SourceForge.
Whatever executable file I try to download from SourceForge (I need
the pywin32-212.win32-py2.5.exe for my Python version), the download
remains stuck at 4.4/4.7 MB (the pywin32-212.win32-py2.5.exe file size
is 5.3 MB) for a couple of minutes, and then it leaves me with a
corrupted installation file which cannot be run.
Is anyone else experiencing the same issues?



Not sure why there might be a problem. To help you out,
I've just dropped a copy here:

http://timgolden.me.uk/python/downloads/pywin32-212.win32-py2.5.exe

TJG

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


Re: [python-win32] Invalid or corrupted installer...

2008-09-23 Thread Tim Golden

Andrea Gavana wrote:
... No explanation was provided for the reason of the

corrupted download (!)



There used to be a general warning on sites which offered
tgz for download that IE would do something weird with them.
I never experienced the problem myself, and in any case that
was years (and versions) ago so I assumed that whatever it
was had been fixed long before. Maybe not...

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


Re: [python-win32] Virtual print driver - similiar to winpdf

2008-09-23 Thread Tim Golden

geoff wrote:

You might take a look at Pyla. It's a print to fax library. I think it's
kind of what you're talking about. I've been trying to hack it off and on
for a while now as we only need a little of its functionality here at work.
There isn't much for docs, so you'll have to read the source. Here's a link:
http://www.teamsw.it/pyla/

Mike


Thanks Mike.
I think I am going to dig deeper into using  a Windows printer defined
as using the "Standard TCPIP Port" and my own program based on
SocketServer to grab to  output when it it created.  I set up a very
crude test last night and I think this will do exactly what i need -
ie can react immediately when the user is printing something, complete
access to the datastream and of course pure python solution for easy
maintenance  :-) .


Sounds like a technique that's worth knowing about. Do keep
us posted, even if it turns out to be a dead-end.

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


Re: [python-win32] NT service and login prompt

2008-10-01 Thread Tim Golden

Larry Bates wrote:

le dahut wrote:

Hello,
Is it possible to tell windows to wait a python service has started 
before the login prompt is displayed ?


Probably not, but why would you want to implement something that does?  
Share your use case with us and perhaps we can be of more assistance.


Have a look at this thread from earlier this year:

http://mail.python.org/pipermail/python-win32/2008-June/007686.html

(which the OP contributed to, by the look of it)
But I don't think, in the general case, that it's possible.

OP: weren't you trying to do something fancy with GINA or
something similar last year? Was it successful?

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


Re: [python-win32] NT service and login prompt

2008-10-01 Thread Tim Golden

le dahut wrote:
Yes, I was trying to intercept user's logon. I've done it using userinit 
registry key, a python NT service and a python service running on the PDC.


My problem is also that the service has to be available at logon time to 
do some administrative stuff.


It seems that the policy "gpedit" > Computer 
Configuration\Administrative Templates\System\Logon\ "Always wait for 
the network at computer startup and logon" (registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows 
NT\CurrentVersion\Winlogon : SyncForegroundPolicy=1) can help me.


Putting a loop to wait the service is up can also be a good idea.



I'd be very interested (on behalf of anyone else who might
also be!) to see how this one resolves itself...

Thanks

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


Re: [python-win32] How to determine if a process (known pid) is still running ?

2008-10-05 Thread Tim Golden

Stef Mientki wrote:

How to determine if a process (known pid) os still running ?

Googling the web, I found 1 solution in killing the process,
but that's not what I want, I want to reuse the running process.

I could also ask a complete list of active processes,
but from my experiences that's quite slow.

Any better solutions ?


I'm not entirely sure what you're trying to achieve,
or what "reuse the running process" means. This WMI
snippet will tell you whether a given pid is running
or not. As you may know, WMI isn't the fastest thing
on earth, but it may be fast enough for you.


import wmi

pid = int (raw_input ("Enter PID:"))

c = wmi.WMI (find_classes=False)
for process in c.Win32_Process ([], ProcessId=pid):
  print "PID %s in use by %s" % (pid, process.Caption)
  break
else:
  print "PID %d not in use" % pid




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


Re: [python-win32] Problem in accessing the Message body of Outlook Inbox.

2008-10-09 Thread Tim Golden

venu madhav wrote:

Hi all,
How can I access the body of a mail in Outlook Inbox? I tried
various options like message.Body or message.Mesg etc. but didn't
work. I could get the subject of the mail using message.Subject
though.


If you haven't already, check out this page, which
will get you started:

http://timgolden.me.uk/python/win32_how_do_i/read-my-outlook-inbox.html

and check out the CDOLive site referenced from there.


Without answering your question directly, and in a spirit
of teaching people to fish... The things to search for
are "Outlook object model" and "Outlook message body".



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


Re: [python-win32] NT service and login prompt

2008-10-09 Thread Tim Golden

le dahut wrote:
I've put a loop that wait for the service to be up with 
win32serviceutil.WaitForServiceStatus.



Makes sense. Thanks for getting back.

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


Re: [python-win32] NT service and login prompt

2008-10-10 Thread Tim Golden

le dahut wrote:
I've put a loop that wait for the service to be up with 
win32serviceutil.WaitForServiceStatus.




Tim Golden a écrit :


le dahut wrote:
Yes, I was trying to intercept user's logon. I've done it using 
userinit registry key, a python NT service and a python service 
running on the PDC.


My problem is also that the service has to be available at logon time 
to do some administrative stuff.


It seems that the policy "gpedit" > Computer 
Configuration\Administrative Templates\System\Logon\ "Always wait for 
the network at computer startup and logon" (registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows 
NT\CurrentVersion\Winlogon : SyncForegroundPolicy=1) can help me.


Putting a loop to wait the service is up can also be a good idea.



I'd be very interested (on behalf of anyone else who might
also be!) to see how this one resolves itself...

Thanks

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



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



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


Re: [python-win32] Interacting with the desktop as a service on Vista

2008-10-22 Thread Tim Golden

Matt Herbert (matherbe) wrote:

So I have a service that needs to interact with the desktop on a Vista
machine. I've read multiple articles about Vista's updated security and
it's restrictions on services. So I realize that in order for the
service to interact with desktop, I'm going to need to create a new
process as a "normal" user, and use some form of IPC between the child
process and my service to get at the information I need.



Without knowing what the exact problem which you're
encountering, it seems to me that you're probably
fighting the system. I don't use Vista myself but
I seem to remember that the Service security subsystem
has been beefed up to make things like this even harder.

You don't say exactly what your interaction with the
desktop is. Can you not do the usual thing of having
a user run a (possibly systray-ed) app in his userspace
which comminicates with your service via, say, named
pipes (or sockets, or whatever)?


Can you come across with more information, such as
how your service will be interacting with the desktop?

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


Re: [python-win32] force outlook ui update

2008-10-29 Thread Tim Golden

Christan K. wrote:

Tim Roberts  probo.com> writes:


Christian K. wrote:


the subject field in the inbox list changes immedately but the subject
line of the message itself (either shown in the embedded panel or in
its own frame) does not. After a couple of other actions, i.e.
selecting and deslecting other items the message subject will be
updated in every place.

Is there a way to force an UI update?

No.  MAPI controls the mail engine, not the user interface.


Actually I did not expect to find something within mapi. Do you have any ideas 
where to look for these gui related issues?


You'll probably want to automate the Outlook Application itself
via its IDispatch COM interface ("Outlook.Application"). There
you do have some degree of control over the interface. I think
that if you need more than that, you'll have to look at Outlook
plugins and perhaps take a look at the Spambayes project for some
examples there.

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


Re: [python-win32] win32com and DispatchWithEvents()

2008-11-15 Thread Tim Golden

Thomas Heller wrote:

Ryan Neve schrieb:

 I posted this on comp.lang.python. but it has been pointed out to me that
this is a better place to ask.

I'm trying to get DispatchWithEvents() to work with HyperAccess (terminal
program) without much success.


My apologies for (again) advertising comtypes on this list - if this is
inappropriate please tell me and I'll stop.



My 2.5p-worth [*] is that this is a list for the use of
Python under win32 (or, these days, win32/64). So
anything which is relevant to that is relevant here.
And comtypes *definitely* passes the "relevant" test.
It's certainly not confined to the use of the pywin32
packages, if that's what your post was hinting at.

TJG

[*] This is pronounced tuppence-ha'penny-worth for those
of you who have the misfortune not to be English :)
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] turning monitors off from Python?

2008-12-04 Thread Tim Golden

Alec Bennett wrote:

I'm trying to turn a monitor off from a Python script. I can do this using the program 
"wizmo", so its possible from Windows. I found this script which describes a 
method using SendMessage:

http://fci-h.blogspot.com/2007/03/turn-off-your-monitor-via-code-c.html

Translated to Python, here's what I have so far:

SC_MONITORPOWER = 0xF170
win32gui.SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2)

That follows this general structure:
SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal MONITOR_OFF)

My problem is getting the handle. 


The article you mention suggests using the desktop window handle --
available via GetDesktopWindow (). You might try that?


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


Re: [python-win32] rebooting windows from Python?

2008-12-05 Thread Tim Golden

Tim Roberts wrote:

Alec Bennett wrote:
I'm wondering if there's some way to reboot or shutdown Windows from within Python? 


I can log out like this:

win32api.ExitWindowsEx(4)

And according to the documentation, I should be able to shutdown like this:

win32api.ExitWindowsEx(2)

But that returns the following error:

'A required privilege is not held by the client.'

Is there some way to do this? Currently I'm running shutdown.exe, which works, 
but I'd rather do it directly if possible.
  


Yes -- you have to acquire the required privilege.  ;)  The mechanism to
do so is tedious, and involves fetching your current privilege token,
then adjusting it in place.  You can read about it in the MSDN page on
ExitWindowsEx:
http://msdn.microsoft.com/en-us/library/aa376868.aspx

Personally, and it really is a personal preference, I think it's a lot
less trouble, and a lot easier to understand, just to use the tools at
my disposal:
subprocess.call( "shutdown", "-r" )



Or... WMI makes this one slightly easier. This example:

http://timgolden.me.uk/python/wmi_cookbook.html#reboot_remote_machine

comes close. You don't -- probably -- need the remote machine bit,
and the privilege you need is Shutdown, not RemoteShutdown. Oh, sod
it; here's the code:


import wmi

wmi.WMI (privileges=["Shutdown"]).Win32_OperatingSystem ()[0].Shutdown ()



TJG

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


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Golden

Mike Driscoll wrote:
We're doing what amounts to a registry session audit here at work, so I 
need to walk a specific set of subfolders in our registry and get the 
contents thereof. The subfolders will vary from user to user. I found 
Tim Golden's excellent registry walking script on his website here:


http://timgolden.me.uk/python-on-windows/programming-areas/registry/walk-the-registry.html 



My problem is that I need to output the data into *.reg files. Is there 
a builtin way to do that with _winreg or PyWin32 or do I just need to 
roll my own?


Try as I might, I was unable to discover an API to do this. The
backup/restore APIs create opaque binaries. Shouldn't be too hard
to get a simple version up-and-running, but picking up all the nuances
of different data types might be a bit tedious[*]. If you decide to do
something and get it running, please do post it back. I have a
long-in-gestation winsys package:

http://winsys.googlecode.com/svn/trunk

which has a registry module
which could do with such a routine. I had thought about writing
it myself but considered it low priority. I'm hoping that once
I get this -- frankly enormous -- package out with docs & tests
I'll be able to feed the best bits of it, and of my own experience,
back into the docs you reference above which have been sadly
neglected.

TJG

[*} One note which I remember: the .reg files are usually UTF16LE;
not sure if that's important or not.
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] rebooting windows from Python?

2008-12-05 Thread Tim Golden

Alec Bennett wrote:


import wmi

wmi.WMI(privileges=["Shutdown"]).Win32_OperatingSystem()[0].Shutdown ()




Stylin, works. The only thing it doesn't do that I personally need 
it to do is the "force shutdown". In other words "shutdown.exe -f". 
I found this page with some hints but couldn't get it to work:


http://www.freevbcode.com/ShowCode.asp?ID=7693



Well I'm slightly surprised. The MS docs for this method:

 http://msdn.microsoft.com/en-us/library/aa393627(VS.85).aspx

state that there are no params. And, on my XP SP3 box, introspection
says the same:



import wmi
c = wmi.WMI ()
c.Win32_OperatingSystem.Shutdown

 (ReturnValue uint32) | Needs: SeShutdownPrivilege>






Ah. I remember. You need the *Win32Shutdown* method, not the *Shutdown*
method. Sorry.

Try this (untested because I can't be fagged to power my machine down
just to test an email :) ):


import wmi
nForcePowerDown=12 
wmi.WMI(privileges=["Shutdown"]).Win32_OperatingSystem()[0].Win32Shutdown (Flags=nForcePowerDown)



Earlier versions of the WMI module had a bug/feature which only allowed
named params in method calls. Can't remember whether the current release
version has it fixed. Certainly my dev version does.

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


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Golden

Mike Driscoll wrote:

Tim Roberts wrote:

Mike Driscoll wrote:
 

We're doing what amounts to a registry session audit here at work, so
I need to walk a specific set of subfolders in our registry and get
the contents thereof. The subfolders will vary from user to user. I
found Tim Golden's excellent registry walking script on his website 
here:


http://timgolden.me.uk/python-on-windows/programming-areas/registry/walk-the-registry.html 




My problem is that I need to output the data into *.reg files. Is
there a builtin way to do that with _winreg or PyWin32 or do I just
need to roll my own?



I'm not answering the question you asked, but are you aware of the very
handy "reg" tool included with XP?  "reg export" can export a full key
in a format that is compatible with regedit.
reg export HKLM\system\CurrentControlSet\Services\vgasave  xxx.reg

  


I suppose I should have completely explained the project, but I didn't 
think the other details mattered. I will be running this as part of my 
login script, and writing each subfolder to a directory tree on a per 
user basis. We are trying to figure out which users have which sessions 
of a certain program and how to best manage said sessions and their 
respective configurations, hence the audit.


As far as I can see, Mike, there's nothing in your description which
prevents you from using the registry's save/restore functionality:

http://timgolden.me.uk/python-on-windows/programming-areas/registry/save-and-restore-the-registry.html

There are bits in there which are a little out-of-date since pywin32 212
which added stuff, but basically the approach should work. You can save
the user's folder tree and then -- if you need -- pull the file to some
other machine and load it into a different tree. The user running the
save operation will need backup privs, however. Might be a showstopper.

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


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Golden

Dahlstrom, Roger wrote:
If you can read the registry, you can save it without any other 
special permissions.  It is just text.


Just export a branch of your own registry and open it with notepad 
to see the format.  I do it all the time, it works fine.


You're quite right, Roger, and other people earlier in the thread
have more-or-less suggested this approach. I think Mike was looking
for something programmatic and there doesn't seem to be anything in
the API which offers the same output as the Export action gives you
from the menu.

My point about the backup (and later restore) privs refers to the
specific API calls RegSaveKey and RegRestoreKey. These produce
an opaque binary format which doesn't look quite so good in 
notepad. :)


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


Re: [python-win32] Getting active SMTP servers via python.

2008-12-10 Thread Tim Golden

Dominick Lauzon wrote:
I am attempting to determine the accessible SMTP servers 
on a given desktop to avoir various users for having to 
predefine in a given script to facilitate distribution.



Can you clarify what you mean by "the accessible SMTP servers"?
If you're connected to the internet, that list will potentially
be very long :)

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


[python-win32] Passing data in a windows message

2008-12-10 Thread Tim Golden
I'm using win32gui.PyGetBufferAddressAndLen to pass the address & length 
of a marshalled object as the wparam / lparam of a windows message. 
Something like this:


address, length = \
 win32gui.PyGetBufferAddressAndLen (buffer (marshal.dumps (message)))
PostMessage (self.hwnd, self.WM_PROGRESS_MESSAGE, length, address)

where "message" here is actually a unicode object. At the other end, I'm 
unpacking the message with PyGetString:


message = marshal.loads (win32gui.PyGetString (lparam, wparam))


Obviously, these two code fragments occur in two completely
different places. (In two separate threads, in fact). What
I'm entirely unsure about is the safety of this from the
point of view of the object references. I'm fairly shaky on
the Python C-API so altho' I've looked at the implementation
of those functions I can't make out whether any references to
the data in the buffer is being held.

The symptom is that, sometimes, I get garbage out when unmarshalling
from the message, which suggests to me that the memory *is* being
reallocated.

Can anyone enlighten me?

Thanks

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


Re: [python-win32] Passing data in a windows message

2008-12-10 Thread Tim Golden

Tim Roberts wrote:

Thomas Heller wrote:

Since you used PostMessage, the message is simply posted to the thread's
message queue. You have no control when it is processed; so I fear you
must keep the posted 'object' alive even longer.
  


This is a good point that I overlooked.  If you used SendMessage, it
would block until the other end acknowledged it.



Thanks, Tim & Thomas. Pretty much what I thought was happening,
but good to get confirmation from more authoritative sources.
For some reason which now escapes me, I had tried to avoid
using the SendMessage route but it seems like the cleanest
way out. (I think I was trying to avoid a circular message
path, but that doesn't seem to apply now if it ever did).

Thanks for you input.

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


Re: [python-win32] Writing to Excel performance

2008-12-12 Thread Tim Golden

Dominick Lauzon wrote:


I have large matrices of data to push to excel and I find the writing of
data to excel to be excessively slow (cell by cell method) even if the
Visible is to False.




Right now I reverted back to a 2 step CSV - Import to Excel but it is
far from ideal.




Is there any trick to accumulate the data and push it to Excel all at
once or any other way to improve performance altogether ?



Using COM (which I assume you are from the reference to Visible)
you can add a range at a time as a Python list or list of lists:


import win32com.client

xl = win32com.client.gencache.EnsureDispatch ("Excel.Application")
xl.Visible = True
sheet = xl.Workbooks.Add ().ActiveSheet
sheet.Range (sheet.Cells (1, 1), sheet.Cells (10, 10)).Value = \
 [range (10) for i in range (10)]




I suspect -- tho' I've never tried to find out -- that using something
like xlwt (and when I say "something like xlwt" I really mean "xlwt")
might be faster since it doesn't have to manipulate the interface at the
same time:

http://pypi.python.org/pypi/xlwt


Lastly there is a Google Group set up for Python-Excel issues and
you might want to lurk or ask there:

http://groups.google.com.au/group/python-excel

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


Re: [python-win32] Detecting fast user switching

2008-12-16 Thread Tim Golden

Arron Chapman - UnkwnDesign.Com wrote:
I found Tim Golden's artical "See if my workstation is locked" 
http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html 
which got me most of the way to where I need to be, I want to detect 
both logout and login events



I haven't gone down this route, but I imagine it's worth
looking at the win32ts module which exposes Terminal Services
functionality. Altho' you don't think of yourself as running
Terminal Services it basically operates on WinStations
which is more or less what the fast user switch is doing. Might
be worth a browse to see if it takes you anywhere.

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


Re: [python-win32] python.exe crashes while connecting to MSSQL Database using pyodbc.connect

2008-12-17 Thread Tim Golden

siddhartha veedaluru wrote:

i have created a System DSN in my local machine using python script which
uses ctypes module
using pyodbc module i'm trying to connect to remote database.

sometimes python.exe crashes in the connect function



Not answering your question directly but... did you know
that you don't need to create a DSN just to connect via
ODBC? This kind of thing will do it just as well:



import pyodbc

connection = "Driver={SQL Server};Server=SVR;Database=DB;TrustedConnection=Yes"
db = pyodbc.connect (connection)



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


Re: [python-win32] Hello and first question

2008-12-22 Thread Tim Golden

Andrea wrote:

Hi folks,
I'm new to the list and also to the python word!
I want to write a script to exchange messages with a win32 application.
I have a sample code in VB but I want to do it using python.
The problem is that I have no experience on comunication between application
in win.


Look at the win32gui module from the pywin32 extensions:

http://sourceforge.net/projects/pywin32/


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


Re: [python-win32] Reading Task Manager-Performance tab values

2009-01-13 Thread Tim Golden

Tony Cappellini wrote:

Is there an API for reading the values on the Performance Tab in Task
Manager on XP?



Without being 100% sure, I would imagine that WMI could pull them
out for you. However, there isn't -- afaik -- a "Task Manager API"
where you could be guaranteed of getting the selfsame figures which
are showing in the Performance tab: you'd simply have to work out
what those numbers / graphs represent and find the equivalent WMI
classes.

The functions in the win32pdh module are, I think, what the WMI
Win32_Perf... classes use under the covers, so you could go that
way if you wanted to.

This chaps' been blogging on what seems to be a related
subject recently; maybe that helps:

http://coreygoldberg.blogspot.com/2008/12/python-windows-remote-metrics-script.html

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


Re: [python-win32] User transparent authentication with PDC

2009-01-20 Thread Tim Golden

le dahut wrote:
Thank you, it looks like something good. But I was not precise enough in 
my first post, my PDC is a Linux/Samba system.


The client/server app I've written uses twisted-perspective broker. I 
don't trust the client side, so it should send to the server some 
informations it can check against the PDC.

I thought using some sort of NTLM like in squid.


This was announced recently:

http://groups.google.com/group/comp.lang.python.announce/msg/679090ede5ab645c

Might help? (Haven't looked closely; might not ;) )

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


Re: [python-win32] Windows Service, user activity and timed message box

2009-01-27 Thread Tim Golden

Ferdinand Sousa wrote:

Greetings:

I wanted some help on the following topics:

A] How do I set up a script to run as a service? Are there any prerequisites
for this?


There are a few recipes in the cookbook. Here's one for starters:

http://code.activestate.com/recipes/576450/



B] How do we check duration since last user activity -- Assuming that the
screen is set to turn off/display a screensaver after a certain duration, I
wouldn't mind checking if this has indeed occurred (I know how to use
win32gui .SystemParametersInfo to check if either of
these has occurred). However, I would prefer to check the time elapsed since
last user activity.


I don't know that there's a function to do that for
the entire system. GetLastInputInfo will do it for your
own application, but you'd probably need to install some
system hooks and roll your own to get this at system level.
(And that sounds like overkill for what you're after).

Perhaps a more precise description of your requirement would help?



C] Timed message box -- Is there anyway I can set a timeout for a message
box, so that if a user does not click some button within 'x' seconds, the
message box closes of its own accord?



You can certainly implement your own dialog which mimics the message box
and which can do whatever it likes in its own message loop. The
alternative -- trying to post messages to a modal MessageBox queue --
would involve setting up a watchdog thread before you start the
messagebox which "finds" your message box and "presses its button".
Haven't tried it myself so there may be some gotcha I haven't
thought about.

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


Re: [python-win32] advanced properties file

2009-01-28 Thread Tim Golden

wowberk wrote:

Hello everybody,

I need to list the advanced properties of a file such as organization, dll
version, etc..


I think you want structured storage. Have a look at
my winshell module (or at the code it implements):

http://timgolden.me.uk/python/winshell.html

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


Re: [python-win32] Windows Service, user activity and timed message box

2009-02-01 Thread Tim Golden

Ferdinand Sousa wrote:

I couldn't find the GetLastInputInfo function (pywin32 212, python 2.5.2 on
Xp).


That's because it's not there . You'd have
to use ctypes or roll your own extension for that.


What I'm putting together is a script that uses Adobe Acrobat COM. It opens
a port and listens for connections on the LAN. When a pdf is sent to the
port, my script opens it in Acrobat and performs some operations. If Acrobat
is not currently open (checks for an open window with 1st 26 characters of
title text =="Adobe Acrobat Professional"), the script opens Acrobat (in
hidden mode, no visible window) performs the operations and closes it. If
Acrobat is already open, a dialog asks for user's permission before
continuing (because it is made invisible). It processes the file and closes
it, and the user gets back control of Acrobat as it was, with all the files
that were opened by the user as they were. The issue I want to handle is if
Acrobat is open, but, say, the user is away from his desk.


That's a lot clearer; as you point out, sometimes
being forced to explain one's own situation is enough
to clarify certain things about to oneself. Which then
helps one determine what to ask other people.

If your users are going away and leaving their desktops
unlocked then you're down to some sort of (over-the-top)
hooks mechanism[*]. If, however, you're prepared to say:
I'll skip the dialog box if the desktop's locked, then
you can use this kind of technique which is a lot simpler:

http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html

TJG

[*] And a security problem, methinks.
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Unexpected feature in win32security?

2009-02-03 Thread Tim Golden

I *think* this is a bug (or at least an unfortunate effect)
but I'll post here first for a sanity check.

I'm looking at Windows security: descriptors, ACLs, etc. The
conventional wisdom is that a DACL (or an SACL but less commonly)
can be one of three things within a security descriptor:

1) Not there
2) There but NULL
3) There and a (possibly empty) list of ACEs

When calling the GetSecurityDescriptorDacl Win32 API, the first
and second situations are distinguished by the lpbDaclPresent
parameter which receives 0 or 1. From that result, the pDacl
parameter is either meaningless or NULL/pointer to a list.

Within the win32security module, the GetSecurityDescriptorDacl
method of the PySECURITY_DESCRIPTOR object returns None in
both of the first two cases and I can't see any other way to
distinguish the cases without dropping down to ctypes or a
hand-built extension.

The offending code is in PySECURITY_DESCRIPTOR.cpp:


// get Dacl from SD
if (!::GetSecurityDescriptorDacl(psd, &bDaclPresent, &pdacl, 
&bDaclDefaulted))
return PyWin_SetAPIError("GetSecurityDescriptorDacl");

if (!bDaclPresent || pdacl == NULL)
{
Py_INCREF(Py_None);
return Py_None;
}

return new PyACL(pdacl);



which returns None, as you see, in either case. The equivalent code
for SACL does the same thing.


I've not got an easy workaround. In general, it's very unlikely that
a DACL isn't present at all; and it's equally unlikely (I'm not sure
it's even meaningful) to have a NULL SACL. So I can fudge around things
a bit. But I'd prefer something more robust. However, it's difficult to
see what change to suggest without breaking the interface. The only
possibility I could come up with would be a separate pair of functions
whose only job would be to report the presence of the ACL in the SD.

Have I missed anything?

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


Re: [python-win32] Unexpected feature in win32security?

2009-02-03 Thread Tim Golden

Roger Upole wrote:

Thanks very much for responding to this, Roger.


1) Not there
2) There but NULL
3) There and a (possibly empty) list of ACEs


In practice, cases 1 and 2 are functionally identical . Once a security 
descriptor has

been applied to an object, the SE_DACL_PRESENT flag is always set.  If for
some reason you really need this info, you can call 
GetSecurityDescriptorControl

and check for presence of the SE_DACL_PRESENT flag.


That's the key bit I missed. My use case is a bit
abstruse, as I'm writing some wrapper code to
allow slightly easier access to the security stuff
and my unit tests are failing. Therefore what I'm
doing is a bit artificial but (to me) necessary :)


It's quite common for either of these to be NULL.
Most often files don't specify their own security, and just inherit from
the parent directory.  


That's clearly the case, but I thought that this meant
that their DACL was an effective copy of the parent
DACL, not a NULL, eg the following code gives me a PyACL
object, not None:


from win32security import *

#
# Create file with no special security, effectively
# inheriting from its parent
#
open ("c:/temp/blah.txt", "w").close ()
sd = GetNamedSecurityInfo (
 "c:/temp/blah.txt", 
 SE_FILE_OBJECT, 
 DACL_SECURITY_INFORMATION

)
print sd.GetSecurityDescriptorDacl ()



Despite my question here, I don't recall ever actually
coming across a NULL DACL on a file -- which is where
most of my activity is -- but they may be more common
on kernel objects or registry keys or whatever.



SACL's are often NULL also, although they
don't show a difference in behaviour between NULL and empty as
DACL's do.


That I can believe; it's only, as I say, for testing reasons
that I necessarily care. In any case, your pointer to the 
descriptor control has effectively answered my main question,

so thanks very much.

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


Re: [python-win32] win32file.ReadDirectoryChangesW in asynch mode?

2009-02-05 Thread Tim Golden

Eric Blade wrote:

It appears that sometime in the last year, year and a half or so,
someone made the necessary changes to win32file to get
ReadDirectoryChangesW up and working in Asynch mode, which is
something that I would find very nice to be able to use right now ..
however, the docs are making my head swim.


I've got an example here, but I've had problems running
it between a Vista client and a win2k3 server; your
mileage may vary.

http://winsys.googlecode.com/svn/branches/it-support/winsys/fs.py

(Look for "class _DirWatcher" and the code below it)

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


Re: [python-win32] reliability issues with ReadDirectoryChangesW

2009-02-08 Thread Tim Golden

Eric Blade wrote:

I am getting significantly unreliable results using
ReadDirectoryChangesW, attempting to use a simplified version of the
codes that had been presented to me in my last query for help..


Eric, can you say what results you *are* getting and in what
way they're unreliable? I don't claim to have tested my own
version of this exhaustively, but it seems to work in simple
terms.

(Sorry, your code was just so messed up between your email
client and mine that I couldn't face putting it back together)

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


Re: [python-win32] reliability issues with ReadDirectoryChangesW

2009-02-08 Thread Tim Golden

Eric Blade wrote:
[... snipped code ...]


If it's possible, consider posting to something like pastebin
or some other online snippets clipboard so we can see the
whole code. It's even more difficult debugging something
when you only have half the code! :)

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


Re: [python-win32] Obtaining Outlook item properties from saved email file

2009-02-16 Thread Tim Golden

Paul Moore wrote:

Sorry, this is only peripherally a Python issue, as the code I'm
writing could just as easily be VBScript or any other language... But
as I'm writing in Python, and this group is full of helpful and
knowledgeable people... :-)

I have a folder full of emails saved from Outlook (.msg extension). I
want to extract from those files, the subject, sent/received date,
author, etc. Getting the properties isn't hard once I have a CDO
message object (or equivalent) to work with, but I've been unable to
find any way of getting a message object when all I'm given is the
filename of a ".msg" file in the filesystem.

Can anybody suggest a way to do this, or point me at sample code?


They're structured storage and a bit opaque. In principle
this (very sketchy and untested) code should get you started:


import pythoncom
from win32com import storagecon

filename = r"c:\temp\outlook.msg"
print pythoncom.StgIsStorageFile (filename)

flags = storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE
storage = pythoncom.StgOpenStorage (filename, None, flags)

for data in storage.EnumElements ():
 if data[1] == 2:
   print data[0]
   stream = storage.OpenStream (data[0], None, flags)
   print repr (stream.Read (data[2]))

#
# ... and now you've got an IStream interface which
# you can read etc.
#



There are some stream names listed here:

http://www.msusenet.com/archive/topic.php/t-288764.html 


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


Re: [python-win32] PyWin 32 variable instead of 'Nothing' in VB

2009-02-16 Thread Tim Golden

Payman Rowhani wrote:
We have a Visual Basic script that communicates with an application through com. 
We like to translate it to Python and use win32com.client instead. 
We have everything working, except for the use of "Nothing" in the 
VB script for a couple of its function calls. What is the replacement 
of "Nothing" in Python? Note that the generic "None" does not work. 



I *think* you can use pythoncom.Empty

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


Re: [python-win32] OnCtlColor not working?

2009-03-02 Thread Tim Golden

Greg Ewing wrote:

Well, it *almost* works now... it's okay for all the
button styles except BS_PUSHBUTTON.

My OnCtlColor is still getting called, but the
pushbutton seems to ignore the results. All the other
button styles are okay.

Am I still doing something wrong, or is this a known
limitation of pushbuttons?



It's a known limitation; or, at least, it was back in
1996 when I last tried to do this (on Win95). Maybe
things have changed since then, but maybe not...

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


Re: [python-win32] Question on parsing Reparse Points

2009-03-20 Thread Tim Golden

Philip Bloom wrote:
Hello, 


This is my first post the python win32 programming list, so hello.

I'm trying to figure out a way to tell where a Reparse Point
() is really pointing programmatically.  I can determine
pretty easily a folder is a Junction
(win32api.GetFileAttributes(folder)==1040), but from there, I can't seem
to find a way to tell where that reparse point is reparsing into.  I've
seen C++ code that does it, but it depends on FindFirstFile, which I
don't see in win32api or win32file for python.  



You'll need to use the DeviceIoControl function, exposed in
win32file from the pywin32 package. I don't think I've got
an example to hand, but you can pretty much transliterate
any C++ code. You'll have to roll your own structures, tho'.
There's a (random) example here in case it helps:

http://www.flexhex.com/docs/articles/hard-links.phtml

If I get the chance I'll put an example together.

FindFirstFile, btw, is sort-of exposed via win32file.FindFilesIterator
which wraps it and its companions as a Python iterator.

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


Re: [python-win32] how to hibernate from python ? how to detect idleness of the pc ?

2009-03-24 Thread Tim Golden

jo wrote:

Hi

I would like to automatically hibernate my home pc when my wife has not been 
using it for say half an hour.

Two things I dont know

- how to hibernate from python


http://mail.python.org/pipermail/python-win32/2008-June/007698.html


- how to detect idleness of the pc



That's more tricky. You can use GetLastInputInfo
from user32.dll via ctypes. But that only gives you
info about the app which called it (!). You could
try installing a system hook, but that's way too
elaborate and intrusive, I think.

What I suggest is that you simply detect when the
system goes into screen lock of its own accord. You
can use the technique described here, mutatis mutandis:

http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html

and then check additionally for whatever other long-running
processes you want to keep running.

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


Re: [python-win32] How to enumerate com ports?

2009-04-03 Thread Tim Golden

Alec Bennett wrote:
I'd like to get a list of available com ports on a Windows machine. 
I've seen some reference to a function EnumSerialPorts but can't 
find any documentation.


You can get it from WMI via the Win32_SerialPort class

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


Re: [python-win32] Move to mercurial?

2009-04-07 Thread Tim Golden

Mark Hammond wrote:

I'll cut a long story short and say that given Python has decided to move to
Mercurial, I'm more than happy for pywin32 to move to Mercurial too.  I'd
prefer to avoid having this turn into a debate of the relative merits of the
various DVCS systems, but I'd welcome any concerns or objections anyone has
with this.  Are there any timing issues?  (If anyone has changes pending,
I'm fairly confident this can be managed simply by doing "cvs diff" from the
cvs repo and using path to bring it into hg; from that moment things are
looking up; you can commit locally without pushing to the trunk!)


For me, the problem with the variety of dvcs is precisely
that there is a variety. I don't especially want to have to juggle
Git, Mercurial & Bzr (as well as svn & CVS) so I'd far rather you
went with Mercurial if only because it makes my Python life easier!

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


Re: [python-win32] IronPython in Action Out!

2009-04-11 Thread Tim Golden

Michael Foord wrote:

Hello all,

*Finally* IronPython in Action is out. This is the first English language
book on IronPython and is now in stock with Manning and Amazon.com and on
the Safari bookshelf. 


Excellent news. Must be great to see it in the flesh
after so much preparation! I look forward to getting
my hands on a copy.

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


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-17 Thread Tim Golden

John Randolph wrote:

Hi list:

I've been beating my head against this problem for 2 days and can't
figure it out.  Searching the archives produced a semi-relevant thread
from the past but the former fixes haven't worked for me.

Using wmi 1.3.2, I've got the following simple code:

system = wmih.SMS_R_System(NetbiosName=hostname)
new_rule = wmih.SMS_CollectionRuleDirect.new()
new_rule.ResourceID = system[0].ResourceID
new_rule.RuleName = '%s (%d)' % (hostname, system[0].ResourceID)
new_rule.ResourceClassName = 'SMS_R_System'
query_id, rv = c.AddMembershipRule(new_rule)

I've also tried getting the method InParameters, populating them and
calling the method directly as previous list traffic experimented
with.

However, neither method allows me to add the rule.   The code above
produces the following exception:

  File "remotewmi.py", line 115, in PolicyInstall
query_id, rv = c.AddMembershipRule(new_rule)
  File "C:\Documents and Settings\jrand\wmi.py", line 396, in __call__
handle_com_error (error_info)
  File "C:\Documents and Settings\jrand\wmi.py", line 189, in handle_com_error
raise x_wmi, "\n".join (exception_string)
wmi.x_wmi: -0x7ffdfff7 - Exception occurred.
  Error in: SWbemObjectEx
  -0x7ffbefff - Generic failure



Don't you love those "Generic failure" messages? I need to
put some better conversion code in there to help you
search for the error code. -0x7ffbefff is 0x80041001
when you twiddle the bits around, and that throws up
this kind of post:

 
http://myitforum.com/cs2/blogs/scassells/archive/2007/02/07/2147217407-error-or-80041001-how-to-avoid-progromatically.aspx

and this:

 
http://www.myitforum.com/forums/m_52995/mpage_1/key_gathering%252Ccollection%252Call%252Cworkstation%252Cdomain/tm.htm#52995

The first suggests a delay might help. The second doesn't come to
any conclusion except that if the last poster got it working then
it's something a bit environmental. Try the delay, perhaps. 


FWIW, the WMI code probably isn't calling Put_ on your
newly-created object, because it (probably) doesn't
have a Path_ -- it hasn't come off the WMI database.
According to the example at:

 http://msdn.microsoft.com/en-us/library/ms815919.aspx

that's correct. But just in case it makes a difference
you can try calling new_rule.Put_ () before you add it
to the collection. My feeling is that it will fail but
YMMV.

I'm afraid I'm not at all familiar with SMS and I'm certainly
nowhere near an installation, so it's hard for me to test or
reproduce the issue. Feel free to post back and I'm happy
to diagnose at a distance or to produce debug probes in the
WMI code itself.

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


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-18 Thread Tim Golden

John Randolph wrote:


Actually I had previously placed a delay between the new_rule creation
and calling AddMembershipRule for another reason -- to make a clear
break in the timestamps on the server side wmi logs.  Unfortunately
the delay doesn't help.


Shame.


Adding a Put_ gave me a different error, "Attempt to put an instance
with no defined key."


As I expected.

Not sure where to go from here, really.  


Me neither, I'm afraid. I'm more than happy to help
on the Python-WMI front, but outside that I'd be
playing guessing games with the SMS side of things.

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


Re: [python-win32] problem getting printer status in Windows

2009-04-21 Thread Tim Golden

Alec Bennett wrote:
I'm having trouble getting the printer status in Windows. 
Ideally I'd like to get the info contained in the "Status" column 
when you open a printer from the Windows control panel --> printers.


Generally, altho' not always, questions like this have an answer
which starts with "WMI". In this case I'm not absolutely convinced,
but it looks quite good. Guessing that the Win32_Printer class is
what you want leads to this:

 http://msdn.microsoft.com/en-us/library/aa394363(VS.85).aspx

and the PrinterStatus or ExtendedPrinterStatus attributes which 
looks handy. So...



import wmi

c = wmi.WMI ()
for p in c.Win32_Printer ():
 print p.Caption, p.Printerstatus


 
Frankly I've no idea if it's any more or less reliable than your

other method; maybe someone who's done more printer-related work
can chip in here. But it at least opens an alternative avenue
for you to look at.

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


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-21 Thread Tim Golden

John Randolph wrote:

On Sat, Apr 18, 2009 at 8:09 PM, Tim Golden  wrote:

John Randolph wrote:


Actually I had previously placed a delay between the new_rule creation
and calling AddMembershipRule for another reason -- to make a clear
break in the timestamps on the server side wmi logs.  Unfortunately
the delay doesn't help.

Shame.


Adding a Put_ gave me a different error, "Attempt to put an instance
with no defined key."

As I expected.


Not sure where to go from here, really.

Me neither, I'm afraid. I'm more than happy to help
on the Python-WMI front, but outside that I'd be
playing guessing games with the SMS side of things.

TJG



Tim,

is there any more debugging info I can gain on the python wmi side?
I tried setting debug=True but that gives minimal info, mostly wsql
queries during object selection, etc.

Regards
John


There's nothing else built-in, I'm afraid. I'm perfectly happy to
produce an instrumented version of the current release if it'll
help -- or you could just run:

 python -mtrace --trace --ignore-dir c:\python26\lib your-prog.py > 
your-prog.trace.log

In my case, wmi is run out of a subversion checkout somewhere
outside site-packages; excluding c:\python26\lib misses out all
the underlying win32com stuff. This will at least show you
the code path in all its rawness. I honestly expect that this
will just confirm that the problem is outside the Python bit,
but I'm very happy to be proved wrong.

If you want to, run with this and send me the output so I can at
least see what happens.

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


Re: [python-win32] Programatically activating secondary monitor?

2009-04-30 Thread Tim Golden

Alec Bennett wrote:
I'm wondering if there's a way to enable a second monitor in Windows 
from Python or otherwise programatically? Currently I use the utility UltraMon, 
which works, but it sure would be nice to be able to do this from Python.


I'm not quite sure I understand what "enable a second monitor" means here.
But (since I have no specific expertise to offer in this area) I will
offer my usual response: can you find out how to do what you want on
Windows in general, eg from an MS Group or a codeproject.com example, etc.?
Once we've got the technique nailed then it's a question of how best to
translate that into Python -- if it's feasible.

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


Re: [python-win32] gpedit reload method in python

2009-04-30 Thread Tim Golden

le dahut wrote:

Hello,

"gpedit.msc" can change several parameters in system for example items 
in start menu or hidden drives in explorer. The changes made in "gpedit" 
are immediately applied, if you have "My computer" opened you can see 
selected letters disappear.
I know that "gpedit" modifies 
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDrives.
But I don't know how "gpedit" updates the system, what sort of system 
call is done.


I've already tried :
 win32gui.SendMessage(win32con.HWND_BROADCAST, 
win32con.WM_SETTINGCHANGE, 0, 'Environment')

and the commande :
 RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
without success.

Does someone know more about this ?
Are there other API calls that update the system ?



You might need to call SHChangeNotify

 http://msdn.microsoft.com/en-us/library/bb762118(VS.85).aspx

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


Re: [python-win32] Silent installation of pywin32

2009-05-08 Thread Tim Golden

siddhartha veedaluru wrote:

Hi all

Do we have a way to install pywin32 module silently.?
Does the exe which is downloable support silent installation?


Don't think so; your best bet is probably to rebuild
as an MSI which you can install with a "silent running"
mode.

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


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-05-11 Thread Tim Golden

John Randolph wrote:

On Tue, Apr 21, 2009 at 3:52 PM, Tim Golden  wrote:

Actually I had previously placed a delay between the new_rule creation
and calling AddMembershipRule for another reason -- to make a clear
break in the timestamps on the server side wmi logs.  Unfortunately
the delay doesn't help.


Tim, all:

My "Generic Failure" error when calling AddMembershipRule(new rule)
turned out to be permissions related.  My local Windows admins have
segregated read and write access into two groups and my role account
didn't have write access.   oops.

Unfortunately I learned no further details on how to decode "Generic
failure" into "Bad permissions" for the list, though, sorry.   The WMI
service logs look clean so you probably need to dive into the SMS
logs.


Thanks for the update.

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


Re: [python-win32] Fwd: Autosizing column widths in Excel using win32com.client ?

2009-05-17 Thread Tim Golden

James Matthews wrote:

-- Forwarded message --
From: 
Date: Fri, May 15, 2009 at 7:45 PM
Subject: Autosizing column widths in Excel using win32com.client ?
To: python-l...@python.org


Is there a way to autosize the widths of the excel columns as when you
double click them manually?


Usual answer to this kind of question: record a macro
in Excel to do what you want, and then use COM to
automate that. On my Excel 2007, this is the VBA result
of recording:


Sub Macro2()
'
' Macro2 Macro
'
'
   Columns("A:A").Select
   Range(Selection, Selection.End(xlToRight)).Select
   Columns("A:D").EntireColumn.AutoFit
End Sub



You then just fire up win32com.client or comtypes,
according to taste and go from there. If you need
help with the COM side of things, post back here.

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


Re: [python-win32] Re ading date from PYTime

2009-05-19 Thread Tim Golden

SantoshMohan wrote:

Hi,

I am writing a script to read date from xls file.

Output is like this:


emptylist

[((u'Name', u'DOB'),), ((u'C R RAMESH', ),),
((u'G SIVA RAMA KRISHNAIAH', ),)]


emptylist[1]

((u'C R RAMESH', ),)


value

((u'C R RAMESH', ),)

value[0][1]



How to read the date and Time?


http://timgolden.me.uk/python/win32_how_do_i/use-a-pytime-value.html

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


[python-win32] Distutils changes broke pywin32 build

2009-05-19 Thread Tim Golden
Something in the changes to build_ext.py in r72585 
has broken the setup.py build for pywin32:


http://svn.python.org/view/python/trunk/Lib/distutils/command/build_ext.py?r1=72531&r2=72585&pathrev=72585

The symptom is that pywintypes.lib is created in the
build directory, but distutils is then looking to
copy pywintypes27.lib (note the version suffix):

error: can't copy 'build\temp.win32-2.7\Release\win32\src\pywintypes27.lib': 
doesn't exist or not a regular file

The error is also present in the release26-maint branch.

I've just started to try to work out where exactly the problem
lies and whether it's an ill-tested distutils change or a false
assumption in the pywin32 setup.py. Or something else.

Since distutils is a notorious maze of twisty modules, all alike,
and since the pywin32 setup.py is hardly a model of simplicity,
if anyone has immediate insights I'd be glad to hear them.

Thanks

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


Re: [python-win32] Distutils changes broke pywin32 build

2009-05-19 Thread Tim Golden

Tim Golden wrote:
Something in the changes to build_ext.py in r72585 has broken the 
setup.py build for pywin32:


http://svn.python.org/view/python/trunk/Lib/distutils/command/build_ext.py?r1=72531&r2=72585&pathrev=72585 


Well, in short, it's a change in the way in which package
prefixes are used when retrieving the filename in pywin32's 
setup.py at lines 1123ff.


As it stands, none of the if conditions in that function are
firing, because the package-qualified name is never passed in.
Therefore the default build_ext.get_ext_filename is called and
the version info is never added to the filename.

I've posted this here because I don't know whether to characterise
this is a bug on the Python tracker or on the pywin32 one. Opinions
sought...

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


Re: [python-win32] Distutils changes broke pywin32 build

2009-05-19 Thread Tim Golden

Michael Foord wrote:

Distutils is undergoing heavy changes in the hands of Tarek Ziade. One of
the changes is drastically improving the test coverage.

I would definitely discuss the problem with him (directly or on
distutils-sig) as he will want to know about it - either to explain why the
change is necessary and help you modify the pywin32 setup.py or to revert
the change.

Michael Foord


Thanks, Michael. I'll go over to distutils-sig. (Not my
usual stamping ground :) ).

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


Re: [python-win32] Distutils changes broke pywin32 build

2009-05-19 Thread Tim Golden

Tim Golden wrote:
Something in the changes to build_ext.py in r72585 has broken the 
setup.py build for pywin32:


[... after discussions on distutils-sig ...

http://mail.python.org/pipermail/distutils-sig/2009-May/011901.html
]

Looking like it's an issue in distutils. Tarek's said
he'll get a fix & test in place.

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


Re: [python-win32] Converting types for deep lists or Discitonnaries

2009-05-21 Thread Tim Golden

Dominick Lauzon wrote:

I need to convert a multi-level and multi-type list and dictionary (keys
and values) to string format.

Is there a way to do this globally rather than iterating item to
str(item)?


Not really a win32-specific question... but it's the kind
of thing which gets asked and answered fairly frequently
on the main python list:

 http://mail.python.org/mailman/listinfo/python-list

and in the ActiveState cookbook:

 http://www.activestate.com/ASPN/Python/Cookbook/

(the key terms are "flattening" and "pretty print")

and someone recently recommended Armin Ronachers pretty:

 http://lucumr.pocoo.org/2007/10/21/pretty-a-python-pprint-successor


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


Re: [python-win32] overview of ntfs permissions ?

2009-05-27 Thread Tim Golden

Stef Mientki wrote:

hello,

is there a way to get an overview of ntfs permissions,
of a specified part of a directory tree ?


(I've recently answered amost this question over on
StockOverflow as it happens: it wasn't you, was it? :) )

One answer is to use cacls / xcacls, the command-line
tool which ships with Windows.

If you want a Python-y way of doing it (which is,
I assume, why you asked here) then I can do no better
than recommend my fledgling winsys module:

MSI here:
 http://timgolden.me.uk/python/downloads/WinSys-0.4.win32-py2.6.msi

or Subversion here:
 svn co http://winsys.googlecode.com/svn/trunk winsys

The code would then be something like (depending on what you
actually wanted to show...):


from winsys import fs

ROOT = "c:/temp"
#
# For purposes of illustration, just show directories
#
for directory, dirs, files in fs.walk (ROOT):
 dirpath = directory.filepath.relative_to (ROOT)
 indent = "  " * dirpath.count (fs.sep)
 print indent, dirpath
 security = directory.security ()
 for dace in directory.security ().dacl:
   print indent, dace
 print



Obviously, it depends on exactly what you're after. If you'd
rather do it with "native" Python+pywin32, I'm happy to produce
an example, but it's a bit tedious (which is why I wrote the
winsys package to save myself the trouble of remembering...)

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


Re: [python-win32] Query on - win32 impersonate user

2009-06-08 Thread Tim Golden

Vikas NV wrote:

Hi,

I have been trying to use the Impersonate user code that you have in
the PyWin32.chm document.


[... snip ...]


obj = Impersonate('another_user', '01928348')
obj.logon()
print win32api.GetUserName()
os.system('bash sleep.sh')
obj.logoff()


Unfortunately when you do os.system, Windows uses the
original user, not the impersonating user. By good
fortune, this issue came up just last week and someone
posted a ctypes implementation of CreateProcessWithLogonW:

http://mail.python.org/pipermail/python-win32/2009-June/009192.html



Hopefully you can take it from there...

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


[python-win32] MAPI CopyMessages

2009-06-08 Thread Tim Golden

Has anyone had success using the PyIMAPIFolder CopyMessages method?
The spambayes source looks as tho' it's using it happily, so I can't
imagine there's any fundamental problem. Only... it doesn't work for
me. :(

I have a reproducible test case attached which is -- in the way of the
extended MAPI code -- a bit wordy. But I believe it is self-contained
and could be run by anyone with an Exchange account and a folder called
"Docs". The code is also on pastebin: http://pastebin.com/m575adec6

In short, I find my Inbox and my Docs folder and attempt to copy an
arbitrary message from the one to the other. The code completes without
error, but nothing seems to be happening. There's nothing to suggest
that any "commit"-type action is necessary. Just in case, I've tried
various combinations of SaveChanges to no avail. I look in the Docs
folder on Outlook and nothing's there.

All suggestions gratefully received.

TJG
from win32com.mapi import mapi, mapitags

LOGON_FLAGS = mapi.MAPI_NO_MAIL | mapi.MAPI_UNICODE | mapi.MAPI_EXTENDED | 
mapi.MAPI_USE_DEFAULT

mapi.MAPIInitialize ((mapi.MAPI_INIT_VERSION, 0))
try:
  session = mapi.MAPILogonEx (0, "", None, LOGON_FLAGS)
  try:
#
# Find the default message store (my Mailbox)
#
message_stores = session.GetMsgStoresTable (0)
filter = mapi.RES_PROPERTY, (mapi.RELOP_EQ, mapitags.PR_DEFAULT_STORE, 
(mapitags.PR_DEFAULT_STORE, True))
mailbox = None
for rows in mapi.HrQueryAllRows (message_stores, (mapitags.PR_ENTRYID,), 
filter, None, 0):
  for tag, store_id in rows:
mailbox = session.OpenMsgStore (0, store_id, None, 
mapi.MAPI_BEST_ACCESS)
break
if not mailbox:
  raise RuntimeError ("Can't find mailbox")
  
#
# Find my inbox
#
inbox_id, _ = mailbox.GetReceiveFolder (None, 0)
inbox = mailbox.OpenEntry (inbox_id, None, 0)

#
# Find my Docs folder
#
n_props, props = mailbox.GetProps ([mapitags.PR_IPM_SUBTREE_ENTRYID])
for tag, root_folder_id in props:
  root_folder = mailbox.OpenEntry (root_folder_id, None, 0)
  break
else:
  raise RuntimeError ("root folder not found")

hierarchy = root_folder.GetHierarchyTable (0)
for item in mapi.HrQueryAllRows (hierarchy, None, None, None, 0):
  tags = dict (item)
  if tags[mapitags.PR_DISPLAY_NAME_A] == "Docs":
docs_folder = mailbox.OpenEntry (tags[mapitags.PR_ENTRYID], None, 0)
break
else:
  raise RuntimeError ("Docs not found")
  
#
# Pick up a random message from the inbox
#
inbox_contents = inbox.GetContentsTable (0)
for item in mapi.HrQueryAllRows (inbox_contents, None, None, None, 0):
  tags = dict (item)
  print tags[mapitags.PR_SUBJECT_A]
  message_id = tags[mapitags.PR_ENTRYID]
  break

#
# Now:
#   inbox - PyIMAPITable
#   docs_folder - PyIMAPITable
#   message_id - Entry ID of a specific message in the Inbox
#
result = inbox.CopyMessages (
  [message_id],
  None,
  docs_folder,
  0,
  None,
  0
)
  
  finally:
session.Logoff (0, 0, 0)
finally:
  mapi.MAPIUninitialize ()
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] MAPI CopyMessages

2009-06-08 Thread Tim Golden

Tim Golden wrote:

Has anyone had success using the PyIMAPIFolder CopyMessages method?
The spambayes source looks as tho' it's using it happily, so I can't
imagine there's any fundamental problem. Only... it doesn't work for
me. :(


[... snip ...]


Don't you hate it when that happens? Of course, you have to open the
folder with the MAPI_MODIFY flag, otherwise you can't write to it.
That said, it does fail silently; but at least I can move forward now.

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


Re: [python-win32] Regarding build of code using Visual Studio in python

2009-06-16 Thread Tim Golden

a h wrote:

I have a C source code, i want to build it using Visual Studio without using
its IDE. Actually i want to know that how do i write code/script in python
so that it builds my "source.c" file and provides me "source.obj" and
"source.exe" files.


If that's really all you want, you don't really need much
of a tool. But since it's easy enough, have a look at scons:

http://www.scons.org/

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


Re: [python-win32] COM sending and receiveing events

2009-06-22 Thread Tim Golden

Christian K. wrote:

Hi,

I apologize for my ignorance about COM programming in advance. I would like to
be pointed to an example of how I could send a message from a subthread of a COM
server back to the main thread. Being an outlook addin, the COM server is
already reacting to a couple of Outlook generated events. Now it would like to
add my own simple event handling and generation code. I have looked in the
win32com/demos folder and searched on that list, but I think I know too little
about COM to understand that information.



I'm not entirely clear at what level you're asking. If you
want to pass an object around between threads, you'll need
to marshal it up. Look in pythoncom at:

 
http://timgolden.me.uk/pywin32-docs/pythoncom__CoMarshalInterThreadInterfaceInStream_meth.html
 http://timgolden.me.uk/pywin32-docs/pythoncom__CoMarshalInterface_meth.html

and  


 http://timgolden.me.uk/pywin32-docs/pythoncom__CoUnmarshalInterface_meth.html

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


Re: [python-win32] SetSystemTime: A required privilege is not held by the client

2009-06-24 Thread Tim Golden

Robert wrote:

Tim Golden wrote:

Robert wrote:

SetSystemTime on Vista admin account throws:

(1314, 'SetSystemTime', 'A required privilege is not held by
the client.')


Not known from previous Windows versions.
With what switch or whatever can this be enabled?


According to the docs:
(warning: URL will self-destruct in two months)

http://msdn2.microsoft.com/en-us/library/ms724942(VS.85).aspx

this operation automatically enables the SE_SYSTEMTIME_NAME priv
which is disabled by default. But if your user doesn't *have* the
priv to start with, it won't be enabled and you'll get the error message
above.

I don't run Vista, but I assume it has some kind of user-management
user interface? Find whatever bit of that deals with privileges (*not* 
groups)

and add this priv to the user in question.



does anybody with Vista know if there is a UI tool for setting this 
SE_SYSTEMTIME_NAME privilege in an account - how ?



(Goodness, that reply took a long time to come through :) )

Try Start > Run > secpol.msc - that works on XP

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


Re: [python-win32] Permission denied erro while copying file from remote machine to local using win32wnet.WnetAddConnection

2009-06-30 Thread Tim Golden

siddhartha veedaluru wrote:

Hi,

I have used the following code snippet to copy files or folder from remote
machine to local machine.
I have used the same method to copy files to remote machine.

Can  some one point me to solve this?



Am I missing something? Or can't you just catch the permission denied
error and ignore it? Or connect via a user which *has* the right permissions?

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


Re: [python-win32] Shell extension debugging

2009-06-30 Thread Tim Golden

Thomas Heller wrote:

Gertjan Klein schrieb:

2) I see print statements in the source code, but I have no idea where
they go; I checked the event log, but they are not there. Are they
logged anywhere? If not, why are they there to begin with?

Any other tip on how to effectively debug this stuff would be most
welcome as well.

The print statements go into empty space because there is no stdout for
that process.  You can try using the logging module to log to a file, or
you can use ctypes to write to kernel32.OutputDebugString and using a
kernel debug log monitor to read them.

The logging module reminds me of Java too much. :(  I think I'll try to
write to a file, I have no idea if I have a kernel debug log monitor.


For stuff like this you should look around at the sysinternals site.  They have
a DebugView utility that displays these log strings.  ProcessExplorer is also
a very nice and useful replacement or addition for the task manager.


I second the sysinternals visit. But just in case you fancy the
exercise, you can use Python to trap OutputDebugString calls:

http://timgolden.me.uk/python/win32_how_do_i/capture-OutputDebugString.html

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


Re: [python-win32] Shell extension debugging

2009-06-30 Thread Tim Golden

Tim Golden wrote:

Thomas Heller wrote:

Gertjan Klein schrieb:

2) I see print statements in the source code, but I have no idea where
they go; I checked the event log, but they are not there. Are they
logged anywhere? If not, why are they there to begin with?

Any other tip on how to effectively debug this stuff would be most
welcome as well.

The print statements go into empty space because there is no stdout for
that process.  You can try using the logging module to log to a 
file, or

you can use ctypes to write to kernel32.OutputDebugString and using a
kernel debug log monitor to read them.

The logging module reminds me of Java too much. :(  I think I'll try to
write to a file, I have no idea if I have a kernel debug log monitor.


For stuff like this you should look around at the sysinternals site.  
They have
a DebugView utility that displays these log strings.  ProcessExplorer 
is also

a very nice and useful replacement or addition for the task manager.


I second the sysinternals visit. But just in case you fancy the
exercise, you can use Python to trap OutputDebugString calls:

http://timgolden.me.uk/python/win32_how_do_i/capture-OutputDebugString.html



And also the win32traceutil facility which comes with the pywin32
extensions can help you out here. If you import win32traceutil in
any module, sys.stdout (and maybe stderr) is redirected to a pipe
which is picked up by running the win32traceutil module as a script:

python -mwin32traceutil

Insanely helpful when you're trying to debug, an ISAPI extension
module.

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


Re: [python-win32] Sourceforge pywin32 site seems to be down

2009-07-07 Thread Tim Golden

Fadhley Salim wrote:

https://sourceforge.net/projects/pywin32/


Works for me.


The Sourceforge PyWin32 download site seems to have been down for a very
long time. Is there an alternate source of downloads? 


sf has just changed their entire site, it appears. There have been
grumbles about it breaking easy_install as well...

Try this:

 http://sourceforge.net/projects/pywin32/files/

If you can't get through, let me know and I can pull something
for you and drop it somewhere else.

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


Re: [python-win32] Python parser for Windows Event Logs

2009-07-09 Thread Tim Golden

Tony Cappellini wrote:

Thanks, but those just monitor events.

I need to pull some very specific data from an event log file, after I
know the event has already occurred.

Tim has another module called winsys, and there is an object which
handles some aspects of reading event logs.
http://timgolden.me.uk/python/winsys/event_logs.html#module-event_logs

Tim - what I need to is pull this structure
http://msdn.microsoft.com/en-us/library/ms810313.aspx

from the event log, AFTER an event 51 has already occurred.
http://support.microsoft.com/kb/244780

I can easily look at the Event Viewer to determine if the event has occurred.

I don't see it at a glance, but does your winsys module have a way to do this?

If not, I'll just have to hard code offsets and use the struct module to get it.


You can certainly get hold of the event log record via
WMI or via WinSys (which just wraps the pywin32 module
someone else referred to). But there's not special code
for reconstructing the rather specific data structure
you refer to. You'll need to use struct or ctypes for
that.

Let me know if you need help getting the data out in
the first place; I'm not clear whether you've got that
covered or not. (And whether you want to be notified
when the event fires or whether you're merely scanning
historically).

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


Re: [python-win32] Copying a MS Access Table

2009-07-28 Thread Tim Golden

sebastian.ve...@uk.bnpparibas.com wrote:

Hi, how can I make a copy of a table in an Access database using Python?
The VBA command would be 'DoCmd.CopyObject'. If there is no such command 
for Python, then alternatively I could request Python to call a VBA 
function that does that, but I don't know how to do that either.


[... snips longest signature in the known universe ...]



Depends on where you're starting from. You can use the win32com.client
modules from the pywin32 package to automate pretty much anything in
the COM world, including Access. At the same time, you can use the
adodbapi module in that same package to access the db directly. You
only need to look around the web for examples of what you want to
do in any language and then translate them into Python.

If you're still stuck, feel free to post back here. (I'm pretty
sure there isn't an MSAccess-specific package for Python).

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


Re: [python-win32] Copying a MS Access Table

2009-07-29 Thread Tim Golden

[copying back to the list]

Not sure how to reply to the thread, since I thought that if I reply to 
"python-win32@python.org" then it would start a new thread? 


Replying to python-win32@python.org is the right thing to
do; the mailing list software should recognise all the
clues it needs to continue the thread.


sebastian.ve...@uk.bnpparibas.com wrote:

Hi Tim,

I tried this:

a = win32com.client.Dispatch("access.application")
connStr = 'Driver={PostgreSQL 
Unicode};Server=%s;Database=%s;Uid=%s;Pwd=%s;ConnSettings="set TimeZone to 
-8; set search_path to pid,public;"'


Well that surprised me: you're using Access as a frontend
to PostgreSQL? 


a.OpenCurrentDatabase(r'C:/TEMP/db1.mdb')
a.DoCmd.CopyObject(connStr,'MyTable2',0,'MyTable1')


but it threw an exception that I couldn't interpret. Can you please help? 


This is obviously tricky with two different databases in 
the equation, one of them PostgreSQL, but what will be

most helpful is for you to produce an easily reproducible
sample which someone else can run, plus the traceback you
get. Going through this exercise may even cause you to
track down the problem yourself. In particular, try to
eliminate external dependencies: try to do the copy table
thing between two Access databases, or within the same
one (if that's possible; I haven't used Access in earnest
for a while now).

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


Re: [python-win32] faster way to get printer status?

2009-08-05 Thread Tim Golden

Alec Bennett wrote:

I'm trying to get the online/offline status of a printer, and using WMI I'm 
finding it very slow. Here's the code I'm working, maybe there's some way to 
opimize it? Or some other way? I'm able to use win32print to query the status 
of an online printer, but not to find out whether its online or not (its 
pStatus always returns 'Idle').

def check_printer(printer_name):

.c = wmi.WMI ()

.for p in c.Win32_Printer():

..if p.caption == printer_name:

...if p.WorkOffline:
..print "its offline"
...else:
..print "its online"





Generally, check out the speedup hints here:

http://timgolden.me.uk/python/wmi-tutorial.html#speeding-things-up

but as a rule WMI is not the fastest thing on earth,
so if you really need speed, you'll need to drop
down to the Win32 API and go from there. I can't
remember exactly what you need off-hand, altho'
it's probably in the win32print module.
Perhaps someone else can
fill in for me here...?

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


Re: [python-win32] regarding ftp api call

2009-09-23 Thread Tim Golden

a h wrote:

Hi all
i have created an ftp client using ftp api provided in python. whenever i
disconnect my ftp client with the ftp server by removing the wired
connection, my ftp application get hanged, i traced with prints and find
that whenever call made to ftp api, it never came back. How do i
resolve this as it does not return any error or value.
Plz help, thanks in advance


It always helps if you provide some sort of code sample which
shows the problem (or at least, where the problem occurs). But
I would imagine that you've got an open socket with no timeout.
As a quick workaround, try adding this before your FTP code:



import socket
socket.setdefaulttimeout (1.0)



which will cause a socket to time out in 1 second. You'll then have
to catch whatever exception it raises and do something meaningful
within the context of your code.

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


Re: [python-win32] regarding ftp api call

2009-09-23 Thread Tim Golden

[copying back to the list]

Please keep the conversation on-list, a h. We're all
happy to help you, but none of us is a private
consultant -- at least not an unpaid one! Also,
the more people who see what you post, the more
people there are who might be able to answer.

a h wrote:

I have wriiten this piece of code which works fine. which retrieve files
from server and dumping to the local folder

import ftplib
f = ftplib.FTP("server_host_name")
while True:
f.pwd()
...
...my logic
f.retrbinary("RETR %s"% fname, myFile.write)
...

but when disconnected say wire remove then it hang in loop, it does not
throw any exception or any error. I traced by putting prints, and find that
it hanged in ftp api call like "f.pwd()  OR f.retrbinary()" and never return
back



Did you try my suggestion of setting a socket timeout?

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


Re: [python-win32] regarding ftp api call

2009-09-24 Thread Tim Golden

a h wrote:

hi
thanks for the replies.
setting socket timeout works fine.
I also find alternate way that perform the same thing,ie ftp connection
timeout.

import ftplib
f = ftplib.FTP("server_host_name", "TIMEOUT")



Thanks for posting back. And I learnt something new: that the
FTP initialiser takes a timeout parameter, so thanks for
educating me. I would point out, tho', that your quick
example above obviously *won't* set the timeout; it will
connect to the server with a username of "TIMEOUT". Hopefully
you knew that and were just jotting quickly, but for any
future readers, the timeout is most easily specified as
a named param to the FTP constructor:

f = ftplib.FTP ("mail.python.org", timeout=2.0)

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


Re: [python-win32] win32api documentation

2009-10-09 Thread Tim Golden

J wrote:

I've been searching high and low looking for any sort of decent
reference for the win32api in python and I can't find anything that is
useful.


There isn't much, in spite of a few attempts (my own included)
to get something going. There's never enough time...


Ultimately, the win32api calls *are* wrapping the MSDN calls
almost directly so you just have to dive in, but ...



So what I'm trying to do for now, is fairly simple.  I just want to be
able to make a couple calls and get system info like the number of
processor packages, the number of processor cores, processor flags (if
possible), free mem, total mem, OS version and a few other tidbits of
system information.



Here at least I can help. Try using WMI which eats this kind of
thing for breakfast[*]. Start here:

 http://timgolden.me.uk/python/wmi.html

taking in this:

 http://timgolden.me.uk/python/wmi-tutorial.html

and this:

 http://timgolden.me.uk/python/wmi_cookbook.html

and feel free to get back with specifics.

TJG

[*] I hope :)
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32api documentation

2009-10-09 Thread Tim Golden

J wrote:

Awesome!  Thanks a lot.  I'll dig into that after lunch.  I finally
stumbled on the ActiveState info on win32api with a ref for all the
calls, and I'll have to do a little more digging.  


Well that's simply a copy of the CHM which is provided with
the pywin32 installation. I host another copy over here:

 http://timgolden.me.uk/pywin32-docs/contents.html

for private entertainment. It's fairly searchable using Google, eg:

http://www.google.co.uk/search?q=site%3Atimgolden.me.uk%2Fpywin32-docs+EnumProcesses

and has a bit of breadcrumbness about it to help you out. But,
as I say, it's merely an online copy of the .chm which is itself
eminently searchable.


I found out finally

how to pull SYSTEM_INFO (turns out it IS farily trivial) but now I
have other things to figure out (which is nice, as it actually gives
me something to do while I'm waiting on the next project to start).

I can pull most of what I need now after finding the ActiveState
reference, but specifically, I'm having trouble with:

Number of logical processors (counting cores with and without
HyperThreading enabled in BIOS)
Number of processor packages
Total system RAM
Available RAM

I think I can figure out the RAM, but right now it's the processor
counting and info that's dogging me.

Anyway, like I said, I'll dig into the WMI stuff in a bit after a nice
break from the lab and this nasty chair.


Although I'm the author of the Python wmi module, WMI itself
covers such a huge area that I have absolutely no pretence
at comprehensive knowledge. Faced with queries such as yours,
I'd normally just stick, eg, "available ram wmi" into Google
and go from there. There's lots of info out there aimed at
C or vbs developers; translating it into Python's usually
not too hard.

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


Re: [python-win32] win32api documentation

2009-10-12 Thread Tim Golden

J wrote:

Ok... that all helped a lot.  I've been playing around with memory a
bit, and cache, and I'll poke at that some more later.  Today I've
been looking into processors.

So WMI provides Win32_Processor and from what I've read, there exists
one instance of Win32_Processor for each processor on a SMP machine.

So for starters, I assume then that if I had one such machine, I could
count all the cores simply by doing something like:

for p in c.Win32_Processor :
procCount = procCount + 1

which makes sense.


Ummm. Not quite.

c.Win32_Processor is a class-ish thing which you have to call to
pull back the *list* of instances. Which you can then just
count. So something like this:

n_processors = len (c.Win32_Processor ())

I can't at this moment remember how the c.Win32_Processor interacts
with physical processors, multicore processors and hyperthreading.
It's probably documented somewhere, and a little experimentation
should give you answers quite easily. That's the great thing with
Python: you just fire up the interpreter and get the answer!


Now that I look at it, I seem to be able to pull information based on
each core, and I can count cores.  But what about counting processor
sockets or packages?  For example,

Lets say, I do that simple loop and get a return of 16.

How do I differentiate between 16 cores, or 8 cores with
HyperThreading turned on?

Admittedly, that's more an educational curiosity.  The systems I'll be
using all this on are readily accessible, and we'll know ahead of time
that System A has 2 4-core processors and that we turned HT off in
BIOS, so we should only see 8 logical processors when we test.  Any
delta from that will fail the test.

So like I said, I was just curious if there is any built in way via
WMI or whatever to differentiate without having to go and manually
create a class based on the Windows API (because I'm not good enough
to do that kind of work).


This is definitely the place to look for this kind of information:

http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx

unfortunately, some of the useful information like NumberOfCores
and NumberOfLogicalProcessors seems to be available only on the
very latest releases. Might be an issue for you?




Either way, thanks for the help so far, the WMI wrapper is pretty
cool.  I've never written system level code before, beyond
instrumenting some device drivers and services to see why they break,
so this has been pretty fun so far as a learning experience.


Glad it's been useful. I'm just releasing a new version of the
Python module which includes a little web server whichi lets you
browse around the classes to a limited extent. If you're interested,
let me know.

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


Re: [python-win32] win32api documentation

2009-10-13 Thread Tim Golden

J wrote:

And it does indeed work.  We're using the latest 2.6, and so far
everything has worked well. NumberOfCores and
NumberOfLogicalProcessors does just what I hoped they would do, so now
I have a small bit of n00b code:

print "Getting processor information now...\n"


I suspect you're coming from a C background? Or something
similar. Python's a very versatile language and tries to
help you avoid boilerplate. So you can do things like this:


import wmi

c = wmi.WMI ()
numProcs = len (c.Win32_Processor ())
print "Number ...:", numProcs
# or
print "Number ...: %s" % numProcs


and likewise for your other print statement. (Watch out:
print has become a function in Python 3.x). The percent-s
thing works just like sprintf in C only with a Python touch:
you can use a more restrictive %d %2.3f etc. but if you put
%s, Python calls your object's __str__ method which will usually
generate what you expect to see.


numProcs = len(c.Win32_Processor ())
print "Number of Processor Packages found: " + str(numProcs)
for p in c.Win32_Processor ():
  print "Number of processor cores: " + str(p.NumberOfCores)
  print "Number of Logical processors: " + str(p.NumberOfLogicalProcessors)
  if p.NumberOfCores != p.NumberOfLogicalProcessors :
  print "HyperThreading seems to be enabled."



This is definitely the place to look for this kind of information:

http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx

unfortunately, some of the useful information like NumberOfCores
and NumberOfLogicalProcessors seems to be available only on the
very latest releases. Might be an issue for you?


THANKS!  Once again, you're wisdom blows my mind ;-) and your link-fu.


I blush. But in fact (he says, giving away all his secrets) my
magic incantation was simply this:

http://www.google.co.uk/search?q=site%3Amicrosoft.com+win32_processor

Of course, I have done that once or twice before ;)


Glad it's been useful. I'm just releasing a new version of the
Python module which includes a little web server whichi lets you
browse around the classes to a limited extent. If you're interested,
let me know.


Sure... it'd be neat to play with.  Like I've said before, this is
going to be actually useful, but I'm doing it out of boredom and as a
learning experience more than I am doing it to benefit work or
anything like that.  They don't pay me enough to really want to work
for their benefit ;-)


I'll put a release notice out in the next day or two and let you
know where you can get hold of it.



I have run into another issue though with the various Memory classes...


[... snip rather specific Memory stuff ...]

I'm afraid I've no particular insight here. I'm sure I can Google
around a bit to see, but I'm sure you can too...

Keep posting to the list and let's see if someone else has
an idea.

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


Re: [python-win32] wmi query error

2009-10-21 Thread Tim Golden

Nick Moszer wrote:

Hello,

I'm occasionally receiving the following error when doing a set of queries:


Traceback (most recent call last):
  File "psg5220_demo.py", line 236, in find_hdd_drives
partitions = services.query(query)
  File "...path..\wmi.py", line 889, in query
return [ _wmi_object (obj, instance_of, fields) for obj in
self._raw_query(w
ql) ]
  File "C:\Python26\lib\site-packages\win32com\client\util.py", line 84,
in next

return _get_good_object_(self._iter_.next(), resultCLSID =
self.resultCLSID)

pywintypes.com_error: (-2147217406, 'OLE error 0x80041002', None, None)


To make talking about it easier, I've slightly reworked
your code to make it run completely (ie I've added imports and
the initialisation of the data structures) and 
to take advantage of the wmi module's built-in features.

Hopefully it's perfectly clear what's going on; I've just avoided
some of the more "raw" wmi in your code.

I've also turned off find_classes as you don't really want this
in running code; it's more for use the interpreter. The latest
version of the module 1.4 turns this off by default which makes
the startup time much faster.


import wmi

services = wmi.WMI(privileges=["security"], find_classes=False)

serials = {}
serials_reversed = {}
drive_letters = {}

for disk in services.Win32_PhysicalMedia():
 serials[disk.Tag] = disk.SerialNumber
 serials_reversed[disk.Tag] = disk.SerialNumber

for physical_disk in services.Win32_DiskDrive():
 for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
   for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
 drive_letters[logical_disk.DeviceID.rstrip(":")] = physical_disk.DeviceID

print serials
print serials_reversed
print drive_letters



FWIW, the physical-logical drive stuff is straight out of the
Cookbook page:

http://timgolden.me.uk/python/wmi/cookbook.html#show-disk-partitions


This is on Windows XP and Vista both.  It sometimes happens once then
not again for 50 tries.  Sometimes it happens 5 times in a row.  It
appears that an "OLE Error 0x80041002" is an "object not found error".
So the query is running and line 86 in util.py is trying to get the next
result from the query and is bombing out?  For some reason it things
there are more results then there actually are?  This code is a direct
port from working Perl code.  Anyone have any ideas?


I've managed to produce this error by having the script running
continuously and then inserting a USB stick -- watch the serials
dictionary grow -- and then "ejecting" it, at which point, the
WMI query obviously gets caught out between what it thinks is
there and what is there when it comes to query. It's essentially
a race-condition, I suppose.

Given that this can happen, I can only suggest you catch the
exception, look for the specific 80041002 error code and
ignore it / log it. This is assuming that the circumstances
in which you're running it make it likely that the insertion
or removal of another physical disk is a plausible cause.

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


Re: [python-win32] Calling random Windows function?

2009-10-23 Thread Tim Golden

Aahz wrote:

I'm just getting into Windows programming for the first time, and I need
to list all open files.  Windows has a convenient function for that
(NtQuerySystemInformation), but I can't figure out how I am supposed to
call it.  I bought of copy of the Win32 book and I can't find anything
about accessing random API calls;
ctypes.windll.kernel32.NtQuerySystemInformation gives an AttributeError.

Where should I be looking to figure this out?


To answer your question slightly obliquely, can I offer you:

http://winsys.googlecode.com/svn/trunk/random/file_handles.py

which is, I think, coming close to what you want and will at
least illustrate the way of doing it. AFAICT you don't need
a Google sign-in or Javascript to access that code, but if 
you have any problems -- philosophical or technical -- let me

know and I can email you a copy directly.

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


Re: [python-win32] Calling random Windows function?

2009-10-23 Thread Tim Golden

Aahz wrote:

On Fri, Oct 23, 2009, Tim Golden wrote:

Aahz wrote:

I'm just getting into Windows programming for the first time, and I need
to list all open files.  Windows has a convenient function for that
(NtQuerySystemInformation), but I can't figure out how I am supposed to
call it.  I bought of copy of the Win32 book and I can't find anything
about accessing random API calls;
ctypes.windll.kernel32.NtQuerySystemInformation gives an AttributeError.

Where should I be looking to figure this out?

To answer your question slightly obliquely, can I offer you:

http://winsys.googlecode.com/svn/trunk/random/file_handles.py


Wow!  Thanks!  Now that I know more what to look for, I did some
searching and found this post that had no response:

http://mail.python.org/pipermail/python-win32/2009-June/009268.html

Assuming that I only care about monitoring open files within a single
tree, should I be concerned that your code might not return all open
files?


Have to confess that I don't usually work at this level, and as others
have pointed out, this is undocumented stuff... The de facto authority
is sysinternals, but none of that is Open Source so I don't really
know why their handle.exe picks up more files than my code. :(
I was sort of hoping that someone like Tim Roberts -- who works
with device drivers -- would have a hint.

Obviously, the answer would depend on the parameters of what you're
trying to do and how much margin of error you have. One definite
gotcha I wasn't totally able to work around -- although the code in
can_access is trying -- is the issue that attempting to query for
a pipe handle can hang the thread altogether. I believe that the
poster in the thread you refer to above didn't have any such problem
(we had a private correspondence which led up to that post).


If you believe that your C++ code is definitely working and you're
free to post it up, I for one am happy to help you translate it.
Maybe that's an option...

TJG

PS Welcome to the world of Python on Windows!
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] using WMI to get processor flags...

2009-10-24 Thread Tim Golden

Now I've got another question that I hope someone can provide the
answer I want, not the one I'm afraid is coming ;-)



What I haven't been able to find is a way to get a listing of
processor flags (like FPU, MMX, SVN, VMX, SSE3, HTT, etc).  Is there a
way to do this without resorting to pycpuid??  


Not as far as I can see.

Pycpuid can give me

this stuff but it requires some compiling for systems, and I'm still
not positive that it will work across platforms (AMD v. Intel).

Any thoughts?  I haven't found an answer yet.  I've also looked at
CIM_Processor, but it seems to me that the CIM classes are identical
to the Win32 classes, at least in most cases.  


The CIM_ classes represent the DMTF Common Information Model [1],
the structure on which WMI is based. In principle other manufacturers
could implement WMI -- or whatever they would want to call it -- but
as far as I am aware, no-one has.

I'm a little surprised that Microsoft -- who provide sample code [2] for
performing a CPUID check/call -- haven't used that code to provide
such information to WMI, but it doesn't look as though they have.

TJG

[1] http://www.dmtf.org/standards/cim/
[2] http://msdn.microsoft.com/en-us/library/xs6aek1h%28VS.80%29.aspx

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


Re: [python-win32] using WMI to get processor flags...

2009-10-28 Thread Tim Golden

Kevin Horn wrote:

On Sat, Oct 24, 2009 at 4:14 AM, Tim Golden  wrote:



The CIM_ classes represent the DMTF Common Information Model [1],
the structure on which WMI is based. In principle other manufacturers
could implement WMI -- or whatever they would want to call it -- but
as far as I am aware, no-one has.




Somewhat tangential to the conversation, but WBEM/CIM is available for
Linux, Mac OS X, some Unices, and Netware:

http://www.openwbem.org/

In case anyone is interested.


Interesting: is it widely used / known / supported, do you know?

[Absolutely no axe to grind: just interested as I've never seen
it put forward when anyone asks "How do I ...?" on one of those
platforms]

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


Re: [python-win32] Options for running Python under IIS?

2009-11-12 Thread Tim Golden

Preston Landers wrote:

On Thu, Nov 12, 2009 at 6:32 AM, Mark Hammond  wrote:

On 12/11/2009 10:03 AM, Preston Landers wrote:

4) Use isapi-wsgi:  This seems to be getting more popular but it seems
to use threads and I'm wondering whether this will break my app in
subtle ways.

Thread support should be optional - it is if you use the lower-level isapi 
stuff included in pywin32 (which isapi-wsgi uses)


Are there any other good options that I am missing?

It appears you have 4 - how many more exactly are you after?



Sorry, just a v. hurried note to say that I use isapi-wsgi
(in front of Cherrypy, in fact) but that I have had thread-y
issues which I haven't managed to nail. So caveat empleator!

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


  1   2   3   4   5   6   7   >