Najeebsk

TEMP-CLEAN.vbs

Nov 7th, 2025
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '=== ClearTemp_HiddenStartup.vbs ===
  2. Option Explicit
  3. Dim ws, fso, tempPath, file, folder, startupPath, scriptPath, shortcut
  4.  
  5. Set ws = CreateObject("WScript.Shell")
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7.  
  8. ' TEMP folder path
  9. tempPath = ws.ExpandEnvironmentStrings("%TEMP%")
  10.  
  11. ' Delete files inside TEMP
  12. If fso.FolderExists(tempPath) Then
  13.     On Error Resume Next
  14.     For Each file In fso.GetFolder(tempPath).Files
  15.         file.Delete True
  16.     Next
  17.     For Each folder In fso.GetFolder(tempPath).SubFolders
  18.         folder.Delete True
  19.     Next
  20.     On Error GoTo 0
  21. End If
  22.  
  23. ' Get this script's full path
  24. scriptPath = WScript.ScriptFullName
  25.  
  26. ' Hidden startup shortcut
  27. startupPath = ws.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Windows\Start Menu\Programs\Startup\ClearTemp.lnk"
  28.  
  29. If Not fso.FileExists(startupPath) Then
  30.     Set shortcut = ws.CreateShortcut(startupPath)
  31.     shortcut.TargetPath = "wscript.exe"
  32.     shortcut.Arguments = Chr(34) & scriptPath & Chr(34)
  33.     shortcut.WindowStyle = 0  ' Hidden window
  34.    shortcut.Save
  35. End If
  36.  
Advertisement
Add Comment
Please, Sign In to add comment