Ressourcen für IT-Professionals >
Forenhomepage
>
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?
Antworten
- 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- Als Antwort markiertChris MullaneyMSFT, ModeratorMittwoch, 18. Februar 2009 17:49
- Als Antwort vorgeschlagenBill Wesse MSFTModeratorMittwoch, 11. Februar 2009 21:00
Alle Antworten
- 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- Als Antwort vorgeschlagenBill Wesse MSFTModeratorDienstag, 25. November 2008 14: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- Als Antwort markiertChris MullaneyMSFT, ModeratorMittwoch, 18. Februar 2009 17:49
- Als Antwort vorgeschlagenBill Wesse MSFTModeratorMittwoch, 11. Februar 2009 21:00

