add scripts to prevent family safety monitoring
This commit is contained in:
@@ -1267,6 +1267,32 @@ actions:
|
|||||||
docs: https://www.tenforums.com/tutorials/4077-turn-off-sync-settings-microsoft-account-windows-10-a.html
|
docs: https://www.tenforums.com/tutorials/4077-turn-off-sync-settings-microsoft-account-windows-10-a.html
|
||||||
code: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 0 /f
|
code: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 0 /f
|
||||||
revertCode: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 1 /f
|
revertCode: reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\SettingSync\Groups\Language" /t REG_DWORD /v "Enabled" /d 1 /f
|
||||||
|
-
|
||||||
|
category: Prevent Microsoft family safety monitoring
|
||||||
|
children:
|
||||||
|
-
|
||||||
|
name: Disable Microsoft Family Safety Monitor
|
||||||
|
recommend: standard
|
||||||
|
code: |-
|
||||||
|
schtasks /change /disable /tn "Microsoft\Windows\Shell\FamilySafetyMonitor"
|
||||||
|
schtasks /change /disable /tn "Microsoft\Windows\Shell\FamilySafetyRefresh"
|
||||||
|
schtasks /change /disable /tn "Microsoft\Windows\Shell\FamilySafetyUpload"
|
||||||
|
revertCode: |-
|
||||||
|
schtasks /change /enable /tn "Microsoft\Windows\Shell\FamilySafetyMonitor"
|
||||||
|
schtasks /change /enable /tn "Microsoft\Windows\Shell\FamilySafetyRefresh"
|
||||||
|
schtasks /change /enable /tn "Microsoft\Windows\Shell\FamilySafetyUpload"
|
||||||
|
-
|
||||||
|
name: Uninstall Microsoft Family Safety Monitor
|
||||||
|
recommend: strict
|
||||||
|
call:
|
||||||
|
-
|
||||||
|
function: RenameSystemFile
|
||||||
|
parameters:
|
||||||
|
filePath: '%SystemRoot%\System32\WpcTok.exe'
|
||||||
|
-
|
||||||
|
function: RenameSystemFile
|
||||||
|
parameters:
|
||||||
|
filePath: '%SystemRoot%\System32\WpcMon.exe'
|
||||||
-
|
-
|
||||||
category: Configure programs
|
category: Configure programs
|
||||||
children:
|
children:
|
||||||
@@ -4078,3 +4104,24 @@ functions:
|
|||||||
parameters: [ capabilityName ]
|
parameters: [ capabilityName ]
|
||||||
code: PowerShell -Command "Get-WindowsCapability -Online -Name '{{ $capabilityName }}*'' | Remove-WindowsCapability -Online"
|
code: PowerShell -Command "Get-WindowsCapability -Online -Name '{{ $capabilityName }}*'' | Remove-WindowsCapability -Online"
|
||||||
revertCode: PowerShell -Command "$capability = Get-WindowsCapability -Online -Name '{{ $capabilityName }}*''; Add-WindowsCapability -Name \"$capability.Name\" -Online"
|
revertCode: PowerShell -Command "$capability = Get-WindowsCapability -Online -Name '{{ $capabilityName }}*''; Add-WindowsCapability -Name \"$capability.Name\" -Online"
|
||||||
|
-
|
||||||
|
name: RenameSystemFile
|
||||||
|
parameters: [ filePath ]
|
||||||
|
code: |-
|
||||||
|
if exist "{{ $filePath }}" (
|
||||||
|
takeown /f "{{ $filePath }}"
|
||||||
|
icacls "{{ $filePath }}" /grant administrators:F
|
||||||
|
move "{{ $filePath }}" "{{ $filePath }}.OLD"
|
||||||
|
echo Moved "{{ $filePath }}" to "{{ $filePath }}.OLD"
|
||||||
|
) else (
|
||||||
|
echo No action required: {{ $filePath }} is not found.
|
||||||
|
)
|
||||||
|
revertCode: |-
|
||||||
|
if exist "{{ $filePath }}.OLD" (
|
||||||
|
takeown /f "{{ $filePath }}.OLD"
|
||||||
|
icacls "{{ $filePath }}.OLD" /grant administrators:F
|
||||||
|
move "{{ $filePath }}.OLD" "{{ $filePath }}"
|
||||||
|
echo Moved "{{ $filePath }}.OLD" to "{{ $filePath }}"
|
||||||
|
) else (
|
||||||
|
echo Could not find backup file "{{ $filePath }}.OLD" 1>&2
|
||||||
|
)
|
||||||
|
|||||||
@@ -23,19 +23,19 @@ function validateCode(name: string, code: string): void {
|
|||||||
if (!code || code.length === 0) {
|
if (!code || code.length === 0) {
|
||||||
throw new Error(`code of ${name} is empty or undefined`);
|
throw new Error(`code of ${name} is empty or undefined`);
|
||||||
}
|
}
|
||||||
ensureCodeHasUniqueLines(name, code);
|
|
||||||
ensureNoEmptyLines(name, code);
|
ensureNoEmptyLines(name, code);
|
||||||
|
ensureCodeHasUniqueLines(name, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureNoEmptyLines(name: string, code: string): void {
|
function ensureNoEmptyLines(name: string, code: string): void {
|
||||||
if (code.split('\n').some((line) => line.trim().length === 0)) {
|
if (code.split('\n').some((line) => line.trim().length === 0)) {
|
||||||
throw Error(`Script has empty lines "${name}"`);
|
throw Error(`script has empty lines "${name}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureCodeHasUniqueLines(name: string, code: string): void {
|
function ensureCodeHasUniqueLines(name: string, code: string): void {
|
||||||
const lines = code.split('\n')
|
const lines = code.split('\n')
|
||||||
.filter((line) => mayBeUniqueLine(line));
|
.filter((line) => !shouldIgnoreLine(line));
|
||||||
if (lines.length === 0) {
|
if (lines.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -45,13 +45,13 @@ function ensureCodeHasUniqueLines(name: string, code: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mayBeUniqueLine(codeLine: string): boolean {
|
function shouldIgnoreLine(codeLine: string): boolean {
|
||||||
const trimmed = codeLine.trim();
|
codeLine = codeLine.toLowerCase();
|
||||||
if (trimmed === ')' || trimmed === '(') { // "(" and ")" are used often in batch code
|
const isCommentLine = () => codeLine.startsWith(':: ') || codeLine.startsWith('rem ');
|
||||||
return false;
|
const consistsOfFrequentCommands = () => {
|
||||||
}
|
const frequentCodeParts = [ '(', ')', 'else' ];
|
||||||
if (codeLine.startsWith(':: ') || codeLine.startsWith('REM ')) { // Is comment?
|
const trimmed = codeLine.trim().split(' ');
|
||||||
return false;
|
return trimmed.every((part) => frequentCodeParts.includes(part));
|
||||||
}
|
};
|
||||||
return true;
|
return isCommentLine() || consistsOfFrequentCommands();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ScriptCode } from '@/domain/ScriptCode';
|
import { ScriptCode } from '@/domain/ScriptCode';
|
||||||
|
import { IScriptCode } from '../../../src/domain/IScriptCode';
|
||||||
|
|
||||||
describe('ScriptCode', () => {
|
describe('ScriptCode', () => {
|
||||||
describe('scriptName', () => {
|
describe('scriptName', () => {
|
||||||
@@ -15,75 +16,131 @@ describe('ScriptCode', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('code', () => {
|
describe('code', () => {
|
||||||
it('cannot construct with duplicate lines', () => {
|
describe('throws with invalid code', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const code = 'duplicate\nduplicate\ntest\nduplicate';
|
const scriptName = 'test-script';
|
||||||
// act
|
const testCases = [
|
||||||
const act = () => createSut(code);
|
{
|
||||||
// assert
|
name: 'throws when "execute" and "revert" are same',
|
||||||
expect(act).to.throw();
|
code: {
|
||||||
|
execute: 'same',
|
||||||
|
revert: 'same',
|
||||||
|
},
|
||||||
|
expectedError: `${scriptName} (revert): Code itself and its reverting code cannot be the same`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'cannot construct with undefined "execute"',
|
||||||
|
code: {
|
||||||
|
execute: undefined,
|
||||||
|
revert: 'code',
|
||||||
|
},
|
||||||
|
expectedError: `code of ${scriptName} is empty or undefined`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'cannot construct with empty "execute"',
|
||||||
|
code: {
|
||||||
|
execute: '',
|
||||||
|
revert: 'code',
|
||||||
|
},
|
||||||
|
expectedError: `code of ${scriptName} is empty or undefined`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
for (const testCase of testCases) {
|
||||||
|
it(testCase.name, () => {
|
||||||
|
// act
|
||||||
|
const act = () => new ScriptCode(scriptName, testCase.code.execute, testCase.code.revert);
|
||||||
|
// assert
|
||||||
|
expect(act).to.throw(testCase.expectedError);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it('cannot construct with empty lines', () => {
|
describe('throws with invalid code in both "execute" or "revert"', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const code = 'line1\n\n\nline2';
|
const scriptName = 'script-name';
|
||||||
|
const testCases = [
|
||||||
|
{
|
||||||
|
testName: 'cannot construct with duplicate lines',
|
||||||
|
code: 'duplicate\nduplicate\ntest\nduplicate',
|
||||||
|
expectedMessage: 'Duplicates detected in script "$scriptName":\n duplicate\nduplicate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'cannot construct with empty lines',
|
||||||
|
code: 'line1\n\n\nline2',
|
||||||
|
expectedMessage: 'script has empty lines "$scriptName"',
|
||||||
|
},
|
||||||
|
];
|
||||||
// act
|
// act
|
||||||
const act = () => createSut(code);
|
const actions = [];
|
||||||
|
for (const testCase of testCases) {
|
||||||
|
const substituteScriptName = (name) => testCase.expectedMessage.replace('$scriptName', name);
|
||||||
|
actions.push(...[
|
||||||
|
{
|
||||||
|
act: () => new ScriptCode(scriptName, testCase.code, undefined),
|
||||||
|
testName: `execute: ${testCase.testName}`,
|
||||||
|
expectedMessage: substituteScriptName(scriptName),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
act: () => new ScriptCode(scriptName, 'valid code', testCase.code),
|
||||||
|
testName: `revert: ${testCase.testName}`,
|
||||||
|
expectedMessage: substituteScriptName(`${scriptName} (revert)`),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
// assert
|
// assert
|
||||||
expect(act).to.throw();
|
for (const action of actions) {
|
||||||
|
it(action.testName, () => {
|
||||||
|
expect(action.act).to.throw(action.expectedMessage,
|
||||||
|
`Code used: ${action.code}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
it('cannot construct with empty or undefined values', () => {
|
describe('sets as expected with valid "execute" or "revert"', () => {
|
||||||
// arrange
|
// arrange
|
||||||
const name = 'test-code';
|
const testCases = [
|
||||||
const errorMessage = `code of ${name} is empty or undefined`;
|
{
|
||||||
const invalidValues = [ '', undefined ];
|
testName: 'code is a valid string',
|
||||||
invalidValues.forEach((invalidValue) => {
|
code: 'valid code',
|
||||||
// act
|
},
|
||||||
const act = () => new ScriptCode(name, invalidValue, '');
|
{
|
||||||
// assert
|
testName: 'code consists of frequent code parts',
|
||||||
expect(act).to.throw(errorMessage);
|
code: ') else (',
|
||||||
});
|
},
|
||||||
});
|
{
|
||||||
it('sets as expected', () => {
|
testName: 'code is a frequent code part',
|
||||||
// arrange
|
code: ')',
|
||||||
const expected = 'expected-revert';
|
},
|
||||||
|
{
|
||||||
|
testName: 'code with duplicated comment lines (::)',
|
||||||
|
code: ':: comment\n:: comment',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: 'code with duplicated comment lines (REM)',
|
||||||
|
code: 'REM comment\nREM comment',
|
||||||
|
},
|
||||||
|
];
|
||||||
// act
|
// act
|
||||||
const sut = createSut(expected);
|
const actions = [];
|
||||||
|
for (const testCase of testCases) {
|
||||||
|
actions.push(...[
|
||||||
|
{
|
||||||
|
testName: `execute: ${testCase.testName}`,
|
||||||
|
act: () => createSut(testCase.code),
|
||||||
|
expect: (sut: IScriptCode) => sut.execute === testCase.code,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: `revert: ${testCase.testName}`,
|
||||||
|
act: () => createSut('different code', testCase.code),
|
||||||
|
expect: (sut: IScriptCode) => sut.revert === testCase.code,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
// assert
|
// assert
|
||||||
expect(sut.execute).to.equal(expected);
|
for (const action of actions) {
|
||||||
});
|
it(action.testName, () => {
|
||||||
});
|
const sut = action.act();
|
||||||
describe('revert', () => {
|
expect(action.expect(sut));
|
||||||
it('cannot construct with duplicate lines', () => {
|
});
|
||||||
// arrange
|
}
|
||||||
const code = 'duplicate\nduplicate\ntest\nduplicate';
|
|
||||||
// act
|
|
||||||
const act = () => createSut('REM', code);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw();
|
|
||||||
});
|
|
||||||
it('cannot construct with empty lines', () => {
|
|
||||||
// arrange
|
|
||||||
const code = 'line1\n\n\nline2';
|
|
||||||
// act
|
|
||||||
const act = () => createSut('REM', code);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw();
|
|
||||||
});
|
|
||||||
it('cannot construct with when same as code', () => {
|
|
||||||
// arrange
|
|
||||||
const code = 'REM';
|
|
||||||
// act
|
|
||||||
const act = () => createSut(code, code);
|
|
||||||
// assert
|
|
||||||
expect(act).to.throw();
|
|
||||||
});
|
|
||||||
it('sets as expected', () => {
|
|
||||||
// arrange
|
|
||||||
const expected = 'expected-revert';
|
|
||||||
// act
|
|
||||||
const sut = createSut('abc', expected);
|
|
||||||
// assert
|
|
||||||
expect(sut.revert).to.equal(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user