Link to home
Start Free TrialLog in
Avatar of Garry Shape
Garry ShapeFlag for United States of America

asked on

Export registry key value to text or csv

Hello

I'm trying to find a vbscript that will do the following:

1. Look for the key "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General"
2. Get the value for "UserTemplates" in this key
3. Output the information into a text file with the %computername% and if possible the %username% of the user that's logged into the system, to make easier for finding the user.

The idea behind this is to gather all the paths from a lot of computers and see which ones are using a network path for the User Templates path, as opposed to a path on their local C-Drive  (where it should be).

Targets are Windows XP users. Systems are on a domain. The script output results can be saved to a shared \\server path.
Avatar of gintu01
gintu01
Flag of United States of America image

Select the key then file > Export.  it allows you to select .txt files when saving.
Avatar of johnb6767
This is simpole batch, not vbs... Thought I would offer it anyway....  :)
@echo off
echo %computername%/%username% >>\\server\share\OfficeGeneral.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>\\server\share\OfficeGeneral.txt
reg query "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General" /v "UserTemplates">>\\server\share\OfficeGeneral.txt
echo>>\\server\share\OfficeGeneral.txt

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of johnb6767
johnb6767
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Garry Shape

ASKER

Thanks, that works great. The batch works right off the bat. The VBScript helps but I'll need to modify with some research.

Thanks again.
Here is the VBScript version you asked for...

Option Explicit
On Error Resume Next

Dim wShell, fso, adInfo, strTemplatesVal, strServerShare, strOutFile

strServerShare = "\\SomeServer\SomeShare\"

Const reg1 = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General\UserTemplates"

Set wShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set adInfo = CreateObject("ADSystemInfo")

strTemplatesVal = wShell.RegRead(reg1)

Set strOutFile = fso.CreateTextFile(strServerShare & adInfo.ComputerName & "-" & adInfo.UserName & ".txt",true)

If strTemplatesVal <> Null Then
 strOutFile.Write strTemplatesVal
Else
 strOutFile.Write "Key does not Exist " & reg1
End If

Open in new window

If you need help with the vbs script i'll be pleased of helping you.