Solved

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

Posted on 2008-06-17
5
211 Views
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

: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...
0
Comment
Question by:missywpitt
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Jk387
ID: 21802822
0
 

Author Comment

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

Accepted Solution

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

0
 
LVL 6

Expert Comment

by:Jk387
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.
0
 

Author Comment

by:missywpitt
ID: 21803215
Shift-3 ...your awesome! Thanks!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…

813 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

19 Experts available now in Live!

Get 1:1 Help Now