Windows 10自定义SNMP扩展代理安装配置故障排查求助
Let’s walk through the most likely causes and fixes for your SNMP extension agent being ignored—since you’ve already ruled out 32-bit DLL mismatches, we’ll focus on the gotchas specific to modern 64-bit Windows systems:
1. Verify Unmangled Exported Functions
C++ name mangling is a common culprit here. Even if you implemented SnmpExtensionInit and SnmpExtensionQuery, the compiler might have altered their names (e.g., adding _SnmpExtensionInit@12 or similar for __stdcall).
- Use the
dumpbintool (included with Visual Studio) to check your DLL’s export table:dumpbin /exports "C:\Program Files\testing\MyAgent.dll" - Look for exact matches of
SnmpExtensionInitandSnmpExtensionQuery(no extra characters or underscores). If they’re missing, wrap your function declarations inextern "C"to disable name mangling:extern "C" { BOOL WINAPI SnmpExtensionInit(DWORD dwTimeZeroReference, DWORD dwReserved, AsnObjectIdentifier *pFirstSupportedRegion); BOOL WINAPI SnmpExtensionQuery(BYTE bRequestType, SnmpVarBindList *pVarBindList, AsnInteger *pErrorStatus, AsnInteger *pErrorIndex); }
2. Check for Missing Dependencies
Your DLL might be failing to load because it depends on other libraries (like 64-bit Visual C++ Runtime) that aren’t present on the target system.
- Use Dependency Walker (or
dumpbin /dependents) to scan your DLL:dumpbin /dependents "C:\Program Files\testing\MyAgent.dll" - Ensure all listed dependencies exist in the system
PATHor the same directory as your DLL. Install the matching 64-bit Visual C++ Redistributable package if needed.
3. Fix Registry and File Permissions
The SNMP service runs under the Local Service account, which needs read access to both your registry keys and DLL file:
- Registry Permissions:
- Open Regedit, navigate to
HKEY_LOCAL_MACHINE\SOFTWARE\MyAgent\CurrentVersionandHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ExtensionAgents. - Right-click each key → Permissions → Add
Local Service→ Grant it Read permissions.
- Open Regedit, navigate to
- File/Directory Permissions:
- Right-click
C:\Program Files\testing\→ Properties → Security tab → AddLocal Service→ Grant Read & execute permissions for the folder and DLL.
- Right-click
4. Validate Registry Path Configuration
Double-check your registry entries to avoid subtle typos or expansion issues:
- Confirm the
Pathnamevalue inHKEY_LOCAL_MACHINE\SOFTWARE\MyAgent\CurrentVersionis set asREG_EXPAND_SZ(you mentioned this, but ensure there are no typos in the path, like extra spaces or misspelled folder names). - If you used environment variables (e.g.,
%PROGRAMFILES%), test expanding them manually to ensure they resolve to the correct 64-bit path (modern Windows expands%PROGRAMFILES%toC:\Program Filesfor 64-bit processes).
5. Enable Verbose SNMP Logging
Enable debug logging to get more specific error details from the SNMP service:
- Open Regedit and navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters. - Create a new DWORD (32-bit) Value named
DebugLeveland set its value to0x00000003(enables error and warning logs). - Restart the SNMP service.
- Check the System Event Log again—you’ll likely get a more detailed error code (e.g.,
ERROR_PROC_NOT_FOUNDif functions are missing, orERROR_ACCESS_DENIEDfor permissions issues).
6. Test DLL Loading Manually
Write a simple 64-bit test program to verify your DLL loads correctly and exposes the required functions outside of the SNMP service context:
#include <windows.h> #include <stdio.h> #include <snmp.h> // Define function pointers matching SNMP API signatures typedef BOOL (WINAPI *SnmpExtensionInitFunc)(DWORD, DWORD, AsnObjectIdentifier*); typedef BOOL (WINAPI *SnmpExtensionQueryFunc)(BYTE, SnmpVarBindList*, AsnInteger*, AsnInteger*); int main() { HMODULE hDll = LoadLibrary(L"C:\\Program Files\\testing\\MyAgent.dll"); if (!hDll) { printf("LoadLibrary failed! Error code: %d\n", GetLastError()); return 1; } SnmpExtensionInitFunc initFunc = (SnmpExtensionInitFunc)GetProcAddress(hDll, "SnmpExtensionInit"); if (!initFunc) { printf("Failed to find SnmpExtensionInit! Error code: %d\n", GetLastError()); FreeLibrary(hDll); return 1; } SnmpExtensionQueryFunc queryFunc = (SnmpExtensionQueryFunc)GetProcAddress(hDll, "SnmpExtensionQuery"); if (!queryFunc) { printf("Failed to find SnmpExtensionQuery! Error code: %d\n", GetLastError()); FreeLibrary(hDll); return 1; } printf("Success! DLL loaded and functions found.\n"); FreeLibrary(hDll); return 0; }
Compile this as a 64-bit executable and run it. If it fails, the error code will point you directly to the problem (e.g., 126 for missing dependencies, 127 for missing functions).
内容的提问来源于stack exchange,提问作者Navjot Singh

