
프로그램이 실행 중인지 감지하고 그렇지 않은 경우 프로그램을 시작하는 간단한 powershell 스크립트가 있습니다. 스크립트를 마우스 오른쪽 버튼으로 클릭하고 "PowerShell로 실행"하면 제대로 작동하지만 .ps1의 기본 프로그램을 powershell로 변경하고 두 번 클릭하면 작동하지 않습니다. 또한 작업 스케줄러에서는 작동하지 않습니다. 참고로 내 스크립트는 다음과 같습니다.
$filebound = get-process FileBound.Enterprise.ChainEditor -ErrorAction SilentlyContinue
if($filebound -eq $null)
{
start-process -filepath "C:\Program Files (x86)\FileBound\Importer Professional\FileBound.Enterprise.ChainEditor.exe"
}
작업 스케줄러에서 작업을 실행하기 위해 작업을 인수하는 적절한 방법을 찾을 수 없습니다. 작업을 실행하면 Power Shell 화면이 나타났다가 사라지지만 응용 프로그램이 실행되지 않습니다(두 번 클릭과 동일한 동작).
내 작업 정보는 다음과 같습니다.
Run only when user is logged in and run with highest priveleges checked. Configured for Windows 10 (it's a windows 10 vm).
Triggers at startup and repeats every 30 minutes indefinitely. Enabled is checked
Actions starts a program (powershell)
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
with argument (stolen from someone else) -command "& C:\Filebound\Test.ps1" -NonInteractive
Only Condition checked is Wake computer to run task.
Settings are Allow Task to run on demand and Run task as soon as possible are checked.
도움을 주시면 감사하겠습니다.
답변1
그것을 알아 냈습니다. 작업 스케줄러의 인수와 관련이 있습니다. 일단 설정하면 -ExecutionPolicy Bypass C:\Filebound\Test.ps1
모든 것이 작동했습니다.
참고로, 작업을 보다 안정적으로 만들기 위해 "시작 시" 대신 "컴퓨터가 유휴 상태일 때"를 트리거로 조정해야 했습니다.
답변2
-ExecutionPolicy Bypass
PowerShell을 사용하여 실행 정책을 무제한으로 설정하면 ps1 스크립트를 실행해야 할 때마다 매개변수를 지정할 필요가 없습니다 .
PowerShell을 열 수 있지만 이 방법을 사용하려면 관리자 권한이 필요합니다. 이를 사용하여 관리자 권한 PowerShell을 엽니다.
Win+ R→유형 PowerShell
→ Ctrl+ Shift+Enter
그런 다음 이를 PowerShell 창에 붙여넣습니다.
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell" -ErrorAction SilentlyContinue | Out-Null
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell" -Name EnableScripts -Type DWord -Value 1
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell" -Name ExecutionPolicy -Type String -Value Unrestricted
그러면 스크립트를 실행하기 위해 실행 정책을 우회할 필요가 없습니다.
이는 다음 그룹 정책을 변경하는 것과 같습니다.
Win+ R→유형 gpedit.msc
→Enter
로 이동:
"Local Computer Policy"→"Computer Configuration"→"Administrative Templates"→"Windows Components"→"Windows PowerShell"
왼쪽 패널에서 "Windows PowerShell"을 클릭합니다.
오른쪽에서 "스크립트 실행 켜기"를 두 번 클릭하고 "사용"을 클릭한 다음 "실행 정책" 드롭다운 목록에서 "모든 스크립트 허용"을 선택하고 을 클릭한 Apply다음 을 클릭합니다 OK.