Jump to content

CheeseIt v1.0 Powershell Script Launcher and Cleaner


RMarsh

Recommended Posts

Save as .ps1 file and Run with Powershell

###############################################################################
#
# This script:

# 1.) Kills processes for specified undesirable apps
# 2.) Copies the specified Key to the clipboard
# 3.) Launches the cheese EXE and waits for you to do the thing
# 4.) Removes references to previously executed programs from Registry and 
#     C:\Windows\Prefetch
# 5.) Ejects USB
#
# INSTRUCTIONS:
#    - Edit the variables below for the cheese file name, path, and keys
#    - Add any additional undesirable programs you would like killed before 
#     running cheese in the KILL section
#      (BattleNet, Steam, And Discord already included)
#    - Save file
#    - Right click, Run with Powershell
#
# !!!CAUTION:    Windows Prefetch folder requires Admin access so unless you've 
#               already opened it the cleaning command below will not work.  
#               STRONGLY RECOMMEND you disable prefetch and superfetch to avoid
#               storing files there and then there's no issue.
#    SEE HERE: https://www.thewindowsclub.com/disable-superfetch-prefetch-ssd
#
# !!!USB EJECTION:    When Windows says USB is currently in use, choose Continue
#                    and THEN press Enter to close the Powershell window.  
#                    If you close the window first, the USB WILL NOT BE EJECTED!  
#
#                    Also note that after ejection you might still see the drive
#                    letter in Windows but it's not technically mounted.             
#
################################################################################

###########################################################
# Wildcard name of cheese file (used for cleaning registry)
###########################################################
$CHEESEFILE="*mycheese*"

#############################################
# Full path to cheeze file EXE
#############################################
$CHEESEEXE="F:\mycheese.exe"

#######################################################
# Keys you want to see in the menu - adjust accordingly
#######################################################
$KEY1TEXT="MW2"
$KEY1="1111-2222-3333-4444"

$KEY2TEXT="OW2"
$KEY2="ABCD-EFGH-IJKL-MNOP"

$KEY3TEXT="NONE"
$KEY3="XXXX-XXXX-XXXX-XXXX-XXXX"

$KEY4TEXT="NONE"
$KEY4="XXXX-XXXX-XXXX-XXXX-XXXX"

# Key Selection Menu
#
$MainMenu = {
Write-Host " ***************************"
Write-Host " *      Select Key         *"
Write-Host " ***************************"
Write-Host
Write-Host "1.) " $KEY1TEXT " - " $KEY1
Write-Host "2.) " $KEY2TEXT " - " $KEY2
Write-Host "3.) " $KEY3TEXT " - " $KEY3
Write-Host "4.) " $KEY4TEXT " - " $KEY4
Write-Host "5.)  Nevermind - get me out!"
Write-Host
Write-Host "Select an option and press Enter: "  -nonewline
}

Invoke-Command $MainMenu
$Select = Read-Host
cls
Switch ($Select)
    {
        1 { Write-Output $KEY1 | clip ; Write-Host "`n"$KEY1TEXT "key copied to clipboard."}
        2 { Write-Output $KEY2 | clip ; Write-Host "`n"$KEY2TEXT "key copied to clipboard."}
    3 { Write-Output $KEY3 | clip ; Write-Host "`n"$KEY3TEXT "key copied to clipboard."}
    4 { Write-Output $KEY4 | clip ; Write-Host "`n"$KEY4TEXT "key copied to clipboard."}
        5 { exit }
    }

###########################################################
# KILL undesirable apps prior to launch
#
# (Add any other known undesirables on new lines as needed)
###########################################################
echo "Killing things we don't like..."
Get-Process Battle.Net -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue 
Get-Process Steam -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue 
Get-Process Discord -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue 

##################################
# Execute Cheese and wait for exit
##################################
echo "Running cheese.  Paste your key at the opportune moment..." 
try { Start-Process -FilePath $CHEESEEXE -verb RunAs -wait }
catch { 
    Write-Host "`n`n`n!!!ERROR launching" $CHEESEEXE "...make sure you entered the correct path."
    pause
    exit
}

# Sleep a couple seconds to make sure Registry entries are created
#
echo "Just a sec..."
Start-Sleep -Seconds 2


# Remove registry entries that contain recently executed programs
#
echo "Removing registry entries..."
#echo "Removing HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
Remove-ItemProperty -Path "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" -Name $CHEESEFILE -ErrorAction SilentlyContinue

#echo "Removing HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted"
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted" -Name $CHEESEFILE -ErrorAction SilentlyContinue

#echo "Removing HKCU:\Software\Microsoft\Windows\ShellNoRoam\MUICache"
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\ShellNoRoam\MUICache" -Name $CHEESEFILE -ErrorAction SilentlyContinue

#echo "Removing HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store"
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" -Name $CHEESEFILE -ErrorAction SilentlyContinue

echo "Removing C:\Windows\Prefetch"
Remove-Item -Path C:\Windows\Prefetch\$CHEESEFILE -recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path C:\Windows\Prefetch\*consent* -recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path C:\Windows\Prefetch\*notepad* -recurse -Force -ErrorAction SilentlyContinue

########################################################################################################
# Eject USB
#
# This ejects ALL removable drives.  Sorry, I don't feel like figuring it out from $CHEESEEXE right now
# so we do them all.
########################################################################################################
echo "Ejecting USB..."
$volList = get-wmiobject -Class Win32_Volume | where{$_.drivetype -eq '2'}  
if ($volList){
    ForEach ($vol in $volList){
        $volLetter = $vol.DriveLetter
        echo "Ejecting drive $volLetter"
        $Eject =  New-Object -comObject Shell.Application
        $Eject.NameSpace(17).ParseName($volLetter).InvokeVerb("Eject")
    }
}
else {
    echo "No removable drive found"
}

pause
exit
 

Link to comment

Sorry if I say it that way but this Script is.. Bad. Maybe it works, haven’t test it out but what I can see so far it is more then confusing and if there any changes in the system it would be really annoying to maintain it. Maybe if It has some structure and some functions it could be partially useful but personally I wouldn't use it in any case. You even don't say on which system nor built it was tested or coded and what are the lines for. 

Link to comment

LOL!  It is commented throughout and if you can’t read and figure it out that’s on you.  It’s a simple little script I threw together and didn’t feel like wrapping everything up into a bunch of functions.

The only things that might need to change periodically are your key(s) or the name and path to your executable.

I made this for myself and threw it out here in case anyone else wanted to check it out.  
Again, if you can’t figure out a simple powershell script and don’t want to use it, don’t.  If you want to take it and make a version that works better for you, do it. 

Thanks for the feedback and have a great day!

Edited by RMarsh
Link to comment
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...