Skip to content

Instantly share code, notes, and snippets.

@niratama
Created May 18, 2025 16:45
Show Gist options
  • Save niratama/6f5d6b6e87fce35c152b80d9ac3fb6d6 to your computer and use it in GitHub Desktop.
Save niratama/6f5d6b6e87fce35c152b80d9ac3fb6d6 to your computer and use it in GitHub Desktop.
3DxServiceを一時停止したり再開したりするPowerShellスクリプト
<#
.SYNOPSIS
This script manages the 3DxService for 3Dconnexion devices.
.DESCRIPTION
This script checks if the 3DxService is running and can start or stop it based on the provided argument.
.PARAMETER Start
Starts the 3DxService if it is not already running.
.PARAMETER Stop
Stops the 3DxService if it is running.
.PARAMETER Status
Checks the status of the 3DxService and returns whether it is running or not.
.EXAMPLE
.\3dx.ps1 -Start
Starts the 3DxService if it is not already running.
.EXAMPLE
.\3dx.ps1 -Stop
Stops the 3DxService if it is running.
.EXAMPLE
.\3dx.ps1 -Status
Checks the status of the 3DxService and returns whether it is running or not.
#>
param(
[switch]$Help,
[Parameter(ParameterSetName = "Start", Mandatory)]
[switch]$Start,
[Parameter(ParameterSetName = "Stop", Mandatory)]
[switch]$Stop,
[Parameter(ParameterSetName = "Status", Mandatory = $false)]
[switch]$Status
)
$command = "C:\Program Files\3Dconnexion\3DxWare\3DxWinCore\3DxService.exe"
$serviceName = "3DxService"
$proc = Get-Process -Name $serviceName -ErrorAction SilentlyContinue
$showHelp = $false
if ($help) {
$showHelp = $true
} elseif ($Status) {
if ($proc) {
Write-Host "3DxService is already running."
exit
} else {
Write-Host "3DxService is not running."
exit
}
} elseif ($Start) {
if ($proc) {
Write-Host "3DxService is already running."
exit
}
Write-Host "Starting 3DxService..."
Start-Process -FilePath $command
if ($?) {
Write-Host "3DxService started successfully."
} else {
Write-Host "Failed to start 3DxService."
exit
}
} elseif ($Stop) {
if (-not $proc) {
Write-Host "3DxService is not running."
exit
}
Write-Host "Stopping 3DxService..."
Start-Process -Wait -FilePath $command -ArgumentList "-shutdown"
if ($?) {
Write-Host "3DxService stopped successfully."
} else {
Write-Host "Failed to stop 3DxService."
exit
}
} else {
$showHelp = $true
}
if ($showHelp) {
Get-Help -name $MyInvocation.InvocationName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment