Thank you abs0lut3z33r0 for that info, after researching the issue I became very aware of this. However I found something that might be useful to others trying to do this.
I was able to go in to the windows powershell and create my own task.
Goto: Start>Accessories>Windows PowerShell> Windows PowerShell ISE (x86).
Copy & Paste:
3. #Requires -version 2.0
4. Register-WmiEvent -Class win32_VolumeChangeEvent -SourceIdentifier volumeChange
5. write-host (get-date -format s) " Beginning script..."
6. do{
7. $newEvent = Wait-Event -SourceIdentifier volumeChange
8. $eventType = $newEvent.SourceEventArgs.NewEvent.EventType
9. $eventTypeName = switch($eventType)
10. {
11. 1 {"Configuration changed"}
12. 2 {"Device arrival"}
13. 3 {"Device removal"}
14. 4 {"docking"}
15. }
16. write-host (get-date -format s) " Event detected = " $eventTypeName
17. if ($eventType -eq 2)
18. {
19. $driveLetter = $newEvent.SourceEventArgs.NewEvent.DriveName
20. $driveLabel = ([wmi]"Win32_LogicalDisk='$driveLetter'").VolumeName
21. write-host (get-date -format s) " Drive name = " $driveLetter
22. write-host (get-date -format s) " Drive label = " $driveLabel
23. # Execute process if drive matches specified condition(s)
24. if ($driveLetter -eq 'H:' -and $driveLabel -eq 'Mirror')
25. {
26. write-host (get-date -format s) " Starting task in 3 seconds..."
27. start-sleep -seconds 3
28. start-process "H:\file.bat"
29. }
30. }
31. Remove-Event -SourceIdentifier volumeChange
32. } while (1-eq1) #Loop until next event
33. Unregister-Event -SourceIdentifier volumeChange
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 'H:' -and $driveLabel -eq 'Mirror')
My usb hard drive named 'Mirror' is set as the H: drive. You could just use if ($driveLabel -eq 'MyDiskLabel') if you didn't care about the letter.
- start-process "Z:\file.bat"
Path of whatever task you want to do. In my example, I have created a batch file on my USB drive which start backup tasks command lines.
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 "C:\Backup script.ps1"
I can’t take credit for this because I found it on a Google search. But like I always tell my friends, “I don’t have all the answers but I know where to find them”
I am having a few bugs with this scrip so Its not yet working @ 100%. I will keep you updated as I progress.