# Output two values in batch log to .csv with headers



## bryantan101 (May 22, 2013)

Greetings everyone,

To begin with, I extremely suck at doing batch scripting, so pardon my lack of understanding in this field.

I am attempting to output the below values to a .CSV file, however, I am unable to to get them separated into two columns.

Ideally, I would like to have the time-stamp of this activity logged onto another column of the CSV file as well.

Below is what I have thus far :

@echo off
echo %computername%/%username% >>C:\reg_output.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>C:\reg_output.csv
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR" /v "Start">>C:\reg_output.csv
echo>>C:\reg_output.csv

Many thanks in advance for anyone that can provide assistance.


----------



## foxidrive (Oct 20, 2012)

Your code is doing stuff that you haven't described in your question.

What is it you are trying to do? 
Also show what you are expecting in your file.


----------



## Squashman (Apr 4, 2003)

He never responded back to the last thread you tried to help him with a year and a half ago. I hope you aren't holding your breath.


----------



## foxidrive (Oct 20, 2012)

I wonder if he still works for the same Health institution? 

His code creates a whole bunch of lines, and one error,
so who knows what he's trying to get into two columns...


----------



## bryantan101 (May 22, 2013)

Sincere apologies everyone, I was away on an emergency.

The output should look something like this:

Column A 
Hostname
TEST-PC01

Column B 
Queried "START" value of "HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR" from registry 

Column C
DATE
DD/MM/YYYY 

Column D
TIME
14:00


----------



## Squashman (Apr 4, 2003)

```
@echo off
for /f "skip=1 tokens=3 delims= " %%G in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR" /v "Start"') do set query=%%G

echo %computername%,%query%,%date:~4%,%time:~0,-6% >>reg_output.csv

type reg_output.csv

pause
```
If you want the hex value from the reg query converted to a decimal then change the SET statement to this.

```
set /a query=%%G
```


----------



## bryantan101 (May 22, 2013)

Many thanks for the assistance, it produced the desired outcome.

Should I amend the targeted output as a UNC path, and have this run on targeted machines and have their information populated on the .CSV, would the existing information be overwritten?

I am attempting to apply headers on row 1 and have this script run on multiple machines and output to a single .CSV file.


----------



## foxidrive (Oct 20, 2012)

When asking for a script to be written to solve a task, it's respectful to give full and complete details at the start, so the reader can get involved and give you a good solution and then move on to help someone else.


----------



## bryantan101 (May 22, 2013)

Sincere apologies foxidrive, I mean no disrespect to anyone including yourself and the solutions provider for me being "vague" in my problem/issue description(s).

I will be mindful of how I go about my submissions in future.

That being said, I'm very appreciative of what has been provided thus far.


----------



## Squashman (Apr 4, 2003)

See if this makes sense to you.
http://www.robvanderwoude.com/redirection.php


----------

