[python-win32] GetNetworkConnections fails since a Windows update
Steven Manross
steven at manross.net
Wed May 3 15:12:10 EDT 2023
That happens here too in Win10/Win11 using your code. It looks like Microsoft altered the COM object for you not to be able to do a GetNetwork or GetCategory on the connection object, but that seems odd since it basically renders the object pointless.
P.S. some powershell code doesn't seem to be able to access the GetNetwork function either.
$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$connections = $networkListManager.GetNetworkConnections()
$connections |foreach {
$_.GetNetwork()
}
Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))
At line:2 char:5
+ $_.GetNetwork()
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Steven
-----Original Message-----
From: python-win32 <python-win32-bounces+steven=manross.net at python.org> On Behalf Of cwalou at gmail.com
Sent: Wednesday, May 3, 2023 7:00 AM
To: python-win32 at python.org
Subject: [python-win32] GetNetworkConnections fails since a Windows update
Hello.
After a recent update on Windows 10, I not able to tell exactly which, I've a strange behavior on a program that works fine since 2015 on thousands of machines...
* With this code :
def networks_private():
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()
try:
log('switching network interface in private mode')
network.SetCategory(1)
except:
log("error switching network interface in private mode")
pos += 1
* I get this error :
Traceback (most recent call last):
[...]
File "Frame1.pyo", line 163, in _init_
File "fonctions.pyo", line 201, in networks_private File "win32com\client\dynamic.pyo", line 522, ingetattr_
AttributeError: Next.GetNetwork
Regards, thanks.
_______________________________________________
python-win32 mailing list
python-win32 at python.org
https://mail.python.org/mailman/listinfo/python-win32
More information about the python-win32
mailing list