Event triggered task

saik0

New member
Local time
2:49 AM
Messages
20
I'm trying to evoke a certain script once an event occurs, using the Scheduled Tasks in W7 x64 with event triggering. The script copies a certain file from the USB stick to the HDD.
To be precise, the script should run upon specific USB stick is plugged in.

So far i only see the DriverFrameworks-UserMode events in the event viewer where the precise ID of the USB stick can be seen (<UMDFHostDeviceRequest instance="<str>" ... >)
What I also need is to see what drive letter is assigned upon "mount" operation.
I should be able to read somewhere what drive letter is assigned and perform a copy operation such as (e.g. using a .bat script):
Code:
xcopy <drive_letter>:\file.txt C:\some_dir\
Can this be done?
I know autorun is ignored with win7 so that isn't an option.
Perhaps there's a better method..? Also i'd like to use only availlable tools without installing additional automation software.
If possible i'd like to avoid having to define a fixed drive letter assignment.

Thanks in advance
 

My Computer

OS
Microsoft Windows 7 (x64)
CPU
Intel Pentium 4 3.6Ghz (Prescott)
Motherboard
Gigabyte GA-8I955X Pro
Memory
2x1GB OCZ
Graphics Card(s)
Nvidia 7950GT
Sound Card
Realtek ALC882
Screen Resolution
1280*1024
Hard Drives
ST3250824AS
ST3500630NS
ST380815AS
PSU
Chieftec 500W
Case
Chieftec CX-04B-B-A
Cooling
Zalman 7700-CU
Keyboard
Logitech UltraX Cordless
Mouse
Logitech 1000MX
So far I managed to compare the GUID of the partition and detect the assigned drive letter using a powershell script that is triggered upon PnP event:

Code:
$DriveLetter = ""
$ObjFile1 = ""
$ObjFile2 = ""
$File1Path = ""
$File2Path = ""
$PartGUID = ""


##### Partition GUID

$PartGUID = "<your partition guid>"

##### Get disk driveletter

Get-WmiObject Win32_Volume | 

foreach {
    if ($_.DeviceID -like "*$PartGUID*") {
        $DriveLetter = $_.DriveLetter
        }
    
}
if ($DriveLetter -like ""){
        Write-Host "Partition with GUID not found. Terminating."
        exit
}

##### Paths

$File1Path = $DriveLetter+"\file.ext"
$File2Path = "Some_file.ext"

#####

$ObjFile1 = Get-Item $File1Path

$ChkFile2 = Test-Path $File2Path

##### Copy from disk to Dropbox folder

if ($ChkFile2 -eq $True) {

    $ObjFile2 = Get-Item $File2Path

    #Replace file on Dropbox if older then on disk
    if ($ObjFile1.LastWriteTime -gt $ObjFile2.LastWriteTime) { 
        Write-Host "Older file exists, copying newer file..."
        Copy-Item $File1Path $File2Path
        Write-Host "Done."
        exit

    }
    else {Write-Host "File already at newest change."
        exit
    }
    
}

else {
    Write-Host "File doesn't exist in the Dropbox folder, copying new file..."
    Copy-Item $File1Path $File2Path
    Write-Host "Done."
    exit
}
Problem is, the script is executed whenever a mass storage device is plugged in.
Is it possible to somehow make task scheduler filter the event contents and trigger the script only for a specific drive?
 

My Computer

OS
Microsoft Windows 7 (x64)
CPU
Intel Pentium 4 3.6Ghz (Prescott)
Motherboard
Gigabyte GA-8I955X Pro
Memory
2x1GB OCZ
Graphics Card(s)
Nvidia 7950GT
Sound Card
Realtek ALC882
Screen Resolution
1280*1024
Hard Drives
ST3250824AS
ST3500630NS
ST380815AS
PSU
Chieftec 500W
Case
Chieftec CX-04B-B-A
Cooling
Zalman 7700-CU
Keyboard
Logitech UltraX Cordless
Mouse
Logitech 1000MX
Back
Top