Skip to content

Instantly share code, notes, and snippets.

@Sohamkadam333
Created December 12, 2023 18:38
Show Gist options
  • Save Sohamkadam333/2b1a106dcc2418f442eda9189d11596c to your computer and use it in GitHub Desktop.
Save Sohamkadam333/2b1a106dcc2418f442eda9189d11596c to your computer and use it in GitHub Desktop.
Establishes a connection to the service control manager on the specified computer and opens the specified service control manager database.
// OpenSCManager function is part of the Windows API, and it is used to open a handle to the Service Control Manager (SCM) database on a local or remote computer. The SCM is responsible for managing services on a Windows system.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
// OpenSCM
SC_HANDLE scmHandle = OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
if(scmHandle != NULL)
{
cout<<"Service Control Manager handle Opened Successfully "<<endl;
CloseServiceHandle(scmHandle);
cout<<"Service Control Manager handle Closed Successfully "<<endl;
}
else
{
cerr<<"Error Opening Service Control Manager, Error No : "<<GetLastError();
}
system("PAUSE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment