Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' This script ensures Microsoft Word and Excel are always running.
- ' It targets PCs with Windows build 26100 or higher (Win 11 24H2) and 32-bit Microsoft Office.
- ' 1. GetWindowsBuild: Reads the Windows build number from the registry. Returns the build as an integer or 0 if invalid.
- ' 2. IsOffice32BitInstalled: Checks if 32-bit Office is installed by looking for a registry key. Returns True or False.
- ' 3. IsProcessRunning: Uses WMI to verify if a specified process (e.g., Word or Excel) is running. Returns True or False.
- ' 4. LaunchApplication: Starts Word or Excel using their ProgID if not already active and sets them to run invisibly.
- ' Main Logic:
- ' - Verifies Windows build and Office installation.
- ' - If criteria are met, it monitors and launches Word and Excel if needed, checking every 5 seconds.
- '
- Function GetWindowsBuild()
- On Error Resume Next
- Dim objShell, build
- Set objShell = CreateObject("WScript.Shell")
- build = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentBuild")
- If IsNumeric(build) Then
- GetWindowsBuild = CInt(build)
- Else
- GetWindowsBuild = 0
- End If
- On Error GoTo 0
- End Function
- Function IsOffice32BitInstalled()
- On Error Resume Next
- Dim objShell, path
- Set objShell = CreateObject("WScript.Shell")
- path = objShell.RegRead("HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Common\InstallRoot\Path")
- If path <> "" Then
- IsOffice32BitInstalled = True
- Else
- IsOffice32BitInstalled = False
- End If
- On Error GoTo 0
- End Function
- Function IsProcessRunning(appName)
- On Error Resume Next
- Dim objWMI, processes
- Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
- Set processes = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & appName & "'")
- IsProcessRunning = (Not processes Is Nothing And processes.Count > 0)
- On Error GoTo 0
- End Function
- Sub LaunchApplication(progID, ByRef appObject)
- On Error Resume Next
- If appObject Is Nothing Then
- Set appObject = CreateObject(progID)
- If appObject Is Nothing Then
- Exit Sub
- End If
- appObject.Visible = False
- End If
- On Error GoTo 0
- End Sub
- Dim windowsBuild, isOffice32Bit, wordApp, excelApp
- windowsBuild = GetWindowsBuild()
- isOffice32Bit = IsOffice32BitInstalled()
- If windowsBuild >= 26100 And isOffice32Bit Then
- Do
- If Not IsProcessRunning("WINWORD.EXE") Then
- Set wordApp = Nothing
- LaunchApplication "Word.Application", wordApp
- End If
- If Not IsProcessRunning("EXCEL.EXE") Then
- Set excelApp = Nothing
- LaunchApplication "Excel.Application", excelApp
- End If
- WScript.Sleep 5000
- Loop
- End If
Advertisement
Add Comment
Please, Sign In to add comment