Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Script: change in real time the key in the registry

Reply
Thread Tools Display Modes

Script: change in real time the key in the registry

 
 
Salvador
Guest
Posts: n/a

 
      08-30-2009
I need a script that notifies any change in real time the key in the
registry:
KHLM \ Microsoft \ system \ CurrentControlSet \ Enum \ USBSTOR

The notice may be by courier to my team and by email.

As I do?
Thank you

 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-30-2009

"Salvador" <> wrote in message
news:O$...
>I need a script that notifies any change in real time the key in the
>registry:
> KHLM \ Microsoft \ system \ CurrentControlSet \ Enum \ USBSTOR
>
> The notice may be by courier to my team and by email.
>
> As I do?
> Thank you
>


Here you go (based on an idea by the Scripting Guy).
Note that the registry key you quote (KHLM \ Microsoft \ system \
CurrentControlSet \ Enum \ USBSTOR) does not exist. You must specify the
correct key in order to get the script to work.

sHive = "'HKEY_LOCAL_MACHINE'"
sPath = "'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Ru n'"
Set objWMIService = GetObject("winmgmts:\\.\root\default")
Set colEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM RegistryKeyChangeEvent " _
& "WHERE Hive= " & sHive _
& "And KeyPath=" & sPath)

Do
Set objLatestEvent = colEvents.NextEvent
WScript.Echo Now & ": The registry key" & VbCrLf _
& Replace(sHive & "\" & Replace(sPath, "\\", "\"), "'", "") _
& VbCrLf & "has been modified."
Loop

What do you mean with "by courier"?


 
Reply With Quote
 
Salvador
Guest
Posts: n/a

 
      08-30-2009
Thanks, I mean that the user does not leave any popup, it is sent by email
if you can notify the administrator that the user has connected a USB or is
a popup to the administrator.
Is it possible?
With the key is: HKLM / system / currentcontrolset / enum / usbstor

"Pegasus [MVP]" <> wrote in message
news:Oe55V$...
>
> "Salvador" <> wrote in message
> news:O$...
>>I need a script that notifies any change in real time the key in the
>>registry:
>> KHLM \ Microsoft \ system \ CurrentControlSet \ Enum \ USBSTOR
>>
>> The notice may be by courier to my team and by email.
>>
>> As I do?
>> Thank you
>>

>
> Here you go (based on an idea by the Scripting Guy).
> Note that the registry key you quote (KHLM \ Microsoft \ system \
> CurrentControlSet \ Enum \ USBSTOR) does not exist. You must specify the
> correct key in order to get the script to work.
>
> sHive = "'HKEY_LOCAL_MACHINE'"
> sPath = "'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Ru n'"
> Set objWMIService = GetObject("winmgmts:\\.\root\default")
> Set colEvents = objWMIService.ExecNotificationQuery _
> ("SELECT * FROM RegistryKeyChangeEvent " _
> & "WHERE Hive= " & sHive _
> & "And KeyPath=" & sPath)
>
> Do
> Set objLatestEvent = colEvents.NextEvent
> WScript.Echo Now & ": The registry key" & VbCrLf _
> & Replace(sHive & "\" & Replace(sPath, "\\", "\"), "'", "") _
> & VbCrLf & "has been modified."
> Loop
>
> What do you mean with "by courier"?
>


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      08-30-2009

"Salvador" <> wrote in message
news:...
> Thanks, I mean that the user does not leave any popup, it is sent by email
> if you can notify the administrator that the user has connected a USB or
> is a popup to the administrator.
> Is it possible?
> With the key is: HKLM / system / currentcontrolset / enum / usbstor
>


You can try the code below. Note that it will pick up changes at the usbstor
level but not at any deeper level.

sHive = "'HKEY_LOCAL_MACHINE'"
sPath = "'SYSTEM\\CurrentControlSet\\Enum\\USBSTOR'"
Set objWMIService = GetObject("winmgmts:\\.\root\default")
Set colEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM RegistryKeyChangeEvent " _
& "WHERE Hive= " & sHive _
& "And KeyPath=" & sPath)

Do
Set objLatestEvent = colEvents.NextEvent
SendMail sHive, sPath
Loop

Sub SendMail(Hive, Path)
Set oWshShell = CreateObject("WScript.Shell")
cdoBasic = 1
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set objEmail = CreateObject("CDO.Message")
With objEmail
.From = ""
.To = ""
.Subject = "Registry change report - " _
& oWshShell.ExpandEnvironmentStrings("%Computername% ")
.Textbody = "The key " & Hive & "\" & Path _
& " was modified on " & Date & " at " & Time & "."
With .Configuration.Fields
.Item (schema & "sendusing") = 2
.Item (schema & "smtpserver") = "mail.company.com"
.Item (schema & "smtpserverport") = 25
.Item (schema & "smtpauthenticate") = cdoBasic
.Item (schema & "sendusername") = ""
.Item (schema & "smtpaccountname") = ""
.Item (schema & "sendpassword") = "smtppassword"
End With
.Configuration.Fields.Update
.Send
End With
End Sub


 
Reply With Quote
 
jford
Guest
Posts: n/a

 
      08-31-2009
Just a potential gotcha, if you have anti-virus you may want to check the
settings because many will not allow a script or custom built application to
send emails.

troubleshooting ahead


"Pegasus [MVP]" wrote:

>
> "Salvador" <> wrote in message
> news:...
> > Thanks, I mean that the user does not leave any popup, it is sent by email
> > if you can notify the administrator that the user has connected a USB or
> > is a popup to the administrator.
> > Is it possible?
> > With the key is: HKLM / system / currentcontrolset / enum / usbstor
> >

>
> You can try the code below. Note that it will pick up changes at the usbstor
> level but not at any deeper level.
>
> sHive = "'HKEY_LOCAL_MACHINE'"
> sPath = "'SYSTEM\\CurrentControlSet\\Enum\\USBSTOR'"
> Set objWMIService = GetObject("winmgmts:\\.\root\default")
> Set colEvents = objWMIService.ExecNotificationQuery _
> ("SELECT * FROM RegistryKeyChangeEvent " _
> & "WHERE Hive= " & sHive _
> & "And KeyPath=" & sPath)
>
> Do
> Set objLatestEvent = colEvents.NextEvent
> SendMail sHive, sPath
> Loop
>
> Sub SendMail(Hive, Path)
> Set oWshShell = CreateObject("WScript.Shell")
> cdoBasic = 1
> schema = "http://schemas.microsoft.com/cdo/configuration/"
> Set objEmail = CreateObject("CDO.Message")
> With objEmail
> .From = ""
> .To = ""
> .Subject = "Registry change report - " _
> & oWshShell.ExpandEnvironmentStrings("%Computername% ")
> .Textbody = "The key " & Hive & "\" & Path _
> & " was modified on " & Date & " at " & Time & "."
> With .Configuration.Fields
> .Item (schema & "sendusing") = 2
> .Item (schema & "smtpserver") = "mail.company.com"
> .Item (schema & "smtpserverport") = 25
> .Item (schema & "smtpauthenticate") = cdoBasic
> .Item (schema & "sendusername") = ""
> .Item (schema & "smtpaccountname") = ""
> .Item (schema & "sendpassword") = "smtppassword"
> End With
> .Configuration.Fields.Update
> .Send
> End With
> End Sub
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script needed to change the SourcePath value in my Windows Server 2003 Registry Spin Windows Server 3 09-15-2008 04:27 PM
Script needed to change the SourcePath value in my Windows Server 2003 Registry Spin Scripting 3 09-15-2008 04:27 PM
script to force all users to change their password the next time they logon Sergio G. Scripting 1 10-04-2006 08:04 PM
System Time runs 3 times faster then real time Waldemar Thiel Virtual PC 0 02-01-2006 12:19 PM
Script to change registry entry Jrex7 Scripting 3 01-17-2006 09:10 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59