How to set the CMD script for Windows 11 editing to run automatically and give administrative rights?

tj_zero 65 Reputation points
2023-08-28T01:58:21.99+00:00

Implement the following functions:

  1. After logging out, Bitlock will automatically start to encrypt the specified drive again. (The status quo is always save the decryption state unless restarted, I wrote the script myself but currently have to start manually, and run CMD in "administrator" mode, I want to achieve pre-granted permission to run automatically)

2.C:\Users\ current user \Recent directory stored operation records, easy to leak, I want to write a script to specify a time limit to perform automatic cleaning;

The above belongs to the application of Windows system, hope experienced engineers to give guidance and help;

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-09-22T10:59:22.02+00:00

    Hi,

    You can create a scheduled task to run your current cmd script and add a trigger "On an event" with the log off event id 4647. You need to enable the group policy setting Audit Logoff which is under Computer Configuration\Windows Settings\Security Settings\Advanced Audit Policy Configuration\System Audit Policies.

    https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/audit-logoff

    https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4647

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.