Batch file to log if reg key is a 0 instead of 1

Posted on 2008-06-17
Last Modified: 2010-04-16
Im not very good with this kind of stuff but what I'm trying to do is if a registry key is a certain value "0" then I want to log their username, computername, Date and time to a txt file. I have to do this in a batch file not vbs. Heres what I have...

@echo off

IF "hkey_current_user\software\Microsoft\Windows\CurrentVersion\Policies\System" WITH VALUE "NoDispScrSavPage" where "NoDispScrSavPage"="0" exists then
goto log

echo %username% --- %computername% --- %DATE% --- %TIME% >> Y:\win2k\Regfiles\config\Screensaverchange.txt

The log part works if I delete the If statement. I know that if statement isnt correct. Please Help...
Question by:missywpitt
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 21802822

Author Comment

ID: 21802953
Sorry that didn't help me much.
LVL 38

Accepted Solution

Shift-3 earned 500 total points
ID: 21803154
Try this.

@echo off
setlocal enabledelayedexpansion
for /F "tokens=*" %%G in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v NoDispScrSavPage 2^>NUL') do (
 set val=%%G
 set val=!val:~-1!
if [%val%]==[0] (
 echo %username% --- %computername% --- %DATE% --- %TIME% >> Y:\win2k\Regfiles\config\Screensaverchange.txt

Open in new window


Expert Comment

ID: 21803170
Sorry, i have no real batch programming experience i just googled if statements in batch and hoped the guide would help...  Hopefully someone else with batch expereience sees this question.  Good luck.

Author Comment

ID: 21803215
Shift-3 ...your awesome! Thanks!!

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 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