Chr1st0uf

excel_word_2013_background.vbs

Feb 7th, 2025 (edited)
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 2.88 KB | Software | 0 0
  1. ' This script ensures Microsoft Word and Excel (Office 2013) are always running.
  2. ' It targets PCs with Windows build 26100 or higher (Windows 11 24H2) and 32-bit or 64-bit Microsoft Office 2013.
  3. ' 1. GetWindowsBuild: Reads the Windows build number from the registry. Returns the build as an integer or 0 if invalid.
  4. ' 2. IsOffice2013Installed: Checks if Office 2013 is installed by verifying registry keys.
  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 IsOffice2013Installed()
  25.     On Error Resume Next
  26.     Dim objShell, path1, path2
  27.     Set objShell = CreateObject("WScript.Shell")
  28.     path1 = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot\Path")
  29.     path2 = objShell.RegRead("HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\Common\InstallRoot\Path")
  30.     If path1 <> "" Or path2 <> "" Then
  31.         IsOffice2013Installed = True
  32.     Else
  33.         IsOffice2013Installed = False
  34.     End If
  35.     On Error GoTo 0
  36. End Function
  37.  
  38. Function IsProcessRunning(appName)
  39.     On Error Resume Next
  40.     Dim objWMI, processes
  41.     Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
  42.     Set processes = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & appName & "'")
  43.     IsProcessRunning = (Not processes Is Nothing And processes.Count > 0)
  44.     On Error GoTo 0
  45. End Function
  46.  
  47. Sub LaunchApplication(progID, ByRef appObject)
  48.     On Error Resume Next
  49.     If appObject Is Nothing Then
  50.         Set appObject = CreateObject(progID)
  51.         If appObject Is Nothing Then
  52.             Exit Sub
  53.         End If
  54.         appObject.Visible = False
  55.     End If
  56.     On Error GoTo 0
  57. End Sub
  58.  
  59. Dim windowsBuild, isOffice2013, wordApp, excelApp
  60.  
  61. windowsBuild = GetWindowsBuild()
  62. isOffice2013 = IsOffice2013Installed()
  63.  
  64. If windowsBuild >= 26100 And isOffice2013 Then
  65.     Do
  66.         If Not IsProcessRunning("WINWORD.EXE") Then
  67.             Set wordApp = Nothing
  68.             LaunchApplication "Word.Application", wordApp
  69.         End If
  70.  
  71.         If Not IsProcessRunning("EXCEL.EXE") Then
  72.             Set excelApp = Nothing
  73.             LaunchApplication "Excel.Application", excelApp
  74.         End If
  75.  
  76.         WScript.Sleep 5000
  77.     Loop
  78. End If
Advertisement
Add Comment
Please, Sign In to add comment