GoGreen PC Tune-Up™
Learn More

Insta-Install™
this is how ssl encrypt our websites
MTNCOMP | List View | Table View | myBlog (1765 Entries)
myBlog Home

Blog


VB Classic, Delete Windows Temp files

Microsoft Windows

by Mountain Computers Inc., Publication Date: Thursday, February 21, 2019

View Count: 1715, Keywords: VB Classic, Delete Windows Temp Files, Hashtags: #VBClassic #DeleteWindowsTempFiles



 
For those of you wanting to dump the windows temp files and don't have a good way to do it.. here is a tidbit.
to determine NativeOS you will need to figure that out . i have my own way. in addition, the actual .CMD that is created needs to be run with elevated privileges. So if you app already has been elevated, you can shell this CMD and it will carry those permissions just fine. 
 

  
 
Private Declare Function Wow64EnableWow64FsRedirection Lib "kernel32.dll" (ByVal Enable As Boolean) As Boolean
 

 
 Dim is64Bit As Boolean
 
Public Function IsHost64Bit() As Boolean
    Dim handle As Long
    ' Assume initially that this is not a WOW64 process
    is64Bit = False

    ' Then try to prove that wrong by attempting to load the
    ' IsWow64Process function dynamically
    handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")

    ' The function exists, so call it
    If handle <> 0 Then
        IsWow64Process GetCurrentProcess(), is64Bit
    End If

    ' Return the value
    IsHost64Bit = is64Bit
End Function
 
'the rest of your main code, etc...
 
Private Sub DeleteWindowsTempFiles()
Debug.Print "DeleteWindowsTempFiles()"
Screen.MousePointer = vbHourglass
ol.AddItem "Deleting windows temp files. takes ~ 1 minute."

Select Case LCase(NativeOS)

Case "windows 7", "windows 10", "windows 8.1", "windows 8", "windows vista", "windows xp"
    
        If Dir(App.Path & "\windows10-deletewintempfiles.cmd") <> "" Then
        'clear events log cmd file exists
            dbg2.AddItem "Clear Event cmd file (windows10-deletewintempfiles.cmd) exists."
        Else
        'clear events cmd file does not exist, create it
            dbg2.AddItem "Clear Events cmd file (windows10-deletewintempfiles.cmd) missing. creating it."
          Dim sFileText As String
          Dim iFileNo As Integer
          iFileNo = FreeFile
              'open the file for writing
          Open App.Path & "\windows10-deletewintempfiles.cmd" For Output As #iFileNo
          'please note, if this file already exists it will be overwritten!
         
          'write the clear event logs cmd file.
          Print #iFileNo, "@echo off"
          Print #iFileNo, "@echo deleting windows temp files"
          Print #iFileNo, "@echo Y | rd c:\windows\temp /s"
          Print #iFileNo, "@md c:\windows\temp"
      
          'close the file (if you dont do this, you wont be able to open it again!)
          Close #iFileNo
        
        End If
   
   If is64Bit Then
      Wow64EnableWow64FsRedirection False
      ShellExecute Me.hwnd, "open", "windows10-deletewintempfiles.cmd", "", App.Path, vbHidden
      Wow64EnableWow64FsRedirection True
   Else
      ShellExecute Me.hwnd, "open", "windows10-deletewintempfiles.cmd", "", App.Path, vbHidden
   End If
 

Case Else

End Select

Screen.MousePointer = vbNormal

End Sub

if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.

© 2024 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.