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

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
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Groovy:unable to resolve class error 2 206
excel file 5 76
Batch script to move disabled user accounts to different OU 5 98
PS call executable Files in Order 4 12
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

828 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