New
#11
They're the remnants of Microsoft Provisioning. I just delete them..
I know that I am late, but I just stumbled via web search over the posting. This described exactly the observation I made while controlling the content of my TEMP folder. After a little testing (I modified the LOGON task to allow run on demand, then started the task manually, waited some 90 secs and boom: there where another "tw-*****.tmp" folders in my TEMP folder) I decided to beat the system with its own tools.
First of all, you have to launch taskschd.msc of course.
I modified the task under Task Scheduler Library > Microsoft > Windows > Management > Provisioning > Logon a little bit further in this way:
- I added another action under the original line %windir%\system32\ProvTool.exe /turn 5 /source LogonIdleTask, leaving the first line and its task unmodified. The new line reads %windir%\System32\cscript.exe //nologo c:\vbscript\deleteemptyfolders.vbs %windir%\temp 10. For this you have to click on Properties of the Logon task and select the Actions tab. On this you can click on New to add a new action.
- In c:\vbscript (or any directory of your choice, you have to change the path above accordingly) you place the script deleteemptyfolders.vbs (see below). This means that you put the %windir%\System32\cscript.exe part of the line in then field Program/script and the //nologo c:\vbscript\deleteemptyfolders.vbs %windir%\temp 10 part in the field Add arguments (optional):.
- After doing so you can close the dialog with OK.
Result: See picture (apology for only having a german version screenshot).
Now, this is only the half way. Now you need the script, which is following here:
If you now start the modified task Logon again, and watch your TEMP folder some 90 seconds, you should notice the generation of our "tw-*****.tmp" folders in TEMP folder and – after the given 10 seconds – those "tw-*****.tmp" folders should be gone again. Proof of concept.Code:Option Explicit Dim oFso : Set oFso = WScript.CreateObject("Scripting.Filesystemobject") ' oFso As IWshRuntimeLibrary.FileSystemObject / Windows Script Host Object Model / C:\Windows\SysWOW64\wshom.ocx Dim WshShell : Set WshShell = WScript.CreateObject("Wscript.Shell") ' WshShell As IWshRuntimeLibrary.WshShell / Microsoft Scripting Runtime / C:\Windows\SysWOW64\scrrun.dll Dim oShell : Set oShell = WScript.CreateObject("Shell.Application") ' oShell As Shell32.Shell / Microsoft Shell Controls And Automation / C:\Windows\SysWOW64\shell32.dll Dim oArgs : Set oArgs = WScript.Arguments ' aArgs As IHost.IArguments_Class / Windows Script Host / C:\Windows\SysWOW64\wscript.exe Call Main ' Set WshShell = Nothing ' Set oFso = Nothing WScript.Quit ' ----------------------------------------------------- Sub Main Dim oFld Dim ParamDir, ParamWait ' Copyright Thomas Rauner, September 2019 ' GNU GENERAL PUBLIC LICENSE; see https://www.gnu.org/licenses/gpl-3.0 ' Purpose: ' This script deletes all empty folders and subfolders in a given or current directory. ' Prerequisits: None. Output: None ' Parameters: {ThisScript} [ParamDir] [ParamWait] ' {ThisScript}: This script, original name: DeleteEmptyFolders.vbs ' [ParamDir] (optional): Folder, in which the script will search for and delete empty folders. ' A folders means to be empty, if (a) it does not contain any files and ' (b) contains no or only empty subfolders. ' [ParamWait] (optional): Time in seconds to wait before the script starts searching and deleting. ' A little pause might be necessary, if you plan to hook this skript ' to the task "Task Scheduler Library > Microsoft > Windows > ' Management > Provisioning > Logon". A reasonable waiting time (tested) ' should be 3 seconds. ' Example command line: wscript.exe //nologo DeleteEmptyFolders.vbs %windir%\temp 3 If oArgs.count > 0 Then On Error Resume Next ParamDir = oArgs(0) ' First unnamed parameter should be the folder ParamDir = WshShell.ExpandEnvironmentStrings(ParamDir) ' Environment variables allowed If Not oFso.FolderExists(ParamDir) Then ParamDir = "" ' If folder does not exist, empty variable ParamWait = oArgs(1) ' Second unnamed parameter should be a number (seconds to wait) If Not IsNumeric(ParamWait) Then ParamWait = 0 Else ParamWait = CLng(ParamWait) On Error GoTo 0 End If If ParamDir = "" Then ParamDir = WshShell.CurrentDirectory ' If folder variable is empty, take the current folder WScript.Sleep ParamWait * 1000 ' wait the number of seconds found above Call TraverseFolders(ParamDir) ' start searching for empty folders End Sub ' ----------------------------------------------------- Sub TraverseFolders(path) Dim oFolder, oSubFolder Set oFolder = oFso.GetFolder(path) If oFolder.Files.Count = 0 Then ' No files => candidate for erasure If oFolder.SubFolders.Count = 0 Then ' still no subfolders => erase folder On Error Resume Next ' WScript.Echo "Deleting " & oFolder.Path & " ..." ' uncomment this, if you want to see what ois happening. Hint: Only do this with cscript.exe, otherwise you might have to click numerous "OK" messages. oFolder.Delete ' This is what we are after On Error GoTo 0 Else ' has subfolders? => check subfolders For Each oSubFolder in oFolder.SubFolders TraverseFolders(oSubFolder.Path) Next ' oSubFolder End If Else ' has files? => maybe has (empty?) subfolders also => go checking For Each oSubFolder in oFolder.SubFolders TraverseFolders(oSubFolder.Path) Next ' oSubFolder End If End Sub
Of course you can lower the waiting time back to 3 seconds as described in the script – it's cosmetics. And also you now can reset the checkbox Allow a task to be run on demand on the SETTINGS tab back to unchecked.
With this setting the ominous "tw-*****.tmp" folders should be out of your sight. After the next Windows upgrade you very likely have to reset this task again like described above.
I hope this to be helpful not only to me. Thank you all for your research that made this posting possible. Cheers!
Excellent script. I tried it from an elevated PowerShell prompt and it worked immediately. (I used 5 as the delay value)
I'm not sure though about adding it as an action to that particular task. I think I'll create a seperate logon task... but thank you anyway.