How to Delete Your Copied Passwords and Information in Windows 10

Globant CyberSOC
Globant
Published in
8 min readJun 5, 2023

Nowadays, companies are actively enhancing their security measures by making significant changes, implementing patches, fixes and policies to protect personal data and optimize operating systems. However, despite having trust in these efforts, it is still worthwhile to personally verify the status of recommended settings or consider adding another layer of security to your environment.

It is very common to copy your company/personal passwords for doing your daily tasks. Some tools like KeePass will erase the copied password from the clipboard, but most people don’t use such tools to keep their clipboard clean. This means sensitive data will remain in the clipboard until the computer is restarted. To overcome these frustrating and worry some thoughts about your personal security on the Internet, we can recommend some tricks to resolve this problem.

The Windows clipboard stores your copied data and pastes it when you select Paste on the context menu or with the CTRL + V keyboard shortcut. Windows allows you to fetch from previous copies, which can be a highly potential privacy breach to be exploited.

The Shortcut

Creating a shortcut that executes the clip command to erase your copied data is the easiest way to clean your clipboard. The clip command redirects the output of the command line into the Windows clipboard. Go to your desktop, click with your Right Mouse Button (RMB) anywhere, expand the New menu and click on Shortcut:

Create a new shortcut

Add the location and the following command to execute the cleanup process for the shortcut:

cmd /c echo.|clip

and click Next:

Set the cleanup command

This shortcut uses the echo command to print an empty line that the clip command will use to replace the contents of the Windows clipboard.

NOTE: in some situations, you could get an error when executing it, to resolve the issue, add the full path to the command instead:

%windir%\System32\cmd.exe /c “echo off | clip”

Set the complete path to the command

Pick a name for the shortcut (e.g. Clipboard Cleaner) and click Finish:

Create shortcut name

Now, whenever you click on the shortcut, the cleanup command will be executed, clearing the clipboard contents:

Shortcut created

The Context Menu

Another approach to execute the command for deleting your data without relying on shortcuts as we described before, is by adding it to the context menu.

Search in the search bar at the bottom for Regedit and press Open:

How to open de Registry

NOTE: If you have an error about permissions, it could be because you are not allowed to execute the Registry Editor. You can check your permissions by clicking on the “Run as administrator” menu entry:

How to run as Administrator

If the Registry Editor opens this way, then you will be able to continue to edit the Windows registry, if not, then you will receive a negative response:

Access Denied: Please log in with administrator privileges and try again.

We are going to edit the registry entry that controls the context menu. To navigate to this key, replace where it says Computer at the top with the following text:

Computer\HKEY_CLASSES_ROOT\Directory\Background

and hit Enter:

Change key location

Right-click on the Shell folder and create a new key by clicking in the submenu New Key:

Create a new key

Give the new key a name (e.g. Clipboard Cleaner):

Edit Key name
New key name

Right-click on the key you just created (ex: Clipboard Cleaner) and add a new key, by clicking in the submenu New –> Key:

Create another new key

Name it CMD and hit Enter:

New key name

Now, with the CMD key selected, double-click on the value on the right-hand side named Default:

Select key value field

Add the clipboard cleanup command: cmd /c echo.|clip and press OK:

Set new key value

Validate that you see it as the key’s data:

Check value data

To test the new context menu entry, go to your desktop and right-click on any space, you should see the new context menu entry:

New Context Menu option

PowerShell Scheduled Task Automation

The cleanup process can be automated by scheduling a Task in PowerShell. A Task allows us to schedule the execution of a command at specific intervals. We will create a Task to periodically execute the clip command we discussed earlier, avoiding the need to do a manual clipboard cleanup.

The Task creation involves doing three things:

  1. Create the task that will do the clipboard cleanup.
  2. Create a schedule trigger defining the execution interval.
  3. Register the defined Task to be executed with the previous Task Schedule.

We will need to open a PowerShell command line to perform the previous actions. Search on the search bar at the bottom for PowerShell and press Open:

How to open Powershell

Remember that you can run the command as an administrator if you cannot do it with your user. We will start by defining a Scheduled Task Action that will run the cleanup command in a schedule:

$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-Command Start-Process cmd.exe -ArgumentList '/c echo.|clip"

If your company has enabled a security feature called “PowerShell Execution Policy” to protect employee devices from running unauthorized scripts like PowerShell scripts .ps1 files, you may encounter an error message stating “Unauthorized Access”. Don’t worry, there’s a solution for this! You can make a simple adjustment at the beginning of your script by changing the Execution Policy scope to “RemoteSigned” on your local device. It’s important to note that your actions depend on your company’s policies and what they allow you to do.

Powershell: UnauthorizedAccess error
Powershell: Change policy to RemoteSigned

The next thing to do is define the task trigger to schedule the execution interval:

$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 30) -RepetitionDuration (New-TimeSpan -Days 3650)

This task trigger will start and run from the moment it is created, being executed every 30 minutes with a duration of 10 years, set in days.

Now we register the task to be executed using the previous schedule defined:

Register-ScheduledTask -TaskName "Clipboard Cleaner" -Description "This task cleans the clipboard every 30 minutes" -Action $action -Trigger $trigger -TaskPath "myTasks"

Finally, we start the scheduled task:

Start-ScheduledTask -TaskName "Clipboard Cleaner" -TaskPath "\myTasks\

After the scheduled task has been started, set Execution Policy back to Restricted:

Set-ExecutionPolicy Restricted -Scope LocalMachine -Force

To ease the creation of this task, here is a script with all the previous steps:

# Set execution policy to RemoteSigned
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine -Force
# Define scheduled task action
$action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c echo.|clip"
# Define scheduled task trigger to run every 30 minutes
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 30) -RepetitionDuration (New-TimeSpan -Days 3650)
# Register scheduled task
Register-ScheduledTask -TaskName "Clipboard Cleaner" -Description "This task cleans the clipboard every 30 minutes" -Action $action -Trigger $trigger -TaskPath "myTasks"
# Start the scheduled task
Start-ScheduledTask -TaskName "Clipboard Cleaner" -TaskPath "\myTasks\"
# Set execution policy back to Restricted
Set-ExecutionPolicy Restricted -Scope LocalMachine -Force

The following image shows the execution of the script:

Powershell: Complete script process

Now you scheduled your task. To check if the task is active, type in a PowerShell console:

Get-ScheduledTask -TaskPath "\myTasks\"

To print the previous command output in a more readable way, we can use the Format-table command to format the output into a table :

Get-ScheduledTask -TaskPath "\myTasks\" | Format-Table TaskName,Description,State,TaskPath
Powershell: Scheduled task information

To unregister the scheduled task, run this command:

Unregister-ScheduledTask -TaskName "Clipboard Cleaner" -TaskPath "\myTasks\" -Confirm:$false
Powershell: Unregister a scheduled Task

How to validate Windows default clipboard configuration

In general, a good security policy should disable or turn off the clipboard history; you can check if it is disabled by following these steps:

Search on the search bar at the bottom for Clipboard settings and click Open:

How to open Clipboard Settings

When the Clipboard settings show up, check that Clipboard history and Sync across devices are turned off (or disabled in some cases):

Clipboard Settings

If you see that the Clear clipboard data button is enabled, that’s because you previously copied some word, text, password (or images cropped) in your temporary history and this button will let you clear that information. We recommend TURN OFF these settings.

Conclusions

By following these steps, you can significantly enhance your privacy and security when copying data from the Windows clipboard. It is crucial to remain vigilant against malicious actors who may attempt to exploit your clipboard history or temporarily copied information to gain access to sensitive data.

Always remember that a single click gives them access to your personal or professional data if you open or click some links inside of phishing emails, attached documents or invoices, malvertising, unexpected and dirty pop-ups, malicious software downloads or installations. To safeguard your information and maintain its privacy, it is important to apply software patches, enable automatic operating system updates, and implement other recommended methods we have outlined.

By taking these precautions, you empower yourself to keep your information secure and confidential.

References

--

--