Script should update the CSV file

sadiya yousaf
sadiya yousaf used Ask the Experts™

I have found following script from internet and modified it little bit as log in script. It is adding extra line in CSV file every time user log in , Can someone help me to modify it sothat script update the exiting row if PC details are already in the cvs file instead of adding new row.
Script is following:
@echo off

REM set variables
set system=
set login=
set manufacturer=
set model=
set serialnumber=

REM Get Computer Name
FOR /F "tokens=2 delims='='" %%A in ('wmic OS Get csname /value') do SET system=%%A

REM Get User Name
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get UserName /value') do SET Login=%%A

REM Get Computer Manufacturer
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Manufacturer /value') do SET manufacturer=%%A

REM Get Computer Model
FOR /F "tokens=2 delims='='" %%A in ('wmic ComputerSystem Get Model /value') do SET model=%%A

REM Get Computer Serial Number
FOR /F "tokens=2 delims='='" %%A in ('wmic Bios Get SerialNumber /value') do SET serialnumber=%%A

echo Login %date% %username% %logonserver% %computername% %manufacturer% %model% %serialnumber%>> \\opdc02\ScreenImage\Logs\logs1.csv
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
I expect that you are running this om multiple / many users pcs, and all the info is being collected in the single file?  If that is the case I would strongly urge you to adjust your approach.  Don't use one single file for all the data collection, but rather create one file per computer.  As you are currently doing it, sooner or later multiple computers will be logging in at the same time, and trying to write to the same file concurrently with little to no collaboration control, and you will have data corruption or loss.

By have a different file per computer, then you can just overwrite that file each time a login occurs so you always have the current data.  And you should eliminate any contention based issues for the single file.

It's very easy to later merge all these files into a single file if you want for reporting, atc.

Distinguished Expert 2017

A csv file means values are separated by commas, in your case/example you are separating them by space.
Distinguished Expert 2017

Salsa, the script calling wmi is unnecessary for certain predefined variable's surrounded by %


The other three you use are needed.


I have followed Bill's advise and going to look into what Arnold has mentioned as well.
Thank you for your help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial