Resources for IT Professionals >
포럼 홈
>
Technical Interoperability Scenarios (Archived)
>
Service Control Manager privileges
Service Control Manager privileges
- I am trying to open service control manager of a remote machine usingOpenSCManager(machinename,NULL,SC_MANAGER_ALL_ACCESS);But I am getting error 5 from GetLastError(); which means access is denied.What are the privileges that are needed for running the above code?
답변
- Sumedh - Please let me know if I have answered your questions satisfactorily; if so, I will consider your question resolved. Thanks for contacting us - it was my pleasure to help.
Regards,
Bill Wesse
Escalation Engineer- 답변으로 표시됨Chris MullaneyMSFT, 중재자2009년 2월 18일 수요일 오후 5:49
- 답변으로 제안됨Bill Wesse MSFT중재자2009년 2월 11일 수요일 오후 9:00
모든 응답
- Good morning Sumedh - the solution is to have the SE_DEBUG_NAME enabled on your process token. I have inserted a code sample below. On Windows Vista/2008, the process will need to be run with Admin privileges.
Please let me know if this meets your needs!
Regards,
Bill Wesse
MCSE, MCTS / Senior Escalation Engineer, US-CSS DSC PROTOCOL TEAM
#ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0600 // Windows Vista #endif #include <windows.h> #include <tchar.h> BOOL EnablePrivilege(LPTSTR Name) { HANDLE hProcess; HANDLE hToken; BOOL Result = FALSE; hProcess = ::GetCurrentProcess(); if (::OpenProcessToken(hProcess, TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) { TOKEN_PRIVILEGES tp; LUID Luid; if (LookupPrivilegeValue(NULL, Name, &Luid)) { tp.PrivilegeCount = 1; tp.Privileges[0].Luid = Luid; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL)) { Result = TRUE; } } ::CloseHandle(hToken); } ::CloseHandle(hProcess); return Result; } int _tmain(int argc, _TCHAR* argv[]) { return EnablePrivilege(SE_DEBUG_NAME) ? 0 : 1; }
Escalation Engineer- 답변으로 제안됨Bill Wesse MSFT중재자2008년 11월 25일 화요일 오후 2:22
- Hi Bill,I tried executing your codeafter a call to enableprivilege() from main function I try to call openSCmanager.LookupPrivilegeValue(remotemachineName, Name, &Luid)openScmanager(remotemachineName,NULL,SC_MANAGER_CONNECT); here I am getting getlasterror() 977.Also is this kind of opening sc manager on remote machine/local machine in debug mode? Could you explain more on this.regards,Sumedh
Sumedh - sorry I didn't catch your follow up question earlier - is the process running with Administrator privileges?
Regards,
Bill Wesse
Escalation Engineer- Sumedh - Please let me know if I have answered your questions satisfactorily; if so, I will consider your question resolved. Thanks for contacting us - it was my pleasure to help.
Regards,
Bill Wesse
Escalation Engineer- 답변으로 표시됨Chris MullaneyMSFT, 중재자2009년 2월 18일 수요일 오후 5:49
- 답변으로 제안됨Bill Wesse MSFT중재자2009년 2월 11일 수요일 오후 9:00

