1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Batch file creates text file but does not populate data to it

Discussion in 'Software Development' started by DownAndOut, May 23, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. DownAndOut

    DownAndOut Thread Starter

    Joined:
    May 23, 2008
    Messages:
    3
    I created this batch file to log certain users logins. It creates a text file to log in, but doesn't populate any of the data to it. Could someone please take a look at it and see what I did wrong. I'm new to writing batch files.

    Thanks in advance. Here is the code.

    @echo off
    set target=JDoe
    if %username% == target echo %username% %date% %time% %computername% >> c:\logfile.txt
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,783
    target is a variable. You have to surrournd it with %% like any other variable.

    Code:
    C:\>set target=Squashman
    
    C:\>if %username% == %target% echo %username% %date% %time% %computername% >> c:
    \logfile.txt
    
    C:\>type logfile.txt
    Squashman Fri 05/23/2008 10:34:14.74 BUMBLE-BEE
    
    C:\>
     
  3. DownAndOut

    DownAndOut Thread Starter

    Joined:
    May 23, 2008
    Messages:
    3
    Thank you Squashman. Will try it when I have a little more time.
     
  4. DownAndOut

    DownAndOut Thread Starter

    Joined:
    May 23, 2008
    Messages:
    3
    Thanks Squashman. With a little tweaking the batch file now works great. You were a very big help.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/714684

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice