CCCPaste

TEMP-CLEAN.vbs

'=== ClearTemp_HiddenStartup.vbs ===
Option Explicit
Dim ws, fso, tempPath, file, folder, startupPath, scriptPath, shortcut

Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

' TEMP folder path
tempPath = ws.ExpandEnvironmentStrings("%TEMP%")

' Delete files inside TEMP
If fso.FolderExists(tempPath) Then
    On Error Resume Next
    For Each file In fso.GetFolder(tempPath).Files
        file.Delete True
    Next
    For Each folder In fso.GetFolder(tempPath).SubFolders
        folder.Delete True
    Next
    On Error GoTo 0
End If

' Get this script's full path
scriptPath = WScript.ScriptFullName

' Hidden startup shortcut
startupPath = ws.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Windows\Start Menu\Programs\Startup\ClearTemp.lnk"

If Not fso.FileExists(startupPath) Then
    Set shortcut = ws.CreateShortcut(startupPath)
    shortcut.TargetPath = "wscript.exe"
    shortcut.Arguments = Chr(34) & scriptPath & Chr(34)
    shortcut.WindowStyle = 0  ' Hidden window
    shortcut.Save
End If