Solved

Check for Registry VALUE in script

Posted on 2006-10-20
5
437 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Task showing running status in Task Scheduler 5 67
firstswap challenge 20 77
C# code editing and collaboration 3 110
sp_configure 'external scripts enabled', 1; 7 49
This article will show, step by step, how to integrate R code into a R Sweave document
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

785 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