Skip to content

Command‐Line Parameters

Calvindd2f edited this page Jan 14, 2026 · 1 revision

Command-Line Parameters

Relevant source files

The following files were used as context for generating this wiki page:

Purpose and Scope

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.


Parameter Categories

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:


Parameter Parsing Flow

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
Loading

Sources:


Execution Mode Parameters

/DetectOnly (alias: /Preview)

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 = true flag
  • 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:

Sources:


/Quiet (alias: /Q)

Syntax: OfficeScrubC2R.ps1 /Quiet

Purpose: Enables silent execution with no user interface or prompts.

Behavior:

  • Sets fQuiet = true flag (default is already true in direct_conversion.cs:441)
  • Suppresses console output unless running under CScript
  • Disables user prompts for process termination warnings
  • MSI uninstall operations use /q flag instead of /qb-!
  • ODT uninstall XML sets <Display Level="None" />
  • Reboot prompts are suppressed
  • Prevents relaunch as CScript if started with WScript

Code References:

Sources:


Resource Preservation Parameters

/KeepLicense (alias: /KL)

Syntax: OfficeScrubC2R.ps1 /KeepLicense

Purpose: Prevents removal of Office licenses and activation data.

Behavior:

  • Sets fKeepLicense = true flag
  • 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:

Sources:


Logging Parameters

/Log [path] (alias: /L [path])

Syntax: OfficeScrubC2R.ps1 /Log "C:\CustomPath"

Purpose: Specifies a custom directory for log file output.

Behavior:

  • Sets sLogDir to 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:

Sources:


Advanced Options

/NoCancel (alias: /N)

Syntax: OfficeScrubC2R.ps1 /NoCancel

Purpose: Removes cancel buttons from Setup.exe and Msiexec.exe dialogs.

Behavior:

  • Sets fNoCancel = true flag
  • Affects MSI uninstall command-line construction
  • Primarily used in automated deployment scenarios

Code References:

Sources:


/SkipSD (aliases: /S, /SkipShortcutDetection)

Syntax: OfficeScrubC2R.ps1 /SkipSD

Purpose: Skips shortcut detection and cleanup in user profile directories.

Behavior:

  • Sets fSkipSD = true flag
  • 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:

Sources:


/Offline (alias: /ForceOffline)

Syntax: OfficeScrubC2R.ps1 /Offline

Purpose: Forces offline mode, preventing downloads of Office Deployment Tool.

Behavior:

  • Sets fOffline = true flag
  • 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:

Sources:


Parameter Interaction with Execution Stages

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
Loading

Sources:


Internal and Testing Parameters

/NoElevate (alias: /NE)

Syntax: OfficeScrubC2R.ps1 /NoElevate

Purpose: Prevents automatic elevation attempt when insufficient permissions are detected.

Behavior:

  • Sets fNoElevate = true flag
  • Script exits with ERROR_ELEVATION if registry permissions are insufficient
  • Used internally during elevation attempts to prevent infinite relaunch loops
  • Not intended for end-user scenarios

Code References:

Sources:


/ReturnErrorOrSuccess (aliases: /RetErrorSuccess, /REOS)

Syntax: OfficeScrubC2R.ps1 /ReturnErrorOrSuccess

Purpose: Simplifies return code to binary success (0) or failure (non-zero).

Behavior:

  • Sets fReturnErrorOrSuccess = true flag
  • 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:

Sources:


/ForceArpUninstall

Syntax: OfficeScrubC2R.ps1 /ForceArpUninstall

Purpose: Forces use of ARP (Add/Remove Programs) uninstall command instead of ODT.

Behavior:

  • Sets fForceArpUninstall = true flag
  • Skips ODT-based uninstall attempts
  • Falls back directly to cached sArpUninstallCmd from registry
  • Used for testing or when ODT uninstall is known to fail

Code References:

Sources:


/TestRerun (alias: /TR)

Syntax: OfficeScrubC2R.ps1 /TestRerun

Purpose: Testing parameter to simulate reboot requirement scenario.

Behavior:

  • Sets fTestRerun = true flag
  • Forces fRebootRequired = true and sets ERROR_REBOOT_REQUIRED bit
  • Triggers Rerun() logic for testing post-reboot cleanup behavior
  • Not for production use - documented only for testing purposes

Code References:

Sources:


Common Parameter Combinations

Detection and Assessment

# 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

Complete Removal Scenarios

# 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

Enterprise Deployment Scenarios

# 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:


Parameter Validation and Error Handling

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
Loading

Notes on Error Handling:

  • Invalid switches are silently ignored (no error thrown)
  • Missing path for /Log falls 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:


Boolean Flags Summary Table

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:


Help and Syntax Display

/? (aliases: -?, /?)

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:

Sources:

Clone this wiki locally