Solved

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

Posted on 2008-06-17
5
209 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
Comment Utility
0
 

Author Comment

by:missywpitt
Comment Utility
Sorry that didn't help me much.
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Shift-3 ...your awesome! Thanks!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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.

771 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

11 Experts available now in Live!

Get 1:1 Help Now