Windows 8 doesn't let you change the network type?

18 November 2012 (updated 04 March 2015)

In case you've been feeling adventurous like me and installed Windows 8 you probably also installed Hyper-V cause well, it's free and it has way better integration with Windows. Yes, you can make your VM start when Windows starts with VMware too - but Hyper-V remembers if you had it running before shutdown. And shutdown works unlike VMware which does poweroff in case you did not reinstall vmware-tools after kernel upgrade (at least with Ubuntu). Could I have gotten something wrong? Don't think so ... cause it works properly on Hyper-V.

Well anyway, the Network and Sharing Center in Windows 8 is quite weird ... could not change the network type (to private) for one virtual Hyper-V adapter even tho I've enabled all user control with gpedit.msc. To fix it I had to use the Network List Manager API's SetCategory it seems. There was this PowerShell script that seem to do that but, damn it, I don't want to edit the script every time I have the problem. And that PowerShell thing looks awful compared to Python ...

Here's a python script that does the right thing: asks the user what network should be made private.

import win32com.client
NETWORK_CATEGORIES = {
    1: "PRIVATE",
    0: "PUBLIC",
    2: "DOMAIN"
}
m = win32com.client.Dispatch("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}")
more = 1
pos = 1
connections = m.GetNetworkConnections()

while more:
    connection, more = connections.Next(pos)
    if connection:
        network = connection.GetNetwork()
        category = network.GetCategory()
        print '%s. "%s" is %s' % (pos, network.GetName(), NETWORK_CATEGORIES[category])
        if not category and raw_input("Make private [N]") in ['y', 'Y']:
            network.SetCategory(1)
    pos += 1

Now isn't this pretty? (except the shitty iterator-wanna-be api in GetNetworkConnections ...)

This entry was tagged as python windows