USB 장치 연결을 감지하여 예약 된 작업 시작

Gemisigo

Win 7에서 자동 실행 (또는 자동 실행 ??)의 제한으로 인해 연결시 USB 드라이브에서 응용 프로그램을 시작할 수 없다는 논의가있었습니다. 그러나 이벤트 유형 트리거가있는 예약 된 작업을 생성 할 수 있습니다. . 드라이브 또는 USB 장치가 연결될 때 발생하는 이벤트가 있어야합니다.

누구든지 내가 어떤 이벤트 ID를 사용해야하는지 아는 사람이 있습니까? 아니면 적어도 어떤 유형의 이벤트? 이벤트 뷰어에서 이벤트를 어디에서 찾을 수 있습니까?

해리 맥

The thread Task Scheduler: How to automatically synchronize my USB flash drive? has this answer by a user called monotone, which uses PowerShell together with the Task Scheduler :

I had the same question as you, and worked out something with powershell (windows built-in scripting) using techniques from the Scripting Guy Blog here and here. The script runs continuously as a background process, which you can start at system logon with task scheduler. The script will be notified whenever a new drive is plugged and then do something (here you configure the script rather than the task). Since it is basically paused while waiting for the next plugged drive, you should not find it takes up much resources. Here I go:

1) Start Powershell ISE, which can be found in your start menu under Accessories/Windows Powershell. 2) Copy paste the following into Powershell:

#Requires -version 2.0
Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange
write-host (get-date -format s) " Beginning script..."
do{
$newEvent = Wait-Event -SourceIdentifier volumeChange
$eventType = $newEvent.SourceEventArgs.NewEvent.EventType
$eventTypeName = switch($eventType)
{
1 {"Configuration changed"}
2 {"Device arrival"}
3 {"Device removal"}
4 {"docking"}
}
write-host (get-date -format s) " Event detected = " $eventTypeName
if ($eventType -eq 2)
{
$driveLetter = $newEvent.SourceEventArgs.NewEvent.DriveName
$driveLabel = ([wmi]"Win32_LogicalDisk='$driveLetter'").VolumeName
write-host (get-date -format s) " Drive name = " $driveLetter
write-host (get-date -format s) " Drive label = " $driveLabel
# Execute process if drive matches specified condition(s)
if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')
{
write-host (get-date -format s) " Starting task in 3 seconds..."
start-sleep -seconds 3
start-process "Z:\sync.bat"
}
}
Remove-Event -SourceIdentifier volumeChange
} while (1-eq1) #Loop until next event
Unregister-Event -SourceIdentifier volumeChange

3) You need to modify the script above to tell the script what drive to look for, and what to execute. The two lines to change are:

if ($driveLetter -eq 'Z:' -and $driveLabel -eq 'Mirror')

My usb hard drive named 'Mirror' is set as the Z: drive. You could just use if ($driveLabel -eq 'MyDiskLabel') if you didn't care about the letter.

start-process "Z:\sync.bat"

Path of whatever task you want to do. In my example, I have created a batch file on my USB drive which starts 3-4 backup tasks command lines.

4) When you're done, save your script somewhere (extension .ps1), then go create a task in Task Scheduler to have your script run in background. Mine looks like this:

  • Trigger: At log on
  • Action: Start a program
  • Program/script: powershell
  • Add arguments: -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"

5) Voilà!

6) Extra stuff:

스크립트 창을 숨기려면 다음 인수를 사용하십시오.

  • 인수 추가 :
    -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1"

스크립트 메시지를 로그 파일로 출력하려면 (스크립트가 시작될 때마다 즉 로그온 할 때마다 덮어 쓰기 됨) 다음 작업을 사용하십시오.

  • 프로그램 / 스크립트 : cmd
  • 인수 추가 :
    /c powershell -WindowStyle Hidden -ExecutionPolicy Unrestricted -File "D:\Stuff\Backup script.ps1" > "D:\Stuff\scriptlog.txt "

숨겨진 스크립트 실행을 종료하려면 작업 관리자에서 "Powershell"프로세스를 종료 할 수 있습니다.

유일한 단점은 드라이브가 이미 연결된 상태에서 컴퓨터를 부팅 할 때 아무것도 실행되지 않는다는 것입니다. (처음에 첫 번째 검사를 수행하도록 스크립트를 변경할 수 있지만 오늘은 충분했습니다!)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

USB 장치 연결을 감지하여 예약 된 작업 시작

분류에서Dev

예약 된 작업이 배치 파일을 열지 않음

분류에서Dev

WiFi 연결시 예약 된 작업이 실행되지 않음 (트리거)

분류에서Dev

배치 파일을 사용하여 예약 된 작업 xml 파일 만들기

분류에서Dev

예약 된 작업은 WebSocket을 작동하지

분류에서Dev

Android : Android AlarmManager가 예약 된 작업을 수행하기 위해 장치를 깨울 수 있습니까?

분류에서Dev

연결된 특정 USB 장치 감지

분류에서Dev

파이썬에서 불일치 봇에 예약 된 작업이 작업을 수행하지 못함

분류에서Dev

Net Use 저장된 자격 증명을 무시하는 Win7 예약 작업

분류에서Dev

배치 파일을 예약 된 작업으로 실행하면 제대로 작동하지 않습니까?

분류에서Dev

Powershell 4.0을 사용하여 예약 된 작업 동작 업데이트

분류에서Dev

예약 된 기간을 기준으로 재고 항목을 예약 해제하는 예약 된 작업 생성

분류에서Dev

예약 된 작업에서 Repository와 연결 OneToMany가 검색되지 않음

분류에서Dev

지금 작업에 예약 된 실행

분류에서Dev

예약 된 작업으로 실행할 때 Excel을 표시하는 방법

분류에서Dev

Quarzt : 작업을 예약하기 전 /하지 않고 JobDataMap 저장

분류에서Dev

토폴로지 정렬을 사용하여 예약 된 작업의 최소 완료 시간 찾기

분류에서Dev

어떻게 @Scheduled 어노테이션을 사용하기 시작했다 예약 된 작업을 중지?

분류에서Dev

예약 된 작업을 수행하는 클러스터 Python 작업자 집합

분류에서Dev

예약 된 작업을 비활성화하는 MarkLogic 기능

분류에서Dev

창없는 예약 된 작업을 실행하는 방법

분류에서Dev

예약 된 작업을 삭제하는 방법

분류에서Dev

예약 된 작업을 삭제하는 방법

분류에서Dev

예약 된 작업을 백번 실행하는 셀러리

분류에서Dev

재시작 후 Quartz에서 예약 된 작업을 유지하는 방법은 무엇입니까?

분류에서Dev

예약 된 작업이 설정된 위치를 찾을 수 없습니다.

분류에서Dev

USB를 통해 연결된 장치를 꺼내는 powershell 명령이 처음에 작동하지 않음

분류에서Dev

Jenkins 예약 된 작업

분류에서Dev

Jenkins 예약 된 작업

Related 관련 기사

  1. 1

    USB 장치 연결을 감지하여 예약 된 작업 시작

  2. 2

    예약 된 작업이 배치 파일을 열지 않음

  3. 3

    WiFi 연결시 예약 된 작업이 실행되지 않음 (트리거)

  4. 4

    배치 파일을 사용하여 예약 된 작업 xml 파일 만들기

  5. 5

    예약 된 작업은 WebSocket을 작동하지

  6. 6

    Android : Android AlarmManager가 예약 된 작업을 수행하기 위해 장치를 깨울 수 있습니까?

  7. 7

    연결된 특정 USB 장치 감지

  8. 8

    파이썬에서 불일치 봇에 예약 된 작업이 작업을 수행하지 못함

  9. 9

    Net Use 저장된 자격 증명을 무시하는 Win7 예약 작업

  10. 10

    배치 파일을 예약 된 작업으로 실행하면 제대로 작동하지 않습니까?

  11. 11

    Powershell 4.0을 사용하여 예약 된 작업 동작 업데이트

  12. 12

    예약 된 기간을 기준으로 재고 항목을 예약 해제하는 예약 된 작업 생성

  13. 13

    예약 된 작업에서 Repository와 연결 OneToMany가 검색되지 않음

  14. 14

    지금 작업에 예약 된 실행

  15. 15

    예약 된 작업으로 실행할 때 Excel을 표시하는 방법

  16. 16

    Quarzt : 작업을 예약하기 전 /하지 않고 JobDataMap 저장

  17. 17

    토폴로지 정렬을 사용하여 예약 된 작업의 최소 완료 시간 찾기

  18. 18

    어떻게 @Scheduled 어노테이션을 사용하기 시작했다 예약 된 작업을 중지?

  19. 19

    예약 된 작업을 수행하는 클러스터 Python 작업자 집합

  20. 20

    예약 된 작업을 비활성화하는 MarkLogic 기능

  21. 21

    창없는 예약 된 작업을 실행하는 방법

  22. 22

    예약 된 작업을 삭제하는 방법

  23. 23

    예약 된 작업을 삭제하는 방법

  24. 24

    예약 된 작업을 백번 실행하는 셀러리

  25. 25

    재시작 후 Quartz에서 예약 된 작업을 유지하는 방법은 무엇입니까?

  26. 26

    예약 된 작업이 설정된 위치를 찾을 수 없습니다.

  27. 27

    USB를 통해 연결된 장치를 꺼내는 powershell 명령이 처음에 작동하지 않음

  28. 28

    Jenkins 예약 된 작업

  29. 29

    Jenkins 예약 된 작업

뜨겁다태그

보관