PDA

View Full Version : send Registry Settings with email



Djblois
05-11-2007, 09:34 AM
I am saving settings in the registry and I have a but reporting system built into the program. Now I want to set it up that when someone sends out a bug report, that I will get a copy of their registry settings? Is this possible? In a text file preferably?

the settings file is called Business Reporting Today

I have looked into the help files and I can't find anything.

Please this would be very helpful

Charlize
05-11-2007, 04:16 PM
Why don't you use the getsetting thing that you used earlier to get some values from the registry and send that over by mail using cdo. ie When they push a button you'll make sure you first get all the settings off the user by using that getsetting thing. I think you will have to get all the keys one by one (the ones that you have defined with savesetting).

or you could try to control the register editor by using vba and export that key-file (don't have a clue --- yet --- how I would do that).

Just an idea.

Charlize

Djblois
05-14-2007, 12:10 PM
How can I print it to the email though? or in a text file and then attach the text file?

Charlize
05-14-2007, 03:05 PM
Something like this :Sub Mail_with_CDO()
'This is for personal use on a private system. A home pc.
'No error checking yet. Check for internetconnection
'and if mail sending fails, set imsg and iconf to nothing
'before exiting loop.

'Maybe add msgbox to say, send manual mail to your address
'when there was an error with the mail sending
Dim v_mail As String
Dim v_smtp As String

Dim value_variable_setting_one As String
Dim value_variable_setting_two As String

Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant

v_mail = Application.InputBox("Provide me your e-mail address", "Provide e-mail ...")
v_smtp = Application.InputBox("Provide smtp-server for your provider. " & _
vbCrLf & "(outserver.provider.com) for address " & v_mail, "Provide smtp-server ...")

'Must set a reference to microsoft cdo object library
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
'If you get an error with the sending argument you have to remove the ' of
'Dim Flds As Variant and the coding between the ***
'************
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields

With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" & v_smtp & ""
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
'************
'Send an email
With iMsg
Set .Configuration = iConf
.To = "Djblois@provider.com"
'Here you use the personal emailsettings of the user
.From = v_mail
.Subject = "Additional info for requested feedback !"
'Don't remove TextBody. The attachments can not be opened when received.
'Bug in CDO
'value_variable_setting_one is filled by using your getsetting thing
'value_variable_setting_two ...
'...
.TextBody = "Userinfo for the one requesting info." & vbCrLf & _
"- Setting one : " & value_variable_setting_one & vbCrLf & _
"- Setting two : " & value_variable_setting_two
'.addattachment
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
End SubBetter possible way is to include some kind of list where they just must select their provider to send the mail with the address they have given to you (maybe also with that savesetting and getsetting thing). Maybe you can define the smtp server of the provider by using a list ? Or you can create a list of smtp servers based on the providers over the world.

Charlize

Djblois
05-15-2007, 06:52 AM
between the help of one of my books (Where I found GetAllSettings) and then looking up in the help files (Under GetAllSettings), I came up with this code:

UserSettings = GetAllSettings("Business Reporting Today", "Debug")
For intSettings = LBound(UserSettings, 1) To UBound(UserSettings, 1)
Debug.Print UserSettings(intSettings, 0), UserSettings(intSettings, 1)
Next intSettings

but as of right now, all this code does is show the settings in the immediate window. Can I use this code to pring the contents of the immediate window to a text file or just the registry settings itself?
Charlize, I can't use your code becuase I am on a server, at my job. thank you.

Djblois
05-15-2007, 08:30 AM
anybody have any ideas?

Charlize
05-15-2007, 11:16 AM
You can use the code that I provided. Change the smtp server to the name of the mailserver (servermail.textafterat - com.local) on your work. Look at configuration of your mailclient on your desktop or ask it to the IT staff. The .From is problably the inlogname with '.textafterat - com.local'.

If you site is djblois.com, email is username.djblois.local

Charlize

Charlize
05-15-2007, 11:25 AM
Not tested, just a idea : Sub Store_in_array()
Dim A_settings()
UserSettings = GetAllSettings("Business Reporting Today", "Debug")
ReDim Preserve A_settings(UBound(UserSettings), 1)
For intsettings = LBound(UserSettings, 1) To UBound(UserSettings, 1)
Debug.Print UserSettings(intsettings, 0), UserSettings(intsettings, 1)
A_settings(intsettings, 0) = UserSettings(intsettings, 0)
A_settings(intsettings, 1) = UserSettings(intsettings, 1)
Next intsettings
End SubCharlize

Djblois
05-17-2007, 07:47 AM
Charlize,

This is what I am up to. I decided it would work best if I save it to a text file first. So, in the future I can use it to keep a whole log file. Here is what I have:

LogFile = "H:\@Temp\LogFile.txt"
Open LogFile For Output As #1
UserSettings = GetAllSettings("Business Reporting Today", "Debug")
ReDim Preserve A_settings(UBound(UserSettings), 1)
For intSettings = LBound(UserSettings, 1) To UBound(UserSettings, 1)
Print #1, UserSettings(intSettings, 0), UserSettings(intSettings, 1)
A_settings(intSettings, 0) = UserSettings(intSettings, 0)
A_settings(intSettings, 1) = UserSettings(intSettings, 1)
Next intSettings
EmailItem.Attachments.Add LogFile

so far it adds the text file but it doesn't save the settings to a the text file first.

Charlize
05-17-2007, 02:15 PM
LogFile = "H:\@Temp\LogFile.txt"
Open LogFile For Output As #1
UserSettings = GetAllSettings("Business Reporting Today", "Debug")
ReDim Preserve A_settings(UBound(UserSettings), 1)
For intSettings = LBound(UserSettings, 1) To UBound(UserSettings, 1)
Print #1, UserSettings(intSettings, 0), UserSettings(intSettings, 1)
A_settings(intSettings, 0) = UserSettings(intSettings, 0)
A_settings(intSettings, 1) = UserSettings(intSettings, 1)
Next intSettings
---> Close #1
EmailItem.Attachments.Add LogFile

so far it adds the text file but it doesn't save the settings to a the text file first.Should we close the file before trying to attach to a mail ?

Djblois
05-18-2007, 05:28 AM
Charlize,

Which ever way works easier. In the long run I want to turn it into a complete log file but for now I just want to create it send it and then delete it, after it sends.

Daniel

Djblois
05-19-2007, 07:47 AM
bump

Charlize
05-19-2007, 12:28 PM
To fetch the registry items I used this one :Sub test_write_to_file()
Dim logfile As String
Dim usersettings As Variant
Dim intSettings As Long
logfile = "C:\Data\@Temp\LogFile.txt"
Open logfile For Output As #1
usersettings = GetAllSettings("Invoicetracking", "Company")
For intSettings = LBound(usersettings, 1) To UBound(usersettings, 1)
Print #1, usersettings(intSettings, 0) & "#" & _
usersettings(intSettings, 1) & "#" & _
Environ("UserName") & "#" & _
Now
Next intSettings
Close #1
End SubAnd before I've saved them with Sub create_register_values()
SaveSetting appname:="Invoicetracking", section:="Company", key:="Name", setting:="Djblois"
SaveSetting "Invoicetracking", "Company", "Registerkey", "Not Registered"
End SubEverything worked fine ...
Take a look at your register under HKey_Current_User
Search for 'vba program settings' and under that folder (in left pane) there should the values be present that you have saved earlier.

Djblois
05-19-2007, 02:26 PM
Charlize,

You are the man, but now lets try and take it one step further. How can I get it so instead of deleting the contents, it just adds the log to the end, so I can use it as a full fledged log file for each user. I already modified the code to include their user name in the file name:

logfile = "H:\@Temp\" & Environ("UserName") & "_LogFile.txt"

Charlize
05-19-2007, 03:24 PM
Open logfile For Append As #1But you better use freefile to fetch the number to use instead of hard coding it to #1 (you'll never know what someone is doing at that time). So no_file = freefile (or something like that).

Djblois
05-19-2007, 03:30 PM
sorry but please talk to me like I am an idiot. I have no clue what you just said about freefile?

Charlize
05-19-2007, 03:45 PM
Sub Get_Unused_fileno()
Dim FileNumber As Long
FileNumber = FreeFile ' Get unused fileno
' Create file name.
Open "C:\Data\@Temp\youruser_logfile.txt" For Append As #FileNumber
Write #FileNumber, "Data you want in file" ' Output text.
Close #FileNumber ' Close file.
End SubYou never know what the end user is doing. If he is doing some exporting and maybe the programs he uses used also #1, there could be some problems. There can't be two programs that are using the same no to write to a file (my guess).