{"record":{"id":"5c44efb778f4b177","repo":"go-delve/delve","slug":"could-not-acquire-debug-privilege-adjusttokenpriv","errorCode":null,"errorMessage":"could not acquire debug privilege (AdjustTokenPrivileges): %v","messagePattern":"could not acquire debug privilege \\(AdjustTokenPrivileges\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/proc_windows.go","lineNumber":217,"sourceCode":"\t\treturn fmt.Errorf(\"could not acquire debug privilege (OpenCurrentProcessToken): %v\", err)\n\t}\n\tdefer token.Close()\n\n\tprivName, _ := sys.UTF16FromString(\"SeDebugPrivilege\")\n\tvar luid sys.LUID\n\terr = sys.LookupPrivilegeValue(nil, &privName[0], &luid)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not acquire debug privilege  (LookupPrivilegeValue): %v\", err)\n\t}\n\n\tvar tp sys.Tokenprivileges\n\ttp.PrivilegeCount = 1\n\ttp.Privileges[0].Luid = luid\n\ttp.Privileges[0].Attributes = sys.SE_PRIVILEGE_ENABLED\n\n\terr = sys.AdjustTokenPrivileges(token, false, &tp, 0, nil, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not acquire debug privilege (AdjustTokenPrivileges): %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc waitForSearchProcess(pfx string, seen map[int]struct{}) (int, error) {\n\tlog := logflags.DebuggerLogger()\n\thandle, err := sys.CreateToolhelp32Snapshot(sys.TH32CS_SNAPPROCESS, 0)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"could not get process list: %v\", err)\n\t}\n\tdefer sys.CloseHandle(handle)\n\n\tvar entry sys.ProcessEntry32\n\tentry.Size = uint32(unsafe.Sizeof(entry))\n\terr = sys.Process32First(handle, &entry)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"could not get process list: %v\", err)","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_windows.go#L199-L235","documentation":"Final step of acquireDebugPrivilege: Delve calls AdjustTokenPrivileges to turn on SeDebugPrivilege for its token. If that Win32 call fails (returns 0), this error wraps the reason. Note: AdjustTokenPrivileges can also succeed while not actually granting the privilege (GetLastError() == ERROR_NOT_ALL_ASSIGNED); this error only fires when the call itself fails.","triggerScenarios":"Attach on Windows where AdjustTokenPrivileges returns failure — invalid token handle, invalid privilege LUID, or token was closed/changed between calls.","commonSituations":"Attaching from a non-elevated shell where the privilege is present in the list but not enabled and the call fails; token invalidated by session changes; UAC-restricted tokens in odd launch contexts.","solutions":["Relaunch Delve elevated (Right-click -> Run as administrator) — most common fix.","Confirm the privilege is actually assigned: `whoami /priv` shows SeDebugPrivilege only when enabled.","If Delve still cannot enable it, attach to the process as the same user that owns it, avoiding the need for SeDebugPrivilege.","Check EDR/AV software that may block debugger token manipulation."],"exampleFix":"// before\nc:> dlv attach 4242\n// could not acquire debug privilege (AdjustTokenPrivileges): ...\n// after\nc:> # start an elevated shell first\nstart-process powershell -verb runas\nc(dlv attach 4242)","handlingStrategy":"validation","validationCode":"// powershell: confirm SeDebugPrivilege is enabled for the current token\nwhoami /priv | Select-String \"SeDebugPrivilege\\s+Enabled\"","typeGuard":null,"tryCatchPattern":"if err := dbg.Attach(pid, nil); err != nil {\n    if strings.Contains(err.Error(), \"AdjustTokenPrivileges\") {\n        // relaunch elevated, or attach as the process owner\n    }\n}","preventionTips":["Run the debugger elevated (Run as administrator).","Attach to processes owned by the same user when elevation is not possible.","Check EDR/AV that may block token privilege changes."],"tags":["windows","privileges","token","uac","attach"],"backgroundTag":"debug-privilege-not-enabled","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}