*.wsf) to set an (arbitrary)
AppLocker
policy with a single double-click.
Note: the script requires neither
PowerShell
with its
AppLocker cmdlets
nor
Microsoft Management Console
with its GPEdit.msc and SecPol.msc
snap-ins.
*.wsf that sets an
AppLocker
policy, then activate it.
Create a text file *.wsf, for example
AppLocker.wsf, with the following content in an
arbitrary directory:
<?xml version='1.0' encoding='US-ASCII' standalone='yes' ?>
<package>
<comment>Copyright (C) 2009-2025, Stefan Kanthak</comment>
<job>
<object id='Application' progid='Shell.Application' />
<runtime>
<description>Set an AppLocker Policy on Windows 7 and later versions</description>
</runtime>
<script language='JScript'>
if (WScript.Arguments.Length != 0)
WScript.Arguments.ShowUsage()
else
Application.ShellExecute(WScript.FullName, '//Job:Policy ' + WScript.ScriptFullName, WScript.Path, 'RunAs', 1)
</script>
</job>
<job id='Policy'>
<object id='AppIdPolicyHandler' classid='clsid:F1ED7D4C-F863-4DE6-A1CA-7253EFDEE1F3' />
<object id='Application' progid='Shell.Application' />
<object id='Shell' progid='WScript.Shell' />
<resource id='Policy'><![CDATA[<AppLockerPolicy Version='1' />]]></resource>
<script language='JScript'>
if (Application.IsServiceRunning('AppIdSvc') == false)
Application.ServiceStart('AppIdSvc', true)
AppIdPolicyHandler.SetPolicy('', getResource('Policy'))
Shell.RegWrite('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Script Host\\Settings\\IgnoreUserSettings', 1)
Shell.RegWrite('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Script Host\\Settings\\UseWinSAFER', 1)
// WScript.Echo(Shell.Exec('GPUpdate.exe /Target:Computer').StdOut.ReadAll())
</script>
</job>
<job id='Sign'>
<object id='Signer' progid='Scripting.Signer' />
<runtime>
<description>Sign this Windows Script File</description>
<unnamed helpstring='Mandatory Argument' name='Certificate Name' required='1' />
</runtime>
<script language='JScript'>
if (WScript.Arguments.Named.Length != 0
|| WScript.Arguments.Unnamed.Length != 1)
WScript.Arguments.ShowUsage()
else
Signer.SignFile(WScript.ScriptFullName, WScript.Arguments.Unnamed.Item(0))
</script>
</job>
</package>
Note: the second setting written by the second job
enables
SAFER
– either Software Restriction Policies or
AppLocker
– for the
Windows Script Host,
and the first setting prevents to overrule it with the opposite
setting in the corresponding
Registry
key of any user account.
Replace the highlighted
XML snippet
– an (empty) allow all
AppLocker
policy – with the one you wish to deploy, for example the
generic
AppLocker
policy for Windows 11 presented as part of the
Eleventh Commandment,
then save the modified Windows Script File.
(Optional) If you have a code signing certificate run the following command line to sign the Windows Script File modified in step 2.:
WSCRIPT.EXE //Job:Sign ‹script file name›.wsf ‹certificate name›
Run the Windows Script File modified in step 2. respectively signed in step 3. per double-click.
Note: it requires Administrator rights and requests them via User Account Control if necessary.
Restart Windows to activate the just set AppLocker policy.
Create the text file AppLocker.xml with the following
content in an arbitrary directory:
<?xml version='1.0' encoding='UTF-16' standalone='yes' ?>
<!-- Copyright (C) 2011-2025, Stefan Kanthak -->
<Task version='1.3' xmlns='http://schemas.microsoft.com/windows/2004/02/mit/task'>
<RegistrationInfo>
<Author>AMNESIAC\Stefan</Author>
<Date>2011-04-27T12:34:56.7890123</Date>
<Description>Display a message box to the interactive user whenever an AppLocker entry is written to the event log</Description>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id='0' Path='Microsoft-Windows-AppLocker/EXE and DLL'><Select Path='Microsoft-Windows-AppLocker/EXE and DLL'>*[System[Provider[@Name='Microsoft-Windows-AppLocker'] and (Level=1 or Level=2 or Level=3)]]</Select><Select Path='Microsoft-Windows-AppLocker/MSI and Script'>*[System[Provider[@Name='Microsoft-Windows-AppLocker'] and (Level=1 or Level=2 or Level=3)]]</Select></Query></QueryList></Subscription>
<ValueQueries>
<Value name='eventChannel'>Event/System/Channel</Value>
<Value name='eventComputer'>Event/System/Computer</Value>
<Value name='eventCorrelation'>Event/System/Correlation</Value>
<Value name='eventFilePath'>Event/UserData/RuleAndFileData/FilePath</Value>
<Value name='eventID'>Event/System/EventID</Value>
<Value name='eventKeywords'>Event/System/Keywords</Value>
<Value name='eventLevel'>Event/System/Level</Value>
<Value name='eventOpcode'>Event/System/Opcode</Value>
<Value name='eventProcessID'>Event/System/Execution/@ProcessID</Value>
<Value name='eventProvider'>Event/System/Provider/@Name</Value>
<Value name='eventRecordID'>Event/System/EventRecordID</Value>
<Value name='eventTask'>Event/System/Task</Value>
<Value name='eventThreadID'>Event/System/Execution/@ThreadID</Value>
<Value name='eventTime'>Event/System/TimeCreated/@SystemTime</Value>
<Value name='eventUser'>Event/UserData/RuleAndFileData/TargetUser</Value>
<Value name='eventUserID'>Event/System/Security/@UserID</Value>
<Value name='eventVersion'>Event/System/Version</Value>
</ValueQueries>
</EventTrigger>
</Triggers>
<Principals>
<Principal id='Author'>
<GroupId>S-1-5-4</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<AllowHardTerminate>true</AllowHardTerminate>
<AllowStartOnDemand>false</AllowStartOnDemand>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<Enabled>true</Enabled>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Hidden>false</Hidden>
<IdleSettings>
<Duration>PT5M</Duration>
<RestartOnIdle>false</RestartOnIdle>
<StopOnIdleEnd>true</StopOnIdleEnd>
<WaitTimeout>PT1H</WaitTimeout>
</IdleSettings>
<MultipleInstancesPolicy>Queue</MultipleInstancesPolicy>
<Priority>7</Priority>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<StartWhenAvailable>false</StartWhenAvailable>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
</Settings>
<Actions Context='Author'>
<ShowMessage>
<Body>File: $(eventFilePath)
Event: $(eventID)
Provider: $(eventProvider)
Time: $(eventTime)
User: $(eventUser)
UserID: $(eventUserID)</Body>
<Title>AppLocker</Title>
</ShowMessage>
</Actions>
</Task>
Create a Scheduled Task from the task definition file
AppLocker.xml created in step 1.:
SCHTASKS.EXE /Create /TN "AppLocker Alert" /XML AppLocker.xml
SUCCESS: The scheduled task AppLocker Alert has successfully been created.
Get-AppLockerFileInformationGet-AppLockerPolicyNew-AppLockerPolicySet-AppLockerPolicyTest-AppLockerPolicySaferCloseLevel()SaferComputeTokenFromLevel()SaferCreateLevel function()SaferGetLevelInformation()SaferGetPolicyInformation()SaferIdentifyLevel()SaferRecordEventLogEntry()SaferSetLevelInformation()SaferSetPolicyInformation()SaferiIsExecutableFileType()Use the X.509 certificate to send S/MIME encrypted mail.
Note: email in weird format and without a proper sender name is likely to be discarded!
I dislike
HTML (and even
weirder formats too) in email, I prefer to receive plain text.
I also expect to see your full (real) name as sender, not your
nickname.
I abhor top posts and expect inline quotes in replies.
as iswithout any warranty, neither express nor implied.
cookiesin the web browser.
The web service is operated and provided by
Telekom Deutschland GmbH The web service provider stores a session cookie
in the web
browser and records every visit of this web site with the following
data in an access log on their server(s):