• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 699
  • Last Modified:

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

0
gbosko
Asked:
gbosko
  • 2
1 Solution
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now