Solved

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

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

895 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

15 Experts available now in Live!

Get 1:1 Help Now