'분류 전체보기'에 해당되는 글 276건
- 2025.05.23 A lambda to a pointer to function
- 2025.01.10 How to change the parent process when calling CreateProcess API
- 2024.04.09 How to open Control Panel Items in the separate explorer.exe
- 2023.05.10 How to prevent a services from being stopped by administrative users.
- 2022.09.02 NtCreateToken
- 2022.05.30 Getting a device ID
- 2022.01.20 How to list installed programs using IShellAppManager
- 2021.12.31 LLDB
- 2021.11.23 How to change the foreground window
- 2021.09.15 App Container
Recently, I changed the lambda code to capture a local variable, and then the code didn't compile.
What I found was that only a lambda without capture can be converted to a function pointer.
The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type's function call operator. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type's function call operator. |
How to change the parent process when calling CreateProcess API

Usually, the parent process is the process that creats the new process. But you can change this behavior by setting STARTUPINFOEX.lpAttributeList.
HANDLE hParentProcess{ nullptr };
LPPROC_THREAD_ATTRIBUTE_LIST attrList{ nullptr };
// Initialize LPPROC_THREAD_ATTRIBUTE_LIST
hParentProcess = OpenProcess(PROCESS_CREATE_PROCESS, FALSE, parentProcessId);
SIZE_T attrListSize = 0;
InitializeProcThreadAttributeList(nullptr, 1, 0, &attrListSize);
attrList = (LPPROC_THREAD_ATTRIBUTE_LIST)malloc(attrListSize);
InitializeProcThreadAttributeList(attrList, 1, 0, &attrListSize);
UpdateProcThreadAttribute(attrList, 0, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &hParentProcess,
sizeof(hParentProcess), nullptr, nullptr);
// Set LPPROC_THREAD_ATTRIBUTE_LIST to the STARTUPINFOEX
STARTUPINFOEX si = { sizeof(si) };
si.StartupInfo.cb = sizeof(si);
si.lpAttributeList = attrList;
PROCESS_INFORMATION pi = { 0 };
CreateProcess(nullptr, argv[1], nullptr, nullptr, FALSE, EXTENDED_STARTUPINFO_PRESENT, nullptr, nullptr, &si.StartupInfo, &pi);
How to open Control Panel Items in the separate explorer.exe

If you want to open 'This PC\All Control Panel Items\Programs and Features'
First you need to convert each items to GUID
- This PC -> 20d04fe0-3aea-1069-a2d8-08002b30309d
- All Control Panel Items -> 21ec2020-3aea-1069-a2dd-08002b30309d
- Programs and Features -> 7b81be6a-ce2b-4676-a29e-eb907a5126c5
Then launch exporer.exe with /separate paramter
For example:
C:\Windows\explorer.exe /separate, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{21ec2020-3aea-1069-a2dd-08002b30309d}\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}
Then the above process will be terminated and the below process shows up with ' Programs and Features'
C:\WINDOWS\explorer.exe /factory,{75dff2b7-6936-4c06-a8bb-676a7b00b24b} -Embedding
If you want to launch explorer.exe as your descendant process, there is a way
- Run: C:\WINDOWS\explorer.exe /factory,{75dff2b7-6936-4c06-a8bb-676a7b00b24b} -Embedding
- This process is your descendant process and it is invisible.
- Run: C:\Windows\explorer.exe /separate, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{21ec2020-3aea-1069-a2dd-08002b30309d}\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}
- This process will be terminated and 'Programs and Features' will be showed in the previous explorer.exe.
- But if there is one more explorer.exe /factory, there is no gurantee which one shows 'Programs and Features'.
How to prevent a services from being stopped by administrative users.

It is almost impossible to prevent administrators from stopping services.
But there are some ways to make it difficult for them.
- Ignoring the stop notification
SetServiceStatus function (winsvc.h) - Win32 apps
Updates the service control manager's status information for the calling service.
learn.microsoft.com
If you call this function without 'SERVICE_ACCEPT_STOP' in dwControlsAccepted member in SERVICE_STAUS structure, the service ignores the stop notification.
- Chaning the access control on the service
// Get an acl of the service
ATL::CDacl dacl;
bool result = ATL::AtlGetDacl(L"serviceName", SE_SERVICE, &dacl);
// Traverse all access masks
for (UINT index = 0; index < count; ++index) {
CSid aceSid;
ACCESS_MASK mask = 0;
BYTE type = 0;
BYTE flags = 0;
GUID objectType;
GUID inheritedObjectType;
dacl.GetAclEntry(index, &aceSid, &mask, &type, &flags, &objectType, &inheritedObjectType);
}
// Change & Set acess mask
// Remove old ace
dacl.RemoveAce(speciifcIndex);
// Remove permissions(SERVICE_CHANGE_CONFIG & SERVICE_STOP)
specificMask &= ~SERVICE_CHANGE_CONFIG;
specificMask &= ~SERVICE_STOP;
// Add new ace
result = dacl.AddAllowedAce(specificSid, specificMask, specificFlags);
Return Codes
- STATUS_SUCCESS - Indicates the operation was successful.
- STATUS_INVALID_OWNER - Indicates the ID provided to be assigned
as the default owner of the token does not have an attribute
indicating it may be assigned as an owner. - STATUS_INVALID_PRIMARY_GROUP - Indicates the group ID provided
via the PrimaryGroup parameter was not among those assigned
to the token in the Groups parameter. - STATUS_BAD_IMPERSONATION_LEVEL - Indicates no impersonation level
was provided when attempting to create a token of type
TokenImpersonation.
How to list installed programs using IShellAppManager

// appwiz.cpl is COM server related to (UnInstall or Change a program)
#include <shappmgr.h>
#include <iostream>
#import <appwiz.cpl>
// If this import gets into trobule, you could solve the problem by using #import directives
/*
#import <appwiz.cpl> rename("tag_inner_PROPVARIANT", "_tag_inner_PROPVARIANT") \
inject_statement("typedef struct _LARGE_INTEGER2 { LONGLONG QuadPart; } LARGE_INTEGER2;") \
inject_statement("typedef struct _ULARGE_INTEGER2 { ULONGLONG QuadPart;} ULARGE_INTEGER2;") \
rename("_LARGE_INTEGER", " _LARGE_INTEGER2") \
rename("_ULARGE_INTEGER", "_ULARGE_INTEGER2")
*/
int main()
{
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
class __declspec(uuid("{352EC2B7-8B9A-11D1-B8AE-006008059382}")) AppWiz;
static const CLSID CLSID_AppWiz = __uuidof(AppWiz);
SHAPPMGRPLib::IShellAppManagerPtr spShellAppManaager;
HRESULT hr = spShellAppManaager.CreateInstance(CLSID_AppWiz, NULL, CLSCTX_INPROC_SERVER);
SHAPPMGRPLib::IEnumInstalledAppsPtr spEnumInstalledApps;
hr = spShellAppManaager->EnumInstalledApps(&spEnumInstalledApps);
SHAPPMGRPLib::IInstalledAppPtr spInstalledApp;
SHAPPMGRPLib::IInstalledApp* pInstalledApp;
while (S_OK == (hr = spEnumInstalledApps->Next(&pInstalledApp))) {
spInstalledApp = pInstalledApp;
SHAPPMGRPLib::_AppInfoData data = { 0 };
data.cbSize = sizeof(SHAPPMGRPLib::_AppInfoData);
data.dwMask = AIM_DISPLAYNAME | AIM_VERSION | AIM_PUBLISHER | AIM_INSTALLDATE;
hr = spInstalledApp->GetAppInfo(&data);
// You have to check the validation of the data before using it.
std::wcout << "Name: " << data.pszDisplayName << " ver: " << data.pszVersion
<< " publisher: " << data.pszPublisher << " installedOn: " << data.pszInstallDate << std::endl;
}
::CoUninitialize();
return 0;
}