Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Event triggered task

11 Oct 2011   #1
saik0

Microsoft Windows 7 (x64)
 
 
Event triggered task

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 System SpecsSystem Spec
18 Oct 2011   #2
saik0

Microsoft Windows 7 (x64)
 
 

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 System SpecsSystem Spec
Reply

 Event triggered task




Thread Tools





Similar help and support threads
Thread Forum
How to delete a Task Event Notification
I had a lot of WHEA error problems so I set up a Task (Attach Task to Event) to give me a notification message whenever one occurred. I've since replaced the motherboard (and fixed the WHEA errors). I would now like to delete that notification task but don't know how.
Performance & Maintenance
Kernel power event 41, task 63
In the past few months, my Toshiba Satellite L675-S7048, began to reboot on its own. No BSOD at all. After looking at a few postings on the subject and looking at my machine, I determined that it was a kernel power event. I turned on logging, waited for another crash and have collected the log...
BSOD Help and Support
Run scheduled task or a GPO when Win7 SleepMode is triggered?
Hello all, I'd like to launch a custom batch file when my computer goes into sleep mode. I would like to launch this batch through a GPO or task scheduler. I've tested using task scheduler and the power event ID for sleep mode but it seems the event triggers too late for the application to run...
General Discussion
Windows dialog event sounds not triggered
Hello all, I have been searching the internet of a while about my problem, but unfortunately I still did not find anything related to the issues I am having. The problem is quite a strange one, I tried finding the cause and a solution by myself but I just cannot find a possible cause at all. ...
Performance & Maintenance
event id 41 task category 63
...hi...im having problems with my laptop(Acer Aspire 4741) windows 7 ultimate 32 bit...it freezes everytime i connect to internet using my usb modem...ive tried other usb modem but its still the same...it freezes...when i watch movie it also freezes...what causes these???please help me...tnx!!!
BSOD Help and Support
Power Kernal Event 41 task 63
This thing was idle overnight and i woke up finding it restarted so I checked the event viewer and it gave that id error. It's the second time that this has happened so far. I've tried a lot of forums and got no answer at all for this, seems like it's an unsolvable issue. My computer is barely...
BSOD Help and Support

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 22:38.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App