[Open]
[Close]
安裝vLan 後開機變慢
我是用ADSL 上網的。安裝vLan 後開機明顯變慢。查一查event viewer 後,發現這是因為IPvE adpater 在尋找DHCP server, 做成delay.
人手disable IPvE adpater後, 重新開機, 開機果然快了.
請問開發者可不可以在vLan 運作的時侯才enable IPvE adpater? 在結束vLan 時把IPvE adpater disable. 這樣就不會做成開機變慢了。
我現在寫了一個loader 來做以上的事。附上code 給大家參一參考。如開發者能夠把這項功能加到vLan 內就太好了。
以下是loader 的code.
#include "stdafx.h"
#include "vLanController.h"
#include <objbase.h>
#include <netcon.h>
#include <string.h>
HRESULT EnableVLanConnection(BOOL bEnable);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
EnableVLanConnection(true);
STARTUPINFO si;
PROCESS_INFORMATION pi;
LPVOID lpMsgBuf = NULL;
HHOOK hKH = NULL;
HANDLE hKHDll = NULL;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if(!CreateProcess(_T("C:\\Program Files\\vLan\\vLan.exe"), NULL, NULL, NULL, FALSE, 0, NULL, _T("C:\\Program Files\\vLan\\"), &si, &pi)) {
MessageBox(0, _T("Failed to CreateProcess"), _T("Failed to CreateProcess"), 16);
LocalFree(lpMsgBuf);
return 0;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
UnhookWindowsHookEx(hKH);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
EnableVLanConnection(false);
return 0;
}
HRESULT EnableVLanConnection(BOOL bEnable)
{
HRESULT hr = E_FAIL;
CoInitialize(NULL);
INetConnectionManager *pNetConnectionManager = NULL;
hr = CoCreateInstance(CLSID_ConnectionManager,
NULL,
CLSCTX_LOCAL_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
IID_INetConnectionManager,
reinterpret_cast<LPVOID *>(&pNetConnectionManager)
);
if (SUCCEEDED(hr))
{
/*
Get an enumurator for the set of connections on the system
*/
IEnumNetConnection* pEnumNetConnection;
pNetConnectionManager->EnumConnections(NCME_DEFAULT, &pEnumNetConnection);
ULONG ulCount = 0;
BOOL fFound = FALSE;
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
HRESULT hrT = S_OK;
/*
Enumurate through the list of adapters on the system and look for the one we want
NOTE: To include per-user RAS connections in the list, you need to set the COM
Proxy Blanket on all the interfaces. This is not needed for All-user RAS
connections or LAN connections.
*/
do
{
NETCON_PROPERTIES* pProps = NULL;
INetConnection * pConn;
/*
Find the next (or first connection)
*/
hrT = pEnumNetConnection->Next(1, &pConn, &ulCount);
if (SUCCEEDED(hrT) && 1 == ulCount)
{
/*
Get the connection properties
*/
hrT = pConn->GetProperties(&pProps);
if (S_OK == hrT)
{
//printf("* %S\n", pProps->pszwName);
//MessageBox(0, pProps->pszwName, pProps->pszwName, 0);
if (!wcscmp(pProps->pszwName, _T("IPvE Adapter")))
if (bEnable)
{
//printf(" Enabling adapter: %S...\n",pProps->pszwName);
hr = pConn->Connect();
}
else
{
//printf(" Disabling adapter: %S...\n",pProps->pszwName);
hr = pConn->Disconnect();
}
CoTaskMemFree (pProps->pszwName);
CoTaskMemFree (pProps->pszwDeviceName);
CoTaskMemFree (pProps);
}
pConn->Release();
pConn = NULL;
}
} while (SUCCEEDED(hrT) && 1 == ulCount && !fFound);
if (FAILED(hrT))
{
hr = hrT;
}
pEnumNetConnection->Release();
}
if (FAILED(hr) && hr != HRESULT_FROM_WIN32(ERROR_RETRY))
{
//printf("Could not enable or disable connection (0x%08x)\r\n", hr);
}
pNetConnectionManager->Release();
CoUninitialize();
return hr;
}