Click here to Skip to main content
14,979,837 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
PraiseRe: CWinThread for background processing Pin
CPallini7-Sep-20 1:33
mveCPallini7-Sep-20 1:33 
QuestionGroup policy editor api Pin
Member 1487268130-Aug-20 23:13
MemberMember 1487268130-Aug-20 23:13 
AnswerRe: Group policy editor api Pin
Richard MacCutchan31-Aug-20 1:27
mveRichard MacCutchan31-Aug-20 1:27 
QuestionRe: Group policy editor api Pin
Member 1487268131-Aug-20 17:08
MemberMember 1487268131-Aug-20 17:08 
AnswerRe: Group policy editor api Pin
Richard MacCutchan31-Aug-20 20:57
mveRichard MacCutchan31-Aug-20 20:57 
GeneralRe: Group policy editor api Pin
Member 1487268131-Aug-20 21:33
MemberMember 1487268131-Aug-20 21:33 
GeneralRe: Group policy editor api Pin
Richard MacCutchan31-Aug-20 21:40
mveRichard MacCutchan31-Aug-20 21:40 
AnswerRe: Group policy editor api Pin
Randor 1-Sep-20 23:24
professional Randor 1-Sep-20 23:24 
Hi,

You should add more error handling, this is just a code sample:

#include <guiddef.h>
#include <initguid.h>
#include <windows.h>
#include <comdef.h>
#include <cguid.h>
#include <atlcomcli.h>
#include <gpedit.h>
#include <Iaccess.h>

#pragma comment(lib,"gpedit.lib")

int main()
{
	HKEY key;
	HKEY pol;
	DWORD val = 1;
	DWORD disp = 0;
	GUID ext = REGISTRY_EXTENSION_GUID;

	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	CComPtr<IGroupPolicyObject> lgp;
	HRESULT hr = CoCreateInstance(CLSID_GroupPolicyObject, NULL, CLSCTX_INPROC_SERVER, IID_IGroupPolicyObject, (LPVOID*)&lgp);	
	if (SUCCEEDED(lgp->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY)))
	{
		if (SUCCEEDED(lgp->GetRegistryKey(GPO_SECTION_MACHINE, &key)))
		{
			//All Removable Storage classes: Deny All access
			RegCreateKeyExW(key, L"SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_QUERY_VALUE, NULL, &pol, &disp);
			RegSetValueEx(pol, L"Deny_All", 0, REG_DWORD, (BYTE*)&val, sizeof(val));
			
			RegCreateKeyExW(key, L"SOFTWARE\\Policies\\Microsoft\\Windows\\RemovableStorageDevices\\{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_QUERY_VALUE, NULL, &pol, &disp);
			//Removable Disks: Deny write access
			RegSetValueEx(pol, L"Deny_Write", 0, REG_DWORD, (BYTE*)&val, sizeof(val));
			//Removable Disks: Deny read access
			RegSetValueEx(pol, L"Deny_Read", 0, REG_DWORD, (BYTE*)&val, sizeof(val));
			//Removable Disks: Deny execute access
			RegSetValueEx(pol, L"Deny_Execute", 0, REG_DWORD, (BYTE*)&val, sizeof(val));

			RegCloseKey(key);
			hr = lgp->Save(TRUE, TRUE, &ext, const_cast<GUID*>(&CLSID_GPESnapIn));
			_com_error err(hr);
			wprintf(L"%s", err.ErrorMessage());
		}
	}
	lgp.Release();
	CoUninitialize();
	return 0;
}


It will set the following policies:

- All Removable Storage classes: Deny All access
- Removable Disks: Deny execute access
- Removable Disks: Deny read access
- Removable Disks: Deny write access

Best Wishes,
-David Delaune

[Edit two days later]
You can also add an attack surface reduction policy via Windows Defender that requires anything that executes from USB to be signed:
powershell.exe Add-MpPreference -AttackSurfaceReductionRules_Ids b2b3f03d-6a65-4f7b-a9c7-1c7ef74a9ba4 -AttackSurfaceReductionRules_Actions Enabled


modified 4-Sep-20 17:57pm.

QuestionWindows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
jackngill30-Aug-20 12:01
Memberjackngill30-Aug-20 12:01 
AnswerRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Mircea Neacsu30-Aug-20 16:47
mvaMircea Neacsu30-Aug-20 16:47 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
jackngill30-Aug-20 22:26
Memberjackngill30-Aug-20 22:26 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
jackngill2-Sep-20 22:48
Memberjackngill2-Sep-20 22:48 
AnswerRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
David Crow3-Sep-20 2:59
MemberDavid Crow3-Sep-20 2:59 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
jackngill3-Sep-20 4:01
Memberjackngill3-Sep-20 4:01 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
David Crow3-Sep-20 4:23
MemberDavid Crow3-Sep-20 4:23 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov3-Sep-20 6:41
MemberVictor Nijegorodov3-Sep-20 6:41 
QuestionRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
David Crow3-Sep-20 7:08
MemberDavid Crow3-Sep-20 7:08 
AnswerRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov3-Sep-20 7:47
MemberVictor Nijegorodov3-Sep-20 7:47 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
David Crow3-Sep-20 7:57
MemberDavid Crow3-Sep-20 7:57 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov3-Sep-20 8:04
MemberVictor Nijegorodov3-Sep-20 8:04 
QuestionRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
David Crow3-Sep-20 8:09
MemberDavid Crow3-Sep-20 8:09 
AnswerRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov3-Sep-20 9:27
MemberVictor Nijegorodov3-Sep-20 9:27 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov3-Sep-20 8:07
MemberVictor Nijegorodov3-Sep-20 8:07 
AnswerRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Victor Nijegorodov3-Sep-20 7:47
MemberVictor Nijegorodov3-Sep-20 7:47 
GeneralRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
jackngill3-Sep-20 11:41
Memberjackngill3-Sep-20 11:41 

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.