Unfortunately, that does not work. SetIfEntry seems to
does something to the network INTERFACE, not the
CONNECTION on it. What I would like to see is the effect
of manually disabling the CONNECTION (like right-clicking
on e.g. "Local Area Connection" in "Network Connections")
and then selecting "Disable".
I used SetInEntry to set the dwAdminStatus to 2 for
disable, and although this disables the network
interface, Windows does not seem to notice this. That is,
the "connected" icon stays in my taks bar. Setting
dwOperStatus does not seem to have any effect at all...
Does anyone know how to pull this off?
Regards,
Joost
#include <netcon.h>
// wszName is the name of the connection as appears in Network Connections
folder
// set bEnable to true to enable and to false to disable
bool EnableConnection(LPCWSTR wszName, bool bEnable)
{
bool result = false;
typedef void (__stdcall * LPNcFreeNetconProperties) (NETCON_PROPERTIES*
pProps);
HMODULE hmod = LoadLibrary("netshell.dll");
if (!hmod)
return false;
LPNcFreeNetconProperties NcFreeNetconProperties =
(LPNcFreeNetconProperties)GetProcAddress(hmod, "NcFreeNetconProperties");
if (!NcFreeNetconProperties )
return false;
CoInitialize(0);
INetConnectionManager * pMan = 0;
HRESULT hres = CoCreateInstance(CLSID_ConnectionManager, 0,
CLSCTX_ALL, __uuidof(INetConnectionManager), (void**)&pMan);
if (SUCCEEDED(hres))
{
IEnumNetConnection * pEnum = 0;
HRESULT hres = pMan->EnumConnections(NCME_DEFAULT, &pEnum);
if (SUCCEEDED(hres))
{
INetConnection * pCon = 0;
ULONG count;
bool done = false;
while (pEnum->Next(1, &pCon, &count) == S_OK && !done)
{
NETCON_PROPERTIES * pProps = 0;
hres = pCon->GetProperties(&pProps);
if (SUCCEEDED(hres))
{
if (wcscmp(pProps->pszwName,wszName) == 0)
{
if (bEnable)
result = (pCon->Connect() == S_OK);
else
result = (pCon->Disconnect() == S_OK);
done = true;
}
NcFreeNetconProperties(pProps);
}
pCon->Release();
}
pEnum->Release();
}
pMan->Release();
}
CoUninitialize();
FreeLibrary(hmod);
return result;
}
int main()
{
EnableConnection(L"Local Area Connection", false);
}
"Joost van Schaik" <jjc.van...@12move.nl> wrote in message
news:05b801c2d2bf$4b5c93a0$3001...@phx.gbl...
Uhm - you don't happen to have a may to enable/disable
connections by means of command line keyins ... :-)
CU
Joost
>-----Original Message-----
>Well I know how to do it in C or C++ but you (..) Here is
a very quick and
>dirty code.
(code snipped)
Eugene
"joost van schaik" <jjc.van...@12move.nl> wrote in message
news:04d701c2d33a$f2887bf0$a601...@phx.gbl...
INetConnectionManager * pMan = 0;
HRESULT hres = CoCreateInstance(CLSID_ConnectionManager,
0,
CLSCTX_ALL, __uuidof(INetConnectionManager), (void**)
&pMan);
if (SUCCEEDED(hres))
What in blazes does it do? It reminds of an Activator
construction in C#, creating an instance of a class by
name rather than by type. Am I correct
Eugene
"Joost van schaik" <jjc.van...@12move.nl> wrote in message
news:018b01c2d392$0251b3b0$a301...@phx.gbl...
Hi, i found in Platform SDK July 2002 the file netcon.idl, i modified it
and i put into it the lines:
[
uuid(5C63C1AD-3956-4FF8-8486-AAAAAAAAAAAA),
helpstring("NetConnectionManager Class")
]
coclass NetConnectionManager
{
[default] interface INetConnectionManager;
};
i put a random uid, i don't know if this is the error.
Now i've the type library but when i try to execute the lines (visual
basic):
Dim a As New NETCONLib.NetConnectionManager
Dim pp As NETCONLib.IEnumNetConnection
a.EnumConnections NCME_DEFAULT, pp
they return me the error :
Run-time error '429':
ActiveX component can't create object
but, may i use the netshell.dll in this way with Windows 2000 pro?
must i put a correct uid? if yes, where can i find it?
Thank you very much for your help.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"D.I." <X@X.x> wrote in message news:b3vbmk$oma$1...@news.flashnet.it...
Thank you very very very very very much, now i can disable and enable a lan
connection from visual basic, but i've still a little problem, i can't use
INetConnection.GetProperties, the visual basic compiler tell me that could
be a restriction to use it or could be a parameter not supported by visual
basic. In fact i had to modify the struct tagNETCON_PROPERTIES in the IDL.
These are my structs :
typedef struct tagGUID {
LONG Data1;
LONG Data2;
LONG Data3;
BYTE Data4[8];
} GUID;
typedef struct tagNETCON_PROPERTIES
{
GUID guidId;
[string] BSTR pszwName;
[string] BSTR pszwDeviceName;
NETCON_STATUS Status;
NETCON_MEDIATYPE MediaType;
LONG dwCharacter;
GUID clsidThisObject;
GUID clsidUiObject;
} NETCON_PROPERTIES;
and the method is defined in this way :
HRESULT GetProperties(
[out] NETCON_PROPERTIES** ppProps);
How can i resolve the problem?
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"D.I." <X@X.x> wrote in message news:b41o6m$e42$1...@news.flashnet.it...
thanks.
--
Yong Qu
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
"D.I." <X@X.x> wrote in message news:b41o6m$e42$1...@news.flashnet.it...
Eugene
"D.I." <X@X.x> wrote in message news:b41o6m$e42$1...@news.flashnet.it...