Registry values to text file

Hello, We are running vmware view desktops. I would like to record the details of the client that is used to connect to the VMs.
Vmware has some sample of code of this info being pulled from registry here: http://blogs.vmware.com/thinapp/2010/09/looking-up-view-client-machine-info-and-using-it-in-a-thinapp.html

I would like the client NAME, IP, and MAC to be written to a text file with a Timestamp triggered by login script.  (UNC PATH \\Server\share)

So using the example code below how do i get that written to a text file instead of a Messagebox?



'Declare Environment Variables
Dim vMachine, vIP, vMAC

'Set Environment Variables
Const HKEY_CURRENT_USER  = &H80000001
Set wmiLocator=CreateObject("WbemScripting.SWbemLocator")
Set wmiNameSpace = wmiLocator.ConnectServer(".", "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
sPath = "Volatile Environment"

'Lookup values in registry and assign to variables
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_Machine_Name", vMachine)
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_IP_Address", vIP)
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_MAC_Address", vMAC)

'Test Message Box to show values
MsgBox "The Remote Device Name is " & vMachine & " @ " & vIP & "(" & vMAC & ")",, "NTDLL Call Test"

Open in new window

gboskoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prashanthdCommented:
Try the following, it will write to a log file on \\Server\share\

Modify log_file
on error resume next
'Declare Environment Variables
log_file="\\Server\share\VM_Logon.log"

Const ForAppending = 8
Dim vMachine, vIP, vMAC

'Set Environment Variables
Const HKEY_CURRENT_USER  = &H80000001
Set wmiLocator=CreateObject("WbemScripting.SWbemLocator")
Set wmiNameSpace = wmiLocator.ConnectServer(".", "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
sPath = "Volatile Environment"

'Lookup values in registry and assign to variables
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_Machine_Name", vMachine)
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_IP_Address", vIP)
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_MAC_Address", vMAC)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(log_file, ForAppending, True)
objTextFile.WriteLine Now & " - The Remote Device Name is " & vMachine & " @ " & vIP & "(" & vMAC & ")"
objTextFile.Close
'Test Message Box to show values
'MsgBox "The Remote Device Name is " & vMachine & " @ " & vIP & "(" & vMAC & ")",, "NTDLL Call Test"

Open in new window

0
Gašper KamenšekExcel MVPCommented:
Hi,

this should do the trick

Dim fso,textfile
Set fso=CreateObject("scripting.filesystemobject")
Set textfile=fso.opentextfile("somefilename.here",8,true)
textfile.writeline  "The Remote Device Name is " & vMachine & " @ " & vIP & "(" & vMAC & ")",, "NTDLL Call Test"
textfile.close
Set textfile=nothing
Set fso=nothing

Have a nice day...
0
gboskoAuthor Commented:
prashanthd. I gave it a try and that is perfect! There is one thing I did not state in original question. The path where it is saved varies to the logged in user, is there a way to use a variable like %username% in the path?  So if my username is bsmith, when I login it will add to the file \\SERVER1\bsmith$\VM_logon.log?
0
prashanthdCommented:
Try the following...
On Error Resume Next
'Declare Environment Variables

Const ForAppending = 8
Dim vMachine, vIP, vMAC

'Set Environment Variables
Const HKEY_CURRENT_USER  = &H80000001
Set wmiLocator=CreateObject("WbemScripting.SWbemLocator")
Set wmiNameSpace = wmiLocator.ConnectServer(".", "root\default")
Set objRegistry = wmiNameSpace.Get("StdRegProv")
sPath = "Volatile Environment"

'Lookup values in registry and assign to variables
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_Machine_Name", vMachine)
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_IP_Address", vIP)
lRC = objRegistry.GetStringValue(HKEY_CURRENT_USER, sPath, "ViewClient_MAC_Address", vMAC)

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
'WScript.Echo "User Name: " & strUserName
log_file="\\Server1\"& strUserName &"$\VM_Logon.log"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(log_file, ForAppending, True)
objTextFile.WriteLine Now & " - The Remote Device Name is " & vMachine & " @ " & vIP & "(" & vMAC & ")"
objTextFile.Close
'Test Message Box to show values
'MsgBox "The Remote Device Name is " & vMachine & " @ " & vIP & "(" & vMAC & ")",, "NTDLL Call Test"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.