Chr1st0uf

excel_word_background.vbs

Nov 19th, 2024 (edited)
1,542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 2.79 KB | Software | 0 0
  1. ' This script ensures Microsoft Word and Excel are always running.  
  2. ' It targets PCs with Windows build 26100 or higher (Win 11 24H2) and 32-bit Microsoft Office.  
  3. ' 1. GetWindowsBuild: Reads the Windows build number from the registry. Returns the build as an integer or 0 if invalid.  
  4. ' 2. IsOffice32BitInstalled: Checks if 32-bit Office is installed by looking for a registry key. Returns True or False.  
  5. ' 3. IsProcessRunning: Uses WMI to verify if a specified process (e.g., Word or Excel) is running. Returns True or False.  
  6. ' 4. LaunchApplication: Starts Word or Excel using their ProgID if not already active and sets them to run invisibly.  
  7. ' Main Logic:  
  8. ' - Verifies Windows build and Office installation.  
  9. ' - If criteria are met, it monitors and launches Word and Excel if needed, checking every 5 seconds.  
  10. '
  11. Function GetWindowsBuild()
  12.     On Error Resume Next
  13.     Dim objShell, build
  14.     Set objShell = CreateObject("WScript.Shell")
  15.     build = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentBuild")
  16.     If IsNumeric(build) Then
  17.         GetWindowsBuild = CInt(build)
  18.     Else
  19.         GetWindowsBuild = 0
  20.     End If
  21.     On Error GoTo 0
  22. End Function
  23.  
  24. Function IsOffice32BitInstalled()
  25.     On Error Resume Next
  26.     Dim objShell, path
  27.     Set objShell = CreateObject("WScript.Shell")
  28.     path = objShell.RegRead("HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Common\InstallRoot\Path")
  29.     If path <> "" Then
  30.         IsOffice32BitInstalled = True
  31.     Else
  32.         IsOffice32BitInstalled = False
  33.     End If
  34.     On Error GoTo 0
  35. End Function
  36.  
  37. Function IsProcessRunning(appName)
  38.     On Error Resume Next
  39.     Dim objWMI, processes
  40.     Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
  41.     Set processes = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & appName & "'")
  42.     IsProcessRunning = (Not processes Is Nothing And processes.Count > 0)
  43.     On Error GoTo 0
  44. End Function
  45.  
  46. Sub LaunchApplication(progID, ByRef appObject)
  47.     On Error Resume Next
  48.     If appObject Is Nothing Then
  49.         Set appObject = CreateObject(progID)
  50.         If appObject Is Nothing Then
  51.             Exit Sub
  52.         End If
  53.         appObject.Visible = False
  54.     End If
  55.     On Error GoTo 0
  56. End Sub
  57.  
  58. Dim windowsBuild, isOffice32Bit, wordApp, excelApp
  59.  
  60. windowsBuild = GetWindowsBuild()
  61. isOffice32Bit = IsOffice32BitInstalled()
  62.  
  63. If windowsBuild >= 26100 And isOffice32Bit Then
  64.     Do
  65.         If Not IsProcessRunning("WINWORD.EXE") Then
  66.             Set wordApp = Nothing
  67.             LaunchApplication "Word.Application", wordApp
  68.         End If
  69.  
  70.         If Not IsProcessRunning("EXCEL.EXE") Then
  71.             Set excelApp = Nothing
  72.             LaunchApplication "Excel.Application", excelApp
  73.         End If
  74.  
  75.         WScript.Sleep 5000
  76.     Loop
  77. End If
Advertisement
Add Comment
Please, Sign In to add comment