Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' This script ensures Microsoft Word and Excel (Office 2013) are always running.
- ' It targets PCs with Windows build 26100 or higher (Windows 11 24H2) and 32-bit or 64-bit Microsoft Office 2013.
- ' 1. GetWindowsBuild: Reads the Windows build number from the registry. Returns the build as an integer or 0 if invalid.
- ' 2. IsOffice2013Installed: Checks if Office 2013 is installed by verifying registry keys.
- ' 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 IsOffice2013Installed()
- On Error Resume Next
- Dim objShell, path1, path2
- Set objShell = CreateObject("WScript.Shell")
- path1 = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot\Path")
- path2 = objShell.RegRead("HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\Common\InstallRoot\Path")
- If path1 <> "" Or path2 <> "" Then
- IsOffice2013Installed = True
- Else
- IsOffice2013Installed = 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, isOffice2013, wordApp, excelApp
- windowsBuild = GetWindowsBuild()
- isOffice2013 = IsOffice2013Installed()
- If windowsBuild >= 26100 And isOffice2013 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