명령줄을 통해 프로그램 시작(아직 실행되지 않은 경우에만)

명령줄을 통해 프로그램 시작(아직 실행되지 않은 경우에만)

아래 배치 파일을 생각해 냈는데 훌륭하게 작동합니다. 하지만 프로그램이 이미 실행 중인 경우 해당 프로그램을 건너뛰고 다음 프로그램을 시작하도록 코딩하는 방법이 있는지 알고 싶습니다. 이것이 의미가 있기를 바랍니다. 어떤 조언이라도 대단히 감사하겠습니다.

@echo off    
pushd    
start "" cmd /c cscript "C:\Users\User\Desktop\Work.vbs"    
start "C:\Program Files\Microsoft Office\Office15" Outlook.exe    
start "C:\Program Files\Microsoft Office\Office15" Lync.exe    
start "C:\Program Files (x86)\Google\Chrome\Application" chrome.exe    
runas /savecred /user:"DOMAIN\User_Adm" "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe"    
runas /savecred /user:"DOMAIN\User_Adm" "mmc.exe \"My_Tools.msc\"

답변1

다음은 사용 예입니다.작업 목록특정 이름에 대해 실행 중인 모든 응용 프로그램을 확인합니다.
그렇지 않으면 프로그램이 시작됩니다. 나는 당신이 그것을 당신의 필요에 맞게 조정할 수 있다고 확신합니다

tasklist /nh /fi "imagename eq notepad.exe" | find /i "notepad.exe" > nul || (start notepad.exe)

답변2

내 스크립트에 작업 목록을 구현했는데 매력적으로 작동했습니다.
나와 같은 질문을 갖고 있는 다른 사람을 위해 여기에 있습니다.

@echo off
pushd
tasklist /nh /fi "imagename eq iexplore.exe" | find /i "iexplore.exe" > nul ||(start Work.vbs)
tasklist /nh /fi "imagename eq outlook.exe" | find /i "outlook.exe" > nul ||(start outlook.exe)
tasklist /nh /fi "imagename eq lync.exe" | find /i "lync.exe" > nul ||(start lync.exe)
tasklist /nh /fi "imagename eq chrome.exe" | find /i "chrome.exe" > nul ||(start chrome.exe)
tasklist /nh /fi "imagename eq VpxClient.exe" | find /i "VpxClient.exe" > nul || runas /savecred /user:"DOMAIN\User_Adm" "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe"
tasklist /nh /fi "imagename eq mmc.exe" | find /i "mmc.exe" > nul || runas /savecred /user:"DOMAIN\User_Adm" "mmc.exe \"My_Tools.msc\"

답변3

@echo off      
tasklist /FI "IMAGENAME eq outlook.exe" | find /i "outlook.exe"      

IF ERRORLEVEL 2 GOTO LOOP2
IF ERRORLEVEL 1 GOTO LOOP1 

:LOOP1 
  start notepad.exe
goto EXIT     

:LOOP1 
  start outlook.exe 
goto EXIT 

:EXIT

답변4

나는 nixda의 답변을 따랐는데 훌륭하게 작동했지만 내 신청서의 여러 사본이 여전히 시작되는 문제가 있었습니다!!

이는 내 .exe 이름의 길이 때문이므로 다른 사람들도 동일한 문제가 발생할 경우를 대비해 여기에 nixda의 답변을 수정한 버전을 추가할 것이라고 생각했습니다.

.exe 이름이 "SomeReallyVerySuperLongProgram.exe"와 같이 긴 경우 tasklist는 출력을 자릅니다. 즉, 출력을 find 명령으로 파이프하면 실패하고 애플리케이션의 두 번째 인스턴스가 열립니다.

예를 들어:

여기에 이미지 설명을 입력하세요

그래서 tasklist를 사용하는 대신 wmic 명령을 사용하여 프로세스가 이미 실행 중인지 확인했습니다.

내 조정된 버전은 다음과 같습니다.

wmic process where "name='win32calc.exe'" get ProcessID | find /i "ProcessId" > nul || (start /min win32calc.exe)

관련 정보