{"record":{"id":"792b5588932cebca","repo":"peass-ng/PEASS-ng","slug":"win32exception-792b55","errorCode":null,"errorMessage":"Win32Exception","messagePattern":"Win32Exception","errorType":"exception","errorClass":"Win32Exception","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskEditor/Native/NetServerEnum.cs","lineNumber":104,"sourceCode":"\n        public static IEnumerable<NetworkComputerInfo> GetNetworkComputerInfo(ServerTypes serverTypes = ServerTypes.Workstation | ServerTypes.Server, string domain = null) =>\n            NetServerEnum<NetworkComputerInfo>(serverTypes, domain, 101);\n\n        public static T[] NetServerEnum<T>(ServerTypes serverTypes = ServerTypes.Workstation | ServerTypes.Server, string domain = null, int level = 0) where T : struct\n        {\n            if (level == 0)\n                level = int.Parse(System.Text.RegularExpressions.Regex.Replace(typeof(T).Name, @\"[^\\d]\", \"\"));\n\n            IntPtr bufptr = IntPtr.Zero;\n            try\n            {\n                int entriesRead, totalEntries;\n                IntPtr resumeHandle = IntPtr.Zero;\n\n                int ret = Netapi32.NetServerEnum(null, level, out bufptr, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, serverTypes, domain, resumeHandle);\n                if (ret == 0)\n                    return InteropUtil.ToArray<T>(bufptr, entriesRead);\n                throw new System.ComponentModel.Win32Exception(ret);\n            }\n            finally\n            {\n                Netapi32.NetApiBufferFree(bufptr);\n            }\n        }\n\n        public static T NetServerGetInfo<T>(string serverName, int level = 0) where T : struct\n        {\n            if (level == 0)\n                level = int.Parse(System.Text.RegularExpressions.Regex.Replace(typeof(T).Name, @\"[^\\d]\", \"\"));\n\n            IntPtr ptr = IntPtr.Zero;\n            try\n            {\n                int ret = Netapi32.NetServerGetInfo(serverName, level, out ptr);\n                if (ret != 0)\n                {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskEditor/Native/NetServerEnum.cs#L86-L122","documentation":"NetServerEnum wraps the Netapi32 NetServerEnum call and throws Win32Exception(ret) for any nonzero return code at NetServerEnum.cs:104. Common codes are ERROR_ACCESS_DENIED (5), ERROR_NO_BROWSER_SERVERS_FOUND (6118), and ERROR_INVALID_LEVEL — meaning the server/network enumeration itself failed before any results were produced.","triggerScenarios":"Enumerating servers of a given type in a domain/workgroup where the browser service is unavailable, the caller lacks permission, the domain parameter is wrong, or the Server service / Computer Browser is disabled on the network.","commonSituations":"Discovering network servers in hardened environments where browsing is blocked by firewalls; Workstation/Server/Browser services stopped; enumerating in a workgroup with no master browser; group policy blocking enumeration.","solutions":["Check Win32Exception.NativeErrorCode: 6118 means no browser servers — ensure the Computer Browser/Server services and NetBIOS are available","Run with sufficient privileges and confirm access isn't blocked by policy","Fall back to directory-based discovery (AD lookup) when browser enumeration fails","Catch Win32Exception and return an empty/partial server list instead of failing"],"exampleFix":"// before\nvar servers = NetServerEnum.GetServerList(serverTypes, domain);\n// after\ntry { servers = NetServerEnum.GetServerList(serverTypes, domain); }\ncatch (Win32Exception ex) { Log($\"NetServerEnum failed {ex.NativeErrorCode}\"); servers = new ServerInfo[0]; }","handlingStrategy":"fallback","validationCode":"var sc = new System.ServiceProcess.ServiceController(\"LanmanServer\");\nif (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running) { Log(\"Server service not running\"); return; }","typeGuard":null,"tryCatchPattern":"try { servers = NetServerEnum.GetServerList(types, domain); } catch (Win32Exception ex) { Log($\"NetServerEnum {ex.NativeErrorCode}\"); servers = Enumerable.Empty<ServerInfo>(); }","preventionTips":["Ensure Server/Computer Browser services and NetBIOS are enabled in the target network","Check NativeErrorCode 6118 (no browser) vs 5 (access denied) for root cause","Use AD queries as a modern alternative to browser enumeration"],"tags":["win32exception","network-enumeration","netapi32","browser-service"],"backgroundTag":"win32-native-call-failed","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}