Nick Parker
My ramblings on .NET...

Windows Groups and Python

Monday, 18 October 2004 01:34 by nickp

So because of my recent interests with IronPython, I decided I should learn Python to better understand everything. Python really appears to be a nice language (from the weekend that I spent with it). It feels slightly strange not using curly braces to scope methods though. Anyway, I wanted to come up with a nice example of how Python works within Windows to help me better understand the language. I was watching Crossing Jordan tonight with Megan when I though of the script I threw together on Friday at work and how it would be a great sample to test Python. After I downloaded the Python Win32 extensions, I was off and running. After a little fiddling, this is what I came up with, which is very close to my original script:

 

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
strName = shell.ExpandEnvironmentStrings("%USERNAME%")
strDomain = shell.ExpandEnvironmentStrings("%USERDOMAIN%")
objUser = win32com.client.GetObject("WinNT://" + strDomain + "/" + strName)
strMsg = strName + " belongs to the following groups:\n\n"
for group in objUser.Groups():
strMsg += group.Name + "\n"
shell.Popup(strMsg)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   IronPython
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

August 28. 2008 17:00