?
Solved

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

Posted on 2008-06-17
5
Medium Priority
?
219 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 2000 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

Hire Technology Freelancers with Gigs

Work with 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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

578 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