Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script: change in real time the key in the registry

Reply
 
Old 08-30-2009   #1 (permalink)
Salvador


 
 

Script: change in real time the key in the registry

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


My System SpecsSystem Spec
Old 08-30-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Script: change in real time the key in the registry


"Salvador" <salvador.carrero@xxxxxx> wrote in message
news:O$eAzFYKKHA.4168@xxxxxx
Quote:

>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\\Run'"
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"?


My System SpecsSystem Spec
Old 08-30-2009   #3 (permalink)
Salvador


 
 

Re: Script: change in real time the key in the registry

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]" <news@xxxxxx> wrote in message
news:Oe55V$YKKHA.4376@xxxxxx
Quote:

>
> "Salvador" <salvador.carrero@xxxxxx> wrote in message
> news:O$eAzFYKKHA.4168@xxxxxx
Quote:

>>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\\Run'"
> 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"?
>
My System SpecsSystem Spec
Old 08-30-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: Script: change in real time the key in the registry


"Salvador" <salvador.carrero@xxxxxx> wrote in message
news:OJ1RykaKKHA.4608@xxxxxx
Quote:

> 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 = "james@xxxxxx"
.To = "jack@xxxxxx"
.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") = "james@xxxxxx"
.Item (schema & "smtpaccountname") = "john@xxxxxx"
.Item (schema & "sendpassword") = "smtppassword"
End With
.Configuration.Fields.Update
.Send
End With
End Sub


My System SpecsSystem Spec
Old 08-31-2009   #5 (permalink)
jford


 
 

Re: Script: change in real time the key in the registry

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:
Quote:

>
> "Salvador" <salvador.carrero@xxxxxx> wrote in message
> news:OJ1RykaKKHA.4608@xxxxxx
Quote:

> > 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 = "james@xxxxxx"
> .To = "jack@xxxxxx"
> .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") = "james@xxxxxx"
> .Item (schema & "smtpaccountname") = "john@xxxxxx"
> .Item (schema & "sendpassword") = "smtppassword"
> End With
> .Configuration.Fields.Update
> .Send
> End With
> End Sub
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Problems with carret in URL (real time ticker sample) .NET General
Vista giving me a real hard time please help!!!! General Discussion
C#.NET Interview Questions And Real Time Discussions .NET General
Real time command line spy PowerShell
How to turn on CA EZ Antivirus real-time? Vista security


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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