PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Registry/Script question
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Registry/Script question

Réponse
 
LinkBack Outils de la discussion
Vieux 15/11/2007, 23h01   #1
pand0ra.usa
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Registry/Script question

Ok, here is the problem. I am looking to have a script file execute
when a usb device is attached to a computer. My problem is how to do
this without doing a scheduled task. Is there a registry key I can use
where I can point to my .bat file (myscript.bat) or is there a way to
script this to monitor the usb (I'm guessing this is more difficult)?
  Réponse avec citation
Vieux 20/11/2007, 18h01   #2
\RemS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Registry/Script question

"pand0ra.usa" wrote:

> Ok, here is the problem. I am looking to have a script file execute
> when a usb device is attached to a computer. My problem is how to do
> this without doing a scheduled task. Is there a registry key I can use
> where I can point to my .bat file (myscript.bat) or is there a way to
> script this to monitor the usb (I'm guessing this is more difficult)?
>


Here is a simple script in vbs (save as a *.vbs file) that monitors for new
attachted usb-devices.
For testing this script has a 'timeout' and will close the monitor after 2
minutes.
You can later on disable the 'timeout' and run this script as a logonscript.
Now a popup is showed when a device is attached, you can make that a program
to run..
The filter is "USB\" so it reacts for every usb device, but you can change
that.

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
intTimeOut = 3 ' in minutes

strComputer = "."
Set objSWbemServices = _
GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objSWbemEventSource = objSWbemServices.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 3" & _
"WHERE TargetInstance ISA 'Win32_USBControllerdevice'")

On Error Resume Next
intTimeOut = 6e4*(intTimeOut)
Do until err
wscript.sleep 1000
Set objSWbemObject = objSWbemEventSource.NextEvent(intTimeOut)
If Err.number = 0 Then
strDeviceName = objSWbemObject.TargetInstance.Dependent
strQuotes = Chr(34)
strDeviceName = Replace(strDeviceName, strQuotes, "")
arrDeviceNames = Split(strDeviceName, "=")
strDeviceName = Trim(Replace(arrDeviceNames(1),"\\", "\"))
If InStr(strDeviceName, "USB\") Then
With CreateObject("Wscript.Shell")
intReturn = .Popup(objSWbemObject.TargetInstance.Antecedent,3)
End With
End If
End If
Loop
WScript.Echo Err.Descriptio
Err.Clear

Wscript.quit
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''

note:
Users are able to stopt this monitor, by stopping the 'wscript.exe' process
in the TaskManager.

\Rems
  Réponse avec citation
Vieux 05/12/2007, 22h17   #3
pand0ra.usa
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Registry/Script question

\Rems Thanks!
I don't know vbs but I can read the code and I think I can figure out
how to point to a file to run from what you gave me here. Thanks for
the this is exactly what I was looking for.

On Nov 20, 11:01 am, \RemS <R...@discussions.microsoft.com> wrote:
> "pand0ra.usa" wrote:
> > Ok, here is the problem. I am looking to have a script file execute
> > when a usb device is attached to a computer. My problem is how to do
> > this without doing a scheduled task. Is there a registry key I can use
> > where I can point to my .bat file (myscript.bat) or is there a way to
> > script this to monitor the usb (I'm guessing this is more difficult)?

>
> Here is a simple script in vbs (save as a *.vbs file) that monitors for new
> attachted usb-devices.
> For testing this script has a 'timeout' and will close the monitor after 2
> minutes.
> You can later on disable the 'timeout' and run this script as a logonscript.
> Now a popup is showed when a device is attached, you can make that a program
> to run..
> The filter is "USB\" so it reacts for every usb device, but you can change
> that.
>
> '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
> intTimeOut = 3 ' in minutes
>
> strComputer = "."
> Set objSWbemServices = _
> GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
> Set objSWbemEventSource = objSWbemServices.ExecNotificationQuery _
> ("SELECT * FROM __InstanceCreationEvent WITHIN 3" & _
> "WHERE TargetInstance ISA 'Win32_USBControllerdevice'")
>
> On Error Resume Next
> intTimeOut = 6e4*(intTimeOut)
> Do until err
> wscript.sleep 1000
> Set objSWbemObject = objSWbemEventSource.NextEvent(intTimeOut)
> If Err.number = 0 Then
> strDeviceName = objSWbemObject.TargetInstance.Dependent
> strQuotes = Chr(34)
> strDeviceName = Replace(strDeviceName, strQuotes, "")
> arrDeviceNames = Split(strDeviceName, "=")
> strDeviceName = Trim(Replace(arrDeviceNames(1),"\\", "\"))
> If InStr(strDeviceName, "USB\") Then
> With CreateObject("Wscript.Shell")
> intReturn = .Popup(objSWbemObject.TargetInstance.Antecedent,3)
> End With
> End If
> End If
> Loop
> WScript.Echo Err.Descriptio
> Err.Clear
>
> Wscript.quit
> '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
>
> note:
> Users are able to stopt this monitor, by stopping the 'wscript.exe' process
> in the TaskManager.
>
> \Rems


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13946 seconds with 11 queries