new-site/docserver/fix_dcom.bat
justin f8cd37ac8c Initial commit — Performance West telecom compliance platform
Includes: API (Express/TypeScript), Astro site, Python workers,
document generators, FCC compliance tools, Canada CRTC formation,
Ansible infrastructure, and deployment scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 06:54:22 -05:00

53 lines
2.3 KiB
Batchfile

@echo off
REM ============================================================
REM Fix Word COM for Session 0 (services/Task Scheduler)
REM
REM Problem: Word COM fails with 'NoneType' when run from
REM Task Scheduler "Run whether user is logged on or not"
REM because Session 0 has no interactive desktop.
REM
REM Solution: Configure DCOM to launch Word under the 'justin'
REM user context regardless of which session requests it.
REM This is the standard fix for Office COM automation from
REM Windows Services and Task Scheduler.
REM
REM Run this script ONCE as Administrator.
REM ============================================================
echo.
echo [1/4] Creating Desktop folders for SYSTEM and SysWOW64...
mkdir "C:\Windows\System32\config\systemprofile\Desktop" 2>nul
mkdir "C:\Windows\SysWOW64\config\systemprofile\Desktop" 2>nul
echo Done.
echo.
echo [2/4] Configuring Word DCOM to run as 'justin'...
REM Word 16.0 (Office 365) CLSID: {000209FF-0000-0000-C000-000000000046}
REM This sets the "RunAs" identity for the Word COM server
reg add "HKLM\SOFTWARE\Classes\AppID\{000209FF-0000-0000-C000-000000000046}" /v RunAs /t REG_SZ /d ".\justin" /f
reg add "HKLM\SOFTWARE\Classes\AppID\{000209FF-0000-0000-C000-000000000046}" /v RunAsPassword /t REG_SZ /d "H73g1tKGE3#Aakf" /f
echo Done.
echo.
echo [3/4] Setting DCOM default launch/access permissions...
REM Grant SYSTEM and justin full DCOM access
REM (This uses dcomcnfg equivalent registry settings)
REM The default permissions are usually sufficient, but we ensure
REM the AppID is registered for Word
reg add "HKLM\SOFTWARE\Classes\AppID\WINWORD.EXE" /v AppID /t REG_SZ /d "{000209FF-0000-0000-C000-000000000046}" /f
echo Done.
echo.
echo [4/4] Recreating Task Scheduler task as ONSTART/SYSTEM...
schtasks /delete /tn PW-DocserverWorker /f 2>nul
schtasks /create /tn PW-DocserverWorker /tr "cmd.exe /c C:\docserver\start_worker.bat" /sc ONSTART /ru SYSTEM /rl HIGHEST /f
echo Done.
echo.
echo ============================================================
echo DCOM fix applied. Word COM should now work from Session 0.
echo The task will run as SYSTEM at startup, but Word will launch
echo under the 'justin' user context via DCOM RunAs configuration.
echo.
echo Reboot to test: shutdown /r /t 5
echo ============================================================