Repository navigation
Command‐Line Parameters
Relevant source files
The following files were used as context for generating this wiki page:
This page documents all command-line parameters accepted by OfficeScrubC2R, their effects on execution behavior, and how they control the three-stage cleanup pipeline. These parameters provide control over operational modes (interactive vs. silent, detection vs. removal), resource preservation (licenses), execution context (elevation, offline), and logging configuration.
For information about the actual execution workflow controlled by these parameters, see Three-Stage Execution Pipeline. For details on operational modes and use cases, see Operational Modes and Use Cases and Examples.
OfficeScrubC2R accepts command-line switches that control behavior across five categories:
| Category | Parameters | Purpose |
|---|---|---|
| Execution Mode |
/DetectOnly, /Preview, /Quiet, /Q
|
Control whether removal occurs and UI visibility |
| Resource Preservation |
/KeepLicense, /KL
|
Prevent deletion of Office licenses |
| Logging |
/Log [path], /L [path]
|
Specify custom log file location |
| Advanced Options |
/NoCancel, /N, /SkipSD, /S, /Offline, /ForceOffline
|
Control specific behaviors |
| Internal/Testing |
/NoElevate, /NE, /ReturnErrorOrSuccess, /ForceArpUninstall, /TestRerun
|
For testing and wrapper scenarios |
Sources:
flowchart TD
Start[Script Entry] --> Init[Initialize Default Values]
Init --> Parse[ParseCmdLine Function]
Parse --> CheckArgs{Arguments<br/>Provided?}
CheckArgs -->|No| SetDefaults[Set sArg0 = ALL]
CheckArgs -->|Yes| GetArgs[Get Environment.GetCommandLineArgs]
GetArgs --> LoopArgs[Iterate Arguments]
SetDefaults --> CreateLog[CreateLog]
LoopArgs --> CheckSwitch{Switch Type?}
CheckSwitch -->|/?| ShowSyntax[ShowSyntax<br/>Exit]
CheckSwitch -->|/DETECTONLY| SetDetect["fDetectOnly = true"]
CheckSwitch -->|/QUIET| SetQuiet["fQuiet = true"]
CheckSwitch -->|/KEEPLICENSE| SetKeepLic["fKeepLicense = true"]
CheckSwitch -->|/LOG| SetLogDir["sLogDir = args[i+1]"]
CheckSwitch -->|/NOCANCEL| SetNoCancel["fNoCancel = true"]
CheckSwitch -->|/OFFLINE| SetOffline["fOffline = true"]
CheckSwitch -->|/SKIPSD| SetSkipSD["fSkipSD = true"]
CheckSwitch -->|/NOELEVATE| SetNoElevate["fNoElevate = true"]
CheckSwitch -->|/RETERRORSUCCESS| SetRetErrSuc["fReturnErrorOrSuccess = true"]
CheckSwitch -->|/FORCEARPUNINSTALL| SetForceArp["fForceArpUninstall = true"]
CheckSwitch -->|/TESTRERUN| SetTestRerun["fTestRerun = true"]
SetDetect --> NextArg
SetQuiet --> NextArg
SetKeepLic --> NextArg
SetLogDir --> NextArg
SetNoCancel --> NextArg
SetOffline --> NextArg
SetSkipSD --> NextArg
SetNoElevate --> NextArg
SetRetErrSuc --> NextArg
SetForceArp --> NextArg
SetTestRerun --> NextArg
NextArg{More Args?}
NextArg -->|Yes| LoopArgs
NextArg -->|No| CreateLog
CreateLog --> LogArgs["LogH2: Arguments"]
LogArgs --> Continue[Continue Execution]
style SetDetect fill:#fff4e1
style SetQuiet fill:#fff4e1
style SetKeepLic fill:#ffe1e1
style SetLogDir fill:#e1ffe1
Sources:
Syntax: OfficeScrubC2R.ps1 /DetectOnly
Purpose: Enables detection-only mode where the script identifies installed Office Click-to-Run products but performs no removal operations.
Behavior:
- Sets
fDetectOnly = trueflag - Detection phase (Stage 0) executes normally
- All removal operations (
DeleteFile,DeleteDirectory,RegDeleteKey, etc.) are skipped - Log output shows "Preview mode. Disallowing delete..." messages
- Useful for assessment before actual cleanup
Code References:
- Flag set: direct_conversion.cs:760-762
- Checked before deletion: direct_conversion.cs:1599, direct_conversion.cs:1701, direct_conversion.cs:3962
Sources:
Syntax: OfficeScrubC2R.ps1 /Quiet
Purpose: Enables silent execution with no user interface or prompts.
Behavior:
- Sets
fQuiet = trueflag (default is alreadytruein direct_conversion.cs:441) - Suppresses console output unless running under CScript
- Disables user prompts for process termination warnings
- MSI uninstall operations use
/qflag instead of/qb-! - ODT uninstall XML sets
<Display Level="None" /> - Reboot prompts are suppressed
- Prevents relaunch as CScript if started with WScript
Code References:
- Flag set: direct_conversion.cs:818-820
- Affects MSI uninstall: direct_conversion.cs:1689-1696
- Affects ODT XML: direct_conversion.cs:1749-1761
- Affects reboot prompt: direct_conversion.cs:378-411
Sources:
Syntax: OfficeScrubC2R.ps1 /KeepLicense
Purpose: Prevents removal of Office licenses and activation data.
Behavior:
- Sets
fKeepLicense = trueflag - Skips OSPP (Office Software Protection Platform) license cleanup
- Skips vNext license cache cleanup (
%localappdata%\Microsoft\Office\Licenses) - License cleanup operations in Stage 1 are bypassed
- Useful when migrating Office versions but preserving activation
Code References:
- Flag set: direct_conversion.cs:768-771
- OSPP cleanup check: direct_conversion.cs:238-242
- vNext cleanup check: direct_conversion.cs:246-249
Sources:
Syntax: OfficeScrubC2R.ps1 /Log "C:\CustomPath"
Purpose: Specifies a custom directory for log file output.
Behavior:
- Sets
sLogDirto provided path - If path doesn't exist, attempts to create it
- Falls back to
sScrubDir(%temp%\OfficeScrubC2R) if creation fails - Log filename format:
{ComputerName}_{DateTime}_ScrubLog.txt - Default location without this parameter:
%temp%\OfficeScrubC2R
Code References:
- Flag processing: direct_conversion.cs:773-795
- Log creation: direct_conversion.cs:3535-3566
Sources:
Syntax: OfficeScrubC2R.ps1 /NoCancel
Purpose: Removes cancel buttons from Setup.exe and Msiexec.exe dialogs.
Behavior:
- Sets
fNoCancel = trueflag - Affects MSI uninstall command-line construction
- Primarily used in automated deployment scenarios
Code References:
- Flag set: direct_conversion.cs:797-800
- Initial default: direct_conversion.cs:438
Sources:
Syntax: OfficeScrubC2R.ps1 /SkipSD
Purpose: Skips shortcut detection and cleanup in user profile directories.
Behavior:
- Sets
fSkipSD = trueflag - Early return in
CleanShortcuts()function - Significantly reduces execution time by avoiding recursive directory scans
- User shortcuts remain intact but may point to removed Office installations
Code References:
- Flag set: direct_conversion.cs:827-832
- Early return check: direct_conversion.cs:2665
Sources:
Syntax: OfficeScrubC2R.ps1 /Offline
Purpose: Forces offline mode, preventing downloads of Office Deployment Tool.
Behavior:
- Sets
fOffline = trueflag - Disables
HttpDownloadFile()operations for ODT - Falls back to pre-bundled ODT executables or ARP uninstall command
- Essential for disconnected environments or restrictive network policies
Code References:
- Flag set: direct_conversion.cs:806-810
- Download check: direct_conversion.cs:1856
Sources:
flowchart LR
subgraph "Parameters"
P1["/DetectOnly"]
P2["/KeepLicense"]
P3["/Quiet"]
P4["/SkipSD"]
P5["/Offline"]
P6["/Log"]
end
subgraph "Stage 0: Detection"
S0[FindInstalledOProducts<br/>EnsureValidWIMetadata]
end
subgraph "Stage 1: Uninstall"
S1A[CleanOSPP]
S1B[ClearVNextLicCache]
S1C[CloseOfficeApps]
S1D[DelSchtasks]
S1E[CleanShortcuts]
S1F[Uninstall<br/>UninstallOfficeC2R]
end
subgraph "Stage 2: Registry Cleanup"
S2[RegWipe<br/>ClearShellIntegrationReg]
end
subgraph "Stage 3: File Cleanup"
S3[FileWipe<br/>DeleteServices<br/>DeleteFolders]
end
P1 -.blocks.-> S1A
P1 -.blocks.-> S1B
P1 -.blocks.-> S1D
P1 -.blocks.-> S1F
P1 -.blocks.-> S2
P1 -.blocks.-> S3
P2 -.blocks.-> S1A
P2 -.blocks.-> S1B
P3 -.modifies.-> S1C
P3 -.modifies.-> S1F
P4 -.blocks.-> S1E
P5 -.modifies.-> S1F
P6 -.affects.-> S0
P6 -.affects.-> S1F
P6 -.affects.-> S2
P6 -.affects.-> S3
S0 --> S1A
S1A --> S1B
S1B --> S1C
S1C --> S1D
S1D --> S1E
S1E --> S1F
S1F --> S2
S2 --> S3
Sources:
Syntax: OfficeScrubC2R.ps1 /NoElevate
Purpose: Prevents automatic elevation attempt when insufficient permissions are detected.
Behavior:
- Sets
fNoElevate = trueflag - Script exits with
ERROR_ELEVATIONif registry permissions are insufficient - Used internally during elevation attempts to prevent infinite relaunch loops
- Not intended for end-user scenarios
Code References:
- Flag set: direct_conversion.cs:802-805
- Permission check: direct_conversion.cs:575-592
Sources:
Syntax: OfficeScrubC2R.ps1 /ReturnErrorOrSuccess
Purpose: Simplifies return code to binary success (0) or failure (non-zero).
Behavior:
- Sets
fReturnErrorOrSuccess = trueflag - Default behavior returns detailed error bitmask (see Constants and Error Codes)
- With this flag, script evaluates all error bits and returns:
-
0(ERROR_SUCCESS) if no critical errors occurred -
1(ERROR_FAIL) if any critical error occurred
-
- Critical errors: USERCANCEL, STAGE2, DCAF_FAILURE, ELEVATION_USERDECLINED, ELEVATION, SCRIPTINIT, RELAUNCH, UNKNOWN
- Non-critical: REBOOT_REQUIRED, INCOMPLETE (both considered success)
Code References:
- Flag set: direct_conversion.cs:822-826
- Return code translation: direct_conversion.cs:351-375
Sources:
Syntax: OfficeScrubC2R.ps1 /ForceArpUninstall
Purpose: Forces use of ARP (Add/Remove Programs) uninstall command instead of ODT.
Behavior:
- Sets
fForceArpUninstall = trueflag - Skips ODT-based uninstall attempts
- Falls back directly to cached
sArpUninstallCmdfrom registry - Used for testing or when ODT uninstall is known to fail
Code References:
- Flag set: direct_conversion.cs:764-766
- ODT skip check: direct_conversion.cs:1841
- ARP fallback: direct_conversion.cs:1903-1929
Sources:
Syntax: OfficeScrubC2R.ps1 /TestRerun
Purpose: Testing parameter to simulate reboot requirement scenario.
Behavior:
- Sets
fTestRerun = trueflag - Forces
fRebootRequired = trueand setsERROR_REBOOT_REQUIREDbit - Triggers
Rerun()logic for testing post-reboot cleanup behavior - Not for production use - documented only for testing purposes
Code References:
- Flag set: direct_conversion.cs:835-838
- Test enforcement: direct_conversion.cs:290-296
Sources:
# Detect installed products without removal
.\OfficeScrubC2R.ps1 /DetectOnly
# Silent detection with custom log location
.\OfficeScrubC2R.ps1 /DetectOnly /Quiet /Log "C:\Logs"
# Preview mode skipping shortcut detection for speed
.\OfficeScrubC2R.ps1 /Preview /SkipSD# Silent removal with license preservation
.\OfficeScrubC2R.ps1 /Quiet /KeepLicense
# Offline silent removal (disconnected environment)
.\OfficeScrubC2R.ps1 /Quiet /Offline /Log "C:\RemovalLogs"
# Removal without user prompts
.\OfficeScrubC2R.ps1 /Quiet /NoCancel# Wrapper-friendly with simplified return code
.\OfficeScrubC2R.ps1 /Quiet /ReturnErrorOrSuccess /Log "\\Server\Logs"
# Fast removal skipping shortcut detection
.\OfficeScrubC2R.ps1 /Quiet /SkipSD /NoCancel
# Offline enterprise removal with all safeguards
.\OfficeScrubC2R.ps1 /Quiet /Offline /NoCancel /Log "C:\DeploymentLogs"Sources:
flowchart TD
Param[Parameter Input] --> Validate{Valid Switch?}
Validate -->|Invalid| Ignore[Silently Ignore]
Validate -->|Valid| Check{Has Value?}
Check -->|No Value Needed| SetFlag[Set Boolean Flag]
Check -->|Needs Value| CheckNext{Next Arg<br/>Available?}
CheckNext -->|Yes| ValidatePath{Valid Path?}
CheckNext -->|No| UseDefault[Use Default Value]
ValidatePath -->|Exists| SetPath[Set Path Variable]
ValidatePath -->|Doesn't Exist| TryCreate[Try Create Directory]
TryCreate -->|Success| SetPath
TryCreate -->|Failure| UseDefault
SetFlag --> Continue[Continue Parsing]
SetPath --> Continue
UseDefault --> Continue
Ignore --> Continue
Continue --> MoreArgs{More<br/>Arguments?}
MoreArgs -->|Yes| Param
MoreArgs -->|No| Initialize[Initialize Execution]
style Validate fill:#fff4e1
style ValidatePath fill:#ffe1e1
style TryCreate fill:#e1ffe1
Notes on Error Handling:
- Invalid switches are silently ignored (no error thrown)
- Missing path for
/Logfalls back to%temp%\OfficeScrubC2R - Case-insensitive parameter matching using
.ToUpper() - Multiple occurrences of same parameter: last one wins
- Boolean flags cannot be "unset" once enabled
Sources:
| Flag Variable | Parameter(s) | Default | Purpose |
|---|---|---|---|
fDetectOnly |
/DetectOnly, /Preview
|
false |
Enable detection-only mode |
fQuiet |
/Quiet, /Q
|
true |
Suppress UI and prompts |
fKeepLicense |
/KeepLicense, /KL
|
false |
Preserve Office licenses |
fNoCancel |
/NoCancel, /N
|
false |
Remove cancel buttons |
fSkipSD |
/SkipSD, /S, /SkipShortcutDetection
|
false |
Skip shortcut detection |
fOffline |
/Offline, /ForceOffline
|
false |
Force offline mode |
fNoElevate |
/NoElevate, /NE
|
false |
Prevent elevation attempt |
fReturnErrorOrSuccess |
/ReturnErrorOrSuccess, /RetErrorSuccess, /REOS
|
false |
Simplify return code |
fForceArpUninstall |
/ForceArpUninstall |
false |
Skip ODT, use ARP |
fTestRerun |
/TestRerun, /TR
|
false |
Test reboot scenario |
Sources:
Syntax: OfficeScrubC2R.ps1 /?
Purpose: Displays script syntax and available parameters.
Behavior:
- Calls
ShowSyntax()function - Outputs parameter descriptions to console
- Exits immediately with return code 0
- No logging or detection performed
Output Format:
OffScrubC2R.vbs V {SCRIPTVERSION}
Copyright (c) Microsoft Corporation. All Rights Reserved
OffScrubC2R.vbs - Remove Office C2R / O365
when a regular uninstall is no longer possible
Usage: OffScrubC2R.vbs
/? ' Displays this help
/Log [LogfolderPath] ' Custom folder for log files
/SkipSD ' Skips the ShortcutDetection in local profiles
/NoCancel ' Setup.exe and Msiexec.exe have no Cancel button
/Quiet ' Script, Setup.exe and Msiexec.exe run quiet with no UI
/ReturnErrorOrSuccess ' Returns 0 for a successful removal. Non-Zero if not.
Code References:
- Function: direct_conversion.cs:850-863
- Call sites: direct_conversion.cs:731, direct_conversion.cs:753-757
Sources: