### 조건 1. 큰 따옴표로 둘러쌓이지 않고 경로 내에 공백이 존재하는 `ImagePath` 속성을 가진 서비스 2. 공백이 존재하는 서비스 경로 디렉토리에 파일 쓰기 권한이 있어야 함. 3. 서비스를 재시작하거나 호스트를 재시작할 권한이 있어야 함. `ImagePath` 속성을 가진 서비스가 있는지 확인 ```powershell # PowerShell Get-WmiObject Win32_Service | Where-Object { $_.StartMode -eq 'Auto' -and $_.PathName -notlike 'C:\\Windows\\*' -and $_.PathName -notmatch '^\\s*\\".*\\".* } | Select-Object Name, DisplayName, PathName, StartMode # CMD # 서비스 설정 확인 # CMD sc qc "Service Name" # PowerShell sc.exe qc "Service Name" ``` 만약 파일 경로가 `C:\\opt\\Hello World\\hello.exe` 라면 `C:\\opt` 디렉토리에 현재 유저가 쓰기 권한이 있는지 확인해야 한다. - `icacls` Built-in - `accesschk.exe` Sysinternals Suite ```powershell # icacls icacls C:\\opt # get-acl Get-Acl "C:\opt" | Format-List # accesschk.exe accesschk.exe -q -d C:\\opt\\accepteula ``` 실제로 서비스를 재시작하지 않고 재시작이 가능한지 확인 ```powershell try { Restart-Service -Name <Service> -WhatIf echo "You have permission to restart the service" } catch { echo "You do not have permission to restart the service" } try { Restart-Service -Name <Service> -WhatIf; echo "You have permission to restart the service" } catch { "You do not have permission to restart the service" } ``` 서비스 재시작 ```powershell Restart-Service -Name <Service> # OR sc stop "Service Name" sc start "Service Name" ```