Python: Executing a Program on a Remote 64-bit Windows Machine

Executing a program, exe’s, services on a remote Windows machine can be accomplished very easily, with a very few lines of code in Python. The task is similar to Psexec. However, in Python, one of the ways is using Windows Management Instrumentation (WMI).

From Tim Golden’s Python Stuff:

Windows Management Instrumentation (WMI) is Microsoft’s implementation of Web-Based Enterprise Management (WBEM), an industry initiative to provide a Common Information Model (CIM) for pretty much any information about a computer system.

Executing remote program using WMI needs the win32 extensions from Mark Hammond. Below are one of the sample code that I’ve used on a 32-bit target machine:

c = wmi.WMI ('my_remote_windows_machine')
process_id, result = c.Win32_Process.Create (CommandLine="Notepad.exe")
    for process in c.Win32_Process (ProcessId=process_id):
        returnvalue = str(process.ProcessId) + " " + str(process.Name)

    if result == 0:
        returnvalue = "Process started successfully: %s" % returnvalue
    else:
        raise RuntimeError, "Problem creating process: %s" % str(result)
    print returnvalue

 

However, when it comes to 64-bit target machines, I’m getting errors below:

  File "C:\Python26\lib\wmi.py", line 1181, in connect
    return _wmi_namespace (obj, find_classes)
  File "C:\Python26\lib\wmi.py", line 821, in __init__
    self.classes.update (self.subclasses_of ())
  File "C:\Python26\lib\wmi.py", line 843, in subclasses_of
    for c in self._namespace.SubclassesOf (root):
  File "C:\Python26\Lib\site-packages\win32com\client\util.py", line 84, in next

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

 

The solution:

c = wmi.WMI ('my_remote_windows_machine', find_classes=False)
process_id, result = c.Win32_Process.Create (CommandLine="Notepad.exe")
    for process in c.Win32_Process (ProcessId=process_id):
        returnvalue = str(process.ProcessId) + " " + str(process.Name)

    if result == 0:
        returnvalue = "Process started successfully: %s" % returnvalue
    else:
        raise RuntimeError, "Problem creating process: %s" % str(result)
    print returnvalue

Notice the extra parameter find_classes=False when instantiating the WMI object.
Some of the good examples on WMI in Python:
Tim Golden’s Python Stuff
WMI Cookbook

WordPress 2.7 “Coltrane” Available Now

Following my previous post, WordPress 2.7 Coming Tomorrow, which meant to WordPress.com users, the self-hosted version is available NOW. WordPress 2.7 “Coltrane”, is available on WordPress.org site. When you logged in to your WordPress control panel, you will be prompt with a “WordPress 2.7 is available!” notification.

Wordpress 2.7
Wordpress 2.7

Enjoy your new WordPress release ! 🙂

Answering “So … what do you do?”

For most types of work, only two levels of description are ever needed. Accountants, for example, would describe themselves as accountants to laypeople, and “tax” or “GL” or “fixed assets” to other accountants.

For my line of work, however, I find it interesting that I need to give lots of different answers to different kinds of people:

  1. How do you explain “software developer” to someone who doesn’t even know what software is? Therefore, my dear grandmother thinks I’m selling computers …
  2. To normal laypeople, I just say I’m in IT.
  3. To people in SEO, I say I’m an SEO reseller.
  4. To people who are more IT savvy, I say that I’m in software.
  5. To people in software, I say that I develop web applications using .NET and C#.
  6. To people who are working in software development companies, I say that I’m doing both sustaining (defects) and product development.

WordPress 2.7 coming tomorrow

According to DownloadSquad and WordPress.com, WordPress 2.7 is coming out tomorrow.

As promised, here is the advance notice that WordPress 2.7 is coming to WordPress.com, and will go live on Thursday, December 4, 2008 at 8pm Eastern Time.

That’s 9 a.m. in Kuala Lumpur!

WordPress 2.7 represents a huge shift away from earlier versions of WordPress – at least in the administration area. Most of the changes will be visible to bloggers, but not blog readers. But the changes in the admin area are huge. First, the navigation menus have all been moved to the left side of the screen, giving you more room at the top of the page. The submenus are all also collapsible, which allows you to navigate the administration interface without reloading the page as often.

A screenshot from RC1:

Wordpress 2.7
Wordpress 2.7

I just can’t wait to load it when it comes out.