Answered by:
Service Control Manager privileges

Question
-
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?Tuesday, November 25, 2008 10:44 AM
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- Proposed as answer by Bill Wesse MSFT Wednesday, February 11, 2009 9:00 PM
- Marked as answer by Chris Mullaney Wednesday, February 18, 2009 5:49 PM
Wednesday, 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 by Bill Wesse MSFT Tuesday, November 25, 2008 2:22 PM
Tuesday, 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,SumedhMonday, December 1, 2008 2:01 PM
-
Sumedh - sorry I didn't catch your follow up question earlier - is the process running with Administrator privileges?
Regards,
Bill Wesse
Escalation EngineerThursday, January 8, 2009 5:11 PM -
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- Proposed as answer by Bill Wesse MSFT Wednesday, February 11, 2009 9:00 PM
- Marked as answer by Chris Mullaney Wednesday, February 18, 2009 5:49 PM
Wednesday, February 11, 2009 9:00 PM