Resources for IT Professionals >
Forums Home
>
Archived Forums Forums
>
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?
Answers
- 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- Marked As Answer byChris MullaneyMSFT, ModeratorWednesday, February 18, 2009 5:49 PM
- Proposed As Answer byBill Wesse MSFTModeratorWednesday, February 11, 2009 9:00 PM
All Replies
- 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- Proposed As Answer byBill Wesse MSFTModeratorTuesday, November 25, 2008 2:22 PM
- 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- Marked As Answer byChris MullaneyMSFT, ModeratorWednesday, February 18, 2009 5:49 PM
- Proposed As Answer byBill Wesse MSFTModeratorWednesday, February 11, 2009 9:00 PM

