Re: [python-win32] Setting UserInitials in Office

2010-04-27 Thread Tim Golden

On 26/04/2010 23:56, Tim Roberts wrote:

Mike Driscoll wrote:


I am looking for a way to set the UserInitials and Username in
Microsoft Office applications. The reason is that we have had some
users who have managed to put their initials into some Office programs
when a different user was logged in and this has made it difficult to
tell who has what open. From what I've read so far, the information is
encoded in the Registry here:

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo

I tried to use the base64 module to decode it, but I must be doing
something wrong. Does anyone know of a good way to get and set this
information? I am dealing with users on Windows XP and Python 2.4


???  The strings in there are not encoded in any way.  They are
plaintext Unicode strings.  They happen to be identified as REG_BINARY,
but that's just a silly accident.



On my (WinXP SP3, Office 2003) machine, they look to be utf16-encoded
strings (null-terminated):

code
import _winreg

k = _winreg.OpenKey (
  _winreg.HKEY_CURRENT_USER,
  rSoftware\Microsoft\Office\11.0\Common\UserInfo
)
username, _ = _winreg.QueryValueEx (k, UserName)
print repr (username)
# 'g\x00o\x00l\x00d\x00e\x00n\x00t\x00\x00\x00'
print repr (username.decode (utf16))
# u'goldent\x00'

/code

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


Re: [python-win32] Using win32com.mapi to automate mail dispatch...

2010-04-27 Thread Varun Avashia
Understood, since I did not need very sophisticated code to do the bidding... 
(Just something little to keep exchange busy), I've started using following 
snippet which seems to be working great. Posting here for reference. Thank you 
all for your time...

from win32com.client import Dispatch
import random
s=Dispatch(Mapi.Session)
random.seed('')
MessageBody = ''
for i in range (1, 1): MessageBody += str(random.randint(0, 9))

for i in range(1,10): ##I'm gonna make this an infinite while loop 
eventually
  s.Logon(Outlook)
  newMsg = s.Outbox.Messages.Add(Test mail from Pythonwin32, MessageBody)
  recip1 = newMsg.Recipients.Add(mapi1, SMTP:ma...@mapi.aryaka.india)
  newMsg.Send()
  s.DeliverNow()
  s.Logoff()


P.S. I'm still interested in making the other snippet work. Is there any known 
issues with my configs?

 - Exchange 2k3 on win2k3 R2 server
 - CDO ver1.2.1
 - Pyton 2.6.4
 - pywin32 latest version
 - WinXPSP2 with Office2k7

-Original Message-
From: Mark Hammond [mailto:skippy.hamm...@gmail.com] 
Sent: Tuesday, April 27, 2010 11:05 AM
To: Varun Avashia
Cc: Python-Win32 List
Subject: Re: [python-win32] Using win32com.mapi to automate mail dispatch...

That EID was almost certainly fetched as a property, but the code isn't 
checking the returned property type before assuming it is a string 
entryid - in your case the type will be PT_ERROR, indicating the value 
holds the error reason as an integer.  As Tim mentioned, that code means 
the requested item wasn't found.

HTH,

Mark

On 27/04/2010 2:05 PM, Varun Avashia wrote:
 Yes Tim, the user has Admin privileges, and eid has a -ve value of 
 -2147221233.

 -Original Message-
 From: python-win32-bounces+varun.avashia=aryaka@python.org 
 [mailto:python-win32-bounces+varun.avashia=aryaka@python.org] On Behalf 
 Of Tim Roberts
 Sent: Tuesday, April 27, 2010 4:22 AM
 To: Python-Win32 List
 Subject: Re: [python-win32] Using win32com.mapi to automate mail dispatch...

 Varun Avashia wrote:



 I tried to follow the code on this link
 http://mail.python.org/pipermail/python-win32/2004-August/002239.html



 This worked fine for me on win7 with Outlook2k7 (CDO were installed
 separately), However this failed to work on winxp with sp2 and
 outlook2k7 (with CDO installed) with following trace-back….



 Traceback (most recent call last):

File C:\Documents and
 Settings\Administrator\Desktop\send1kMail.py, line 73,

   inmodule

  SendEMAPIMail(SendSubject, SendMessage, SendTo,
 MAPIProfile=MAPIProfile)

File C:\Documents and
 Settings\Administrator\Desktop\send1kMail.py, line 28,

   in SendEMAPIMail

  outboxfolder = msgstore.OpenEntry(eid,None,mapi.MAPI_BEST_ACCESS)

 TypeError: EntryID must be a string or None



 Am I missing any additional components for WinXP?



 The eid variable at line 27 has a value of -2147221233…


 For what it's worth, that's 0x8004010F, which is MAPI_E_NOT_FOUND.

 You might want to print out the eid that you fetched in the line
 immediately preceding.  Perhaps something went wrong with fetching the
 outbox ID.  Has Outlook 2007 actually been configured for Administrator
 on this machine?


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


Re: [python-win32] get installed software remote machine

2010-04-27 Thread pacopyc

Ok, thank you very much. Very good with set administrator password (it works), but I've 
problem with installed software. The list is not complete (I don't understand). For 
example key Adobe Flash Player ActiveX return this error:

Traceback (most recent call last):
 File pyshell#49, line 1, in module
   key = OpenKey(HKEY_LOCAL_MACHINE,
'Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player 
ActiveX', 0, KEY_ALL_ACCESS)
WindowsError: [Error 2] Impossibile trovare il file specificato (Impossible 
find file)

But key Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player 
ActiveX exists.
What's the problem? The spaces? I don't think so.

This is the code:

import wmi
from _winreg import (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, 
QueryValueEx)

host=''
reg = wmi.WMI(host,namespace=root/default).StdRegProv
result, names = reg.EnumKey 
(hDefKey=HKEY_LOCAL_MACHINE,sSubKeyName=rSoftware\Microsoft\Windows\CurrentVersion\Uninstall)
keyPath = rSoftware\Microsoft\Windows\CurrentVersion\Uninstall
count = 0
while count = len(names):
   try:
   print names[count]
   path = keyPath + \\ + names[count]
   key = OpenKey(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS)
   temp = QueryValueEx(key, 'DisplayName')
   display = str(temp[0])
   print names[count]+ - +display
   count += 1
   except:
   count += 1
   continue

More examples are these:

Software\Microsoft\Windows\CurrentVersion\Uninstall\KB951748Aggiornamento 
della protezione per Windows XP (KB951748) -- THIS IS OK
Software\Microsoft\Windows\CurrentVersion\Uninstall\KB951978   
  -- NOT OK, but DisplayName = 
Aggiornamento per Windows XP (KB951978)
Software\Microsoft\Windows\CurrentVersion\Uninstall\KB952004Aggiornamento 
della protezione per Windows XP (KB952004) -- THIS IS OK
Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip  
  -- NOT OK, but DisplayName = 7-Zip 4.65
Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player ActiveX 
  -- NOT OK, but DisplayName = Adobe Flash 
Player 10 ActiveX
Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Shockwave Player 
  -- NOT OK, but DisplayName = Adobe 
Shockwave Player 11.5
Software\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft .NET Framework 3.5 
SP1Microsoft .NET Framework 3.5 SP1 -- THIS IS OK


Thanks again

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


Re: [python-win32] get installed software remote machine

2010-04-27 Thread Tim Golden

On 27/04/2010 09:36, pacopyc wrote:

I've problem with installed software. The list is not complete (I don't 
understand).
For example key Adobe Flash Player ActiveX return this error:

Traceback (most recent call last):
   File pyshell#49, line 1, inmodule
 key = OpenKey(HKEY_LOCAL_MACHINE,
'Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player 
ActiveX', 0, KEY_ALL_ACCESS)
WindowsError: [Error 2] Impossibile trovare il file specificato (Impossible 
find file)


Ignoring other complications... you're querying the keys on the
remote machine . But you're then using _winreg to query
the values on the local machine. Why not continue to use the
WMI registry methods:

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

to query the remote keys?

By the way, the pythonic thing to do is to iterate over lists
directly. You don't need to do the while i  len (list) dance.
Just:

for name in names:
  try:
# do stuff with OpenKey (... + name)
  except some Exception class:
# handle and move on

Also, don't put a bare except: unless you're absolutely sure
you'll need it. In the code below, that except: would silently
ignore even a NameError or a Ctrl-C.

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


Re: [python-win32] Using win32com.mapi to automate mail dispatch...

2010-04-27 Thread Tim Roberts
Varun Avashia wrote:
 Yes Tim, the user has Admin privileges,

And has this user already configured Outlook so that all of his
mailboxes really exist?

 and eid has a -ve value of -2147221233.
   

Duh, you did say that in the original message, didn't you...

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

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


Re: [python-win32] get installed software remote machine

2010-04-27 Thread Tim Roberts
pacopyc wrote:
 Ok, thank you very much. Very good with set administrator password (it
 works), but I've problem with installed software. The list is not
 complete (I don't understand). For example key Adobe Flash Player
 ActiveX return this error:

 Traceback (most recent call last):
  File pyshell#49, line 1, in module
key = OpenKey(HKEY_LOCAL_MACHINE,
 'Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash
 Player ActiveX', 0, KEY_ALL_ACCESS)
 WindowsError: [Error 2] Impossibile trovare il file specificato
 (Impossible find file)

 But key Software\Microsoft\Windows\CurrentVersion\Uninstall\Adobe
 Flash Player ActiveX exists.
 What's the problem? The spaces? I don't think so.

Well, in that SPECIFIC line, you aren't escaping the backslashes.  You
either need to use the r prefix on that string, or double all the
backslashes.

Why are you using import wmi for this, if you're just doing straight
registry parsing?

You're asking for KEY_ALL_ACCESS, which is read and write permission. 
If you only need read access, perhaps you should just ask for read
permission.

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

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


Re: [python-win32] Setting UserInitials in Office

2010-04-27 Thread Tim Roberts
Tim Golden wrote:
 On 26/04/2010 23:56, Tim Roberts wrote:
 Mike Driscoll wrote:
 ...
 HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo

 I tried to use the base64 module to decode it, but I must be doing
 something wrong. Does anyone know of a good way to get and set this
 information? I am dealing with users on Windows XP and Python 2.4

 ???  The strings in there are not encoded in any way.  They are
 plaintext Unicode strings.  They happen to be identified as REG_BINARY,
 but that's just a silly accident.

 On my (WinXP SP3, Office 2003) machine, they look to be utf16-encoded
 strings (null-terminated):

Exactly.  They are really just REG_SZ, although they set the type as
REG_BINARY for their own inscrutable reasons.

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

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