Solved

Check for Registry VALUE in script

Posted on 2006-10-20
5
436 Views
Last Modified: 2008-02-12
I want to use a log on script to check for a registry VALUE.  The key may or may not exist.  if the key exists it can have two values- 1, and 2.  

i want the script to change the value to 2 if it's currently 1 but not to do anything if the key doesn't exist.  

Is that possible?

I know you can look for the KEY by using:
If exist [HKEY_LOCAL_MACHINE\rest of key]

but how do I make the script look for the value?

thanks in advance.


0
Comment
Question by:jmerulla
  • 2
5 Comments
 
LVL 6

Expert Comment

by:SCDMETA
ID: 17776726
Option Explicit

Dim WSHShell, RegKey, Value

Set WSHShell = CreateObject("WScript.Shell")

RegKey = "HKLM\Software\Company\Test"


On Error Resume Next

' read key
Value  = WSHShell.RegRead(RegKey)
if Err.Number = 0 Then
      
      WScript.echo "Value: " & Value

      if Value = 1 Then
            ' write key
            WshShell.RegWrite RegKey & "test", 2
      end if

      ' read key again
      Value  = WSHShell.RegRead(RegKey & "Test")
      WScript.echo "Value: " & Value
Else
      WScript.echo "Not Found"
End If
0
 
LVL 2

Author Comment

by:jmerulla
ID: 17776796
i saw that, but I'm trying to do this in a logon script.  I'm not exactly sure how to use it.  Can you please explain?

thanks
0
 
LVL 6

Accepted Solution

by:
SCDMETA earned 250 total points
ID: 17777674
http://www.computerperformance.co.uk/Logon/logon_script_assign.htm

Check out the bottom of this article.
It explains using Group Policy and the aritcle has some pretty good examples.
http://www.tek-tips.com/faqs.cfm?fid=5798



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now