Click here to Skip to main content
15,886,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: For loop Pin
Richard Andrew x6428-Sep-23 12:12
professionalRichard Andrew x6428-Sep-23 12:12 
GeneralRe: For loop Pin
Dave Kreskowiak28-Sep-23 12:20
mveDave Kreskowiak28-Sep-23 12:20 
GeneralRe: For loop Pin
harold aptroot26-Sep-23 15:15
harold aptroot26-Sep-23 15:15 
GeneralRe: For loop Pin
Calin Negru26-Sep-23 23:09
Calin Negru26-Sep-23 23:09 
GeneralRe: For loop Pin
harold aptroot5-Oct-23 21:32
harold aptroot5-Oct-23 21:32 
QuestionService not created correctly under windows 11 but any older version. Pin
Rick R. 202323-Sep-23 14:54
Rick R. 202323-Sep-23 14:54 
AnswerRe: Service not created correctly under windows 11 but any older version. Pin
Randor 23-Sep-23 10:43
professional Randor 23-Sep-23 10:43 
GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Rick R. 202323-Sep-23 12:13
Rick R. 202323-Sep-23 12:13 
Just found out somethhing more.... As soon as I invoke the service creation function from within the program, I do get the normal service controll manager asking for elevated rights in order to create the service, what is exactly what happen. But then the service gets created with start type set to "manual".
If I do start the program manually "as Administrator" and then invoke the service creation function, the service gets created correctly with start type "auto". So there probably might be a problem with my elevation of rights!?... will check this. Strange though, that it works fin under any Windows version since XP... just not windows 11...

Here is the code to start with elevated rights:
BOOL IsRunAsAdministrator()
{
    BOOL isRunAsAdmin = FALSE;
    DWORD dwError = ERROR_SUCCESS;
    PSID pAdministratorsGroup = NULL;

    // Allocate and initialize a SID of the administrators group.
    SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
    if (!AllocateAndInitializeSid(
        &NtAuthority, 
        2, 
        SECURITY_BUILTIN_DOMAIN_RID, 
        DOMAIN_ALIAS_RID_ADMINS, 
        0, 0, 0, 0, 0, 0, 
        &pAdministratorsGroup))
    {
        goto Cleanup;
    }

    // Determine whether the SID of administrators group is enabled in 
    // the primary access token of the process.
    if (!CheckTokenMembership(NULL, pAdministratorsGroup, &isRunAsAdmin))
    {
        goto Cleanup;
    }

Cleanup:
    // Centralized cleanup for all allocated resources.
    if (pAdministratorsGroup)
    {
        FreeSid(pAdministratorsGroup);
        pAdministratorsGroup = NULL;
    }

    return isRunAsAdmin;
}

void RunServiceAsAdmin(char ch, const char *program, const char* name)
{
	// Launch itself as admin
	char param[255];
	SHELLEXECUTEINFO sei = { sizeof(sei) };

	memset(param, 0 , sizeof(param));
	sei.lpVerb = "runas";
	sei.lpFile = "sc.exe";
	sei.hwnd = NULL;
	sei.nShow = SW_NORMAL;

	if(ch == 'I')
	{
		sprintf(param, "create \"%s\" binPath= \"%s\" DisplayName=\"%s\"", name, program, name);
	}
	else
	{
		sprintf(param, "delete \"%s\"", name);
	}

	sei.lpParameters = param;

	if (!ShellExecuteEx(&sei))
	{
		show_error();
	}
}


modified 23-Sep-23 18:23pm.

GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Randor 23-Sep-23 12:22
professional Randor 23-Sep-23 12:22 
GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Rick R. 202323-Sep-23 12:24
Rick R. 202323-Sep-23 12:24 
GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Randor 23-Sep-23 12:53
professional Randor 23-Sep-23 12:53 
GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Rick R. 202323-Sep-23 13:06
Rick R. 202323-Sep-23 13:06 
QuestionRe: Service not created correctly under windows 11 but any older version. Pin
Randor 23-Sep-23 15:57
professional Randor 23-Sep-23 15:57 
AnswerRe: Service not created correctly under windows 11 but any older version. Pin
Rick R. 202324-Sep-23 6:37
Rick R. 202324-Sep-23 6:37 
GeneralRe: Service not created correctly under windows 11 but any older version. Pin
Randor 24-Sep-23 7:08
professional Randor 24-Sep-23 7:08 
Questionfingerprint sensor code with c++ Pin
ibiere21-Sep-23 23:56
ibiere21-Sep-23 23:56 
AnswerRe: fingerprint sensor code with c++ Pin
CPallini22-Sep-23 0:52
mveCPallini22-Sep-23 0:52 
QuestionType of array and printf specifiers Pin
Member 114540620-Sep-23 4:40
Member 114540620-Sep-23 4:40 
AnswerRe: Type of array and printf specifiers Pin
Mircea Neacsu20-Sep-23 5:11
Mircea Neacsu20-Sep-23 5:11 
AnswerRe: Type of array and printf specifiers Pin
k505420-Sep-23 5:36
mvek505420-Sep-23 5:36 
AnswerRe: Type of array and printf specifiers Pin
CPallini20-Sep-23 5:51
mveCPallini20-Sep-23 5:51 
QuestionHow to get disk model and serial number for the disk Windows is installed on Pin
JohnCodding19-Sep-23 20:41
JohnCodding19-Sep-23 20:41 
AnswerRe: How to get disk model and serial number for the disk Windows is installed on Pin
Richard MacCutchan19-Sep-23 21:59
mveRichard MacCutchan19-Sep-23 21:59 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
Valentinor19-Sep-23 22:15
Valentinor19-Sep-23 22:15 
GeneralRe: How to get disk model and serial number for the disk Windows is installed on Pin
Richard MacCutchan19-Sep-23 22:26
mveRichard MacCutchan19-Sep-23 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.