[python-win32] Problem with OLE error 0x80041002
Gowtham
narisipalli at gmail.com
Fri Dec 11 05:49:58 CET 2009
I have also tried with win32security instead of using wmi as mentioned in
Tim Golden's post-
import _winreg
import win32security
username = 'gowtham'
sid =
win32security.ConvertSidToStringSid(win32security.LookupAccountName(None,
username)[0])
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + "\\" + sid)
value, type = _winreg.QueryValueEx(key, "ProfileImagePath")
print value
Output:
C:\Users\gowtham
This works as intended. Is this advisible method of extracting path or the
WMI way?
Thanks,
Gowtham N
On Thu, Dec 10, 2009 at 11:19 PM, Gowtham <narisipalli at gmail.com> wrote:
> Hi All,
>
> I have a python script that retrieves the user profile path from the
> registry using wmi. I am doing this way as win32net.NetUserGetInfo could not
> somehow find the domain user. Here the code snippet-
>
> def GetProfilePath(username):
> pythoncom.CoInitialize()
> try:
> reg = wmi.WMI(find_classes=False, namespace='default').StdRegProv
> try:
> unused_result, profilepath = reg.GetExpandedStringValue(
> hDefKey=_winreg.HKEY_LOCAL_MACHINE,
> sSubKeyName=('%s\\%s' % (ProfileSettings.PROFILES_KEY,
> ProfileSettings.ObtainSid(username))),
> sValueName='ProfileImagePath')
> except WindowsError:
> raise NoProfileInfoError(
> 'The user %s has no Profile Path defined in the registry.' %
> username)
> finally:
> pythoncom.CoUninitialize()
> return profilepath
>
> I am using pythoncom as this request would be able to run from a thread
> instead from the main thread.
>
> This works fine on most of the XP machines but some XP machines throw up
> this exception-
>
> File "wmi.pyc", line 1190, in connect
> File "wmi.pyc", line 189, in handle_com_error
> x_wmi: -0x7ffbeffe - OLE error 0x80041002
>
> I see that 0x80041002 is Object not found error but why is wmi not being
> able to find the object and what could be an alternative?
>
> Any tips, appreciated.
> Gowtham N
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20091210/2ee24bd3/attachment-0001.htm>
More information about the python-win32
mailing list