Clear Ram Now 1.0 https://github.com/kosherplay-betatester/Clear-RAM-Now >> open source .bat and .ps1 version autoinstall sysinternals and run commmand "RAMMap64.exe -Ew" on the fly with auto instaltion of an icon on wthe desktop #2897
kosherplay-betatester
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
##################################################################################
.bat version
#####################
@echo off
REM --> If the error level is not 0, it means the user does not have administrator rights.
if '%errorlevel%' NEQ '0' (
echo ===========================================================================
echo This script requires administrative privileges to run.
echo Please press any key to request elevation.
echo ===========================================================================
pause
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
REM Create a temporary VBScript to elevate the script using UAC.
REM The VBScript runs the same batch file with elevated privileges.
:gotAdmin
REM The script now runs with admin privileges, so we can proceed with the rest of the operations.
pushd "%CD%" REM Save the current directory.
CD /D "%~dp0" REM Change the directory to the script's location.
:--------------------------------------
REM Define variables for paths and file names used in the script.
set "RAMMAP_PATH=%windir%\RAMMap64.exe" REM Path to the RAMMap executable in the Windows directory.
set "SHORTCUT_NAME=Clear RAM Now.lnk" REM Name of the desktop shortcut that will be created.
set "DESKTOP_PATH=%USERPROFILE%\Desktop" REM Path to the current user's desktop.
set "SHORTCUT_PATH=%DESKTOP_PATH%%SHORTCUT_NAME%" REM Full path for the desktop shortcut.
REM Check if RAMMap64.exe already exists in the Windows directory.
if exist "%RAMMAP_PATH%" (
echo RAMMap64.exe already exists.
) else (
REM If RAMMap64.exe does not exist, download and install it.
)
REM Check if the desktop shortcut already exists.
if exist "%SHORTCUT_PATH%" (
REM If the shortcut already exists, no need to create it again.
echo Shortcut 'Clear RAM Now' already exists on Desktop.
) else (
REM If the shortcut doesn't exist, create it.
)
REM Now, run RAMMap64.exe with the -Ew argument to clear Empty Working Sets and free up memory.
echo Running RAMMap64.exe -Ew to clear Empty Working Sets...
"%RAMMAP_PATH%" -Ew
REM If the command runs successfully, display a success message.
echo Memory has been cleared successfully.
REM Pause to allow the user to see the result before the script closes.
pause
Check for Administrator privileges
This block checks if the script is running with administrator rights. If not, it exits with a warning.
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
Write-Warning "This script needs to be run as Administrator."
exit
}
Set strict error handling to stop execution on any errors
$ErrorActionPreference = 'Stop'
Define the path to RAMMap64.exe in the Windows directory
This variable holds the path where RAMMap64.exe will be installed or where it should already be located.
$rammapExe = Join-Path $env:windir "RAMMap64.exe"
Define the desktop shortcut path
This defines the name and location of the shortcut that will be created on the user's desktop.
$shortcutName = "Clear RAM Now.lnk"
$desktopPath = [Environment]::GetFolderPath("Desktop") # Get the user's Desktop path
$shortcutPath = Join-Path $desktopPath $shortcutName
Check if RAMMap64.exe already exists
if (Test-Path $rammapExe) {
# RAMMap64.exe exists, so we don't need to download it
Write-Host "RAMMap64.exe already exists."
} else {
# If RAMMap64.exe doesn't exist, download and install it
$zipUrl = "https://download.sysinternals.com/files/SysinternalsSuite.zip" # URL to download the Sysinternals Suite ZIP file
$zipPath = "$env:TEMP\SysinternalsSuite.zip" # Temporary path to save the downloaded ZIP file
$destinationPath = $env:windir # Destination path where the ZIP will be extracted (Windows directory)
}
##################################################################################
.Ps1 version
#####################
Check for Administrator privileges
This block checks if the script is running with administrator rights. If not, it exits with a warning.
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
Write-Warning "This script needs to be run as Administrator."
exit
}
Set strict error handling to stop execution on any errors
$ErrorActionPreference = 'Stop'
Define the path to RAMMap64.exe in the Windows directory
This variable holds the path where RAMMap64.exe will be installed or where it should already be located.
$rammapExe = Join-Path $env:windir "RAMMap64.exe"
Define the desktop shortcut path
This defines the name and location of the shortcut that will be created on the user's desktop.
$shortcutName = "Clear RAM Now.lnk"
$desktopPath = [Environment]::GetFolderPath("Desktop") # Get the user's Desktop path
$shortcutPath = Join-Path $desktopPath $shortcutName
Check if RAMMap64.exe already exists
if (Test-Path $rammapExe) {
# RAMMap64.exe exists, so we don't need to download it
Write-Host "RAMMap64.exe already exists."
} else {
# If RAMMap64.exe doesn't exist, download and install it
$zipUrl = "https://download.sysinternals.com/files/SysinternalsSuite.zip" # URL to download the Sysinternals Suite ZIP file
$zipPath = "$env:TEMP\SysinternalsSuite.zip" # Temporary path to save the downloaded ZIP file
$destinationPath = $env:windir # Destination path where the ZIP will be extracted (Windows directory)
}
Beta Was this translation helpful? Give feedback.
All reactions