Regedit – Cannot create value: Error writing to the registry.

19 Comments

I guess this is your typical newbie mistake on Windows Vista, but even so I had a hard time finding the solution on Google so I thought I’d post about it.

When I was trying to add a key in the Registry Editor, regedit.exe, I got an error message saying “Cannot create value: Error writing to the registry.”
I have never seen this on XP (but then again I don’t edit the registry that often), but since this is Vista with UAC (User Account Control) I thought it might have to do with permissions so I tried to run regedit.exe as Administrator but to no avail.

Finally I figured out that I did not have the right permissions in the registry tree.
The solution is simply to right click on the folder and select Permissions. You may not even have the right to change the permissions, if this is the case then first you have to take ownership – click Advanced and then the Owner tab.

Funny thing about my folder is that the owner was a group called “TrustedInstaller”. After I had taken ownership, I wanted to change it back to the “TrustedInstaller” group but it was nowhere to be found. Apparently you can’t change it back – it is not a group but a service and part of Windows Resource Protection (WRP) as noted by Richard Civil and others in this TechNet post.

Two other useful newbie things I found out – thanks to this post by Tim Sneath of Microsoft – when trying to figure out how to run a regedit.exe as Administrator in Vista was this:

  1. Run from the XP Start menu is now replaced with Start Search bar in Vista. Simply type regedit.exe (or cmd.exe etc.) in the search bar and hit Enter and it will run.
  2. To run an application with Administrator privileges using this method, instead of hitting Enter you hit Ctrl+Shift+Enter.

Newsletter Unsubscribe and Delivery Failure in Outlook

6 Comments

I have a web site from which I weekly send out newsletters to 15-20.000 members. The sending of the newsletters is fully automated but I use two VBscript Macros in Outlook to handle Delivery Failures (eg. User Unknown, Domain not Found, Mailbox Full) and the manual Unsubscribe Requests I get. I know I can buy or subscribe to tools that automate this for me but I find it easy enough to handle it manually in Outlook using these two Macros. Nothing fancy or hitech but maybe it helps someone else out.

The Macros are written in VBscript and used in Outlook 2003. I have not yet tested them in Outlook 2007 but I expect they will work there too. (I have just installed a new computer with Windows Vista and Office 2007 but have not yet had the time to move everything there)

How I use the Macros:

  1. Newsletters are automatically sent to members
  2. Delivery Failures and Unsubscribe emails land in my Outlook Inbox and I move them to a Errors and Unsubscribe folder respectively (I could/should create an inbox rule that based on recipient automatically move them to the correct folder)
  3. I run the Macros to extract email addresses
  4. I paste the extracted email addresses into a admin page that I have created for my site that remove them from the database, send a confirmation email etc.

Script 1 – GetEmailSender:
Extracts email sender. Runs on all mailitems in current folder that are unread. This is the Macro I run on Unsubscribe emails.
[Update: Download this macro as a text file here.]

Script 2 – GetEmailFromBody:
Extracts first found email address from body. Runs on all items in current folder. This is the Macro I run on Delivery Failure emails.
[Update: Download this macro as a text file here.]

(To add the Macros in Outlook: Copy code from below, goto to Tools – Macros – Visual Basic Editor – and paste the code there)

Sub GetEmailSender()

' ------------------------------------------------
' --- You may use and/or change this code freely
' --- provided you keep this message
' ---
' --- Description:
' --- Extracts email sender
' --- Runs on all mailitems in current folder that
' --- are unread
' ---
' --- By Max Flodén 2006 - http://www.tjitjing.com
' ------------------------------------------------

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace

Dim mySelection As Selection

Dim myItem As Object
Dim myMailItemLog As Outlook.MailItem

Dim myFolder As Outlook.MAPIFolder

Dim strContactFolderName As String 'Directly under Public Folders\All Public Folders
Dim strNewsletterCategoryName As String
Dim strMailItemSender As String
Dim strMailTo As String
Dim intMessageCount As Integer
Dim bolDebug As Boolean 'If true error messages will be shown
Dim strTemp As String

Set myNameSpace = myOlApp.GetNamespace("MAPI")

'Debug settings
bolDebug = True

'Ask to continue - start warning
intRes = MsgBox("This macro will go thru all items in folder." & vbCrLf & "Would like to continue?", vbYesNo + vbQuestion, "Get Email Sender")
If Not intRes = vbYes Then Exit Sub

'Create a new email to use as log file
Set myMailItemLog = myOlApp.CreateItem(olMailItem)
myMailItemLog.Recipients.Add (myNameSpace.CurrentUser)
myMailItemLog.Subject = "Email from Body - " & Now()
myMailItemLog.BodyFormat = olFormatPlain
myMailItemLog.Body = Now() & " Starting..." & vbCrLf & vbCrLf

'Go thru all items in folder
intMessageCount = 0
intMsgCount_Error = 0
For Each myItem In myOlApp.ActiveExplorer.CurrentFolder.Items

If Not TypeName(myItem) = "MailItem" Then
'Errorlog
If bolDebug Then myMailItemLog.Body = myMailItemLog.Body & "ERROR - MESSAGE TYPE IS NOT MAILITEM." & vbCrLf
myItem.UnRead = True
intMsgCount_Error = intMsgCount_Error + 1
ElseIf myItem.UnRead Then
myMailItemLog.Body = myMailItemLog.Body & myItem.SenderEmailAddress & vbCrLf
myItem.UnRead = False
myItem.FlagStatus = olFlagMarked
intMessageCount = intMessageCount + 1
End If

Next

'Done - write to log and show done message
myMailItemLog.Body = myMailItemLog.Body & vbCrLf & Now() & " Done. Email addresses extracted: " & intMessageCount & ". Email addresses NOT extracted: " & intMsgCount_Error & "."
myMailItemLog.Display
MsgBox Now() & " Done. Email addresses extracted: " & intMessageCount & ". Email addresses NOT extracted: " & intMsgCount_Error & ".", vbInformation, "Done"

End Sub


Sub GetEmailFromBody()

' ------------------------------------------------
' --- You may use and/or change this code freely
' --- provided you keep this message
' ---
' --- Description:
' --- Extracts first found email address from body
' --- (used to extract email address from
' --- error messages/returned email)
' --- Runs on all items in current folder
' ---
' --- By Max Flodén 2006 - http://www.tjitjing.com
' ------------------------------------------------

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim mySelection As Selection
Dim myItem As Object
Dim myMailItemLog As Outlook.MailItem
Dim myFolder As Outlook.MAPIFolder

Dim strContactFolderName As String 'Directly under Public Folders\All Public Folders
Dim strNewsletterCategoryName As String
Dim strMailItemSender As String
Dim strMailTo As String
Dim intMessageCount As Integer
Dim bolDebug As Boolean 'If true no emails will be sent
Dim bolOnly550 As Boolean 'Only extract email addresses that are 'user not found' (#550) etc.
Dim strTemp As String

Set myNameSpace = myOlApp.GetNamespace("MAPI")

'Debug settings
bolDebug = True

'Ask to continue - start warning
intRes = MsgBox("This macro will go thru all items in folder." & vbCrLf & "Would like to extract only addresses that have 'user not found'?", vbYesNoCancel + vbQuestion, "Get Email from Body")
If intRes = vbCancel Then
Exit Sub
ElseIf intRes = vbYes Then
bolOnly550 = True
Else
bolOnly550 = False
End If

'Create a new email to use as log file
Set myMailItemLog = myOlApp.CreateItem(olMailItem)
myMailItemLog.Recipients.Add (myNameSpace.CurrentUser)
myMailItemLog.Subject = "Email from Body - " & Now()
myMailItemLog.BodyFormat = olFormatPlain
myMailItemLog.Body = Now() & " Starting..." & vbCrLf & vbCrLf

'Go thru all items in folder
intMessageCount = 0
intMsgCount_Error = 0
For Each myItem In myOlApp.ActiveExplorer.CurrentFolder.Items

If Not TypeName(myItem) = "ReportItem" And Not TypeName(myItem) = "MailItem" Then
'Errorlog
If bolDebug Then myMailItemLog.Body = myMailItemLog.Body & "ERROR - MESSAGE TYPE IS NOT REPORTITEM OR MAILITEM." & vbCrLf
myItem.UnRead = True
intMsgCount_Error = intMsgCount_Error + 1
Else

'Check type is 550 - user not found/inactive etc
If bolOnly550 And _
(InStr(myItem.Body, "550") = 0) And _
(InStr(myItem.Body, "554") = 0) And _
(InStr(myItem.Body, "unknown user") = 0) And _
(InStr(myItem.Body, "user unknown") = 0) And _
(InStr(myItem.Body, "no mailbox here by that name") = 0) And _
(InStr(myItem.Body, "no such user") = 0) And _
(InStr(myItem.Body, "bad address") = 0) And _
(InStr(myItem.Body, "Host or domain name not found") = 0) And _
(InStr(myItem.Body, "e-mail account does not exist") = 0) Then
If bolDebug Then myMailItemLog.Body = myMailItemLog.Body & "ERROR - NOT 550 OR Host or domain name not found MESSAGE." & vbCrLf
myItem.UnRead = True
intMsgCount_Error = intMsgCount_Error + 1
Else

'Extract email address from body
intPos = InStr(myItem.Body, "@")
If intPos = 0 Then
'No email address found
If bolDebug Then myMailItemLog.Body = myMailItemLog.Body & "ERROR - NO EMAIL ADDRESS FOUND IN MESSAGE." & vbCrLf
myItem.UnRead = True
intMsgCount_Error = intMsgCount_Error + 1
Else
'Get right of @
intPos_Space = InStr(intPos, myItem.Body, " ")
intPos_Bracket = InStr(intPos, myItem.Body, ">")
If (intPos_Space < intpos_bracket =" 0)" intpos_temp =" intPos_Space" intpos_temp =" intPos_Bracket" strtemp =" Left(myItem.Body," intpos_space =" InStrRev(strTemp," intpos_bracket =" InStrRev(strTemp,"> intPos_Bracket) Or (intPos_Bracket = 0) Then
intPos_Temp = intPos_Space
Else
intPos_Temp = intPos_Bracket
End If
strTemp = Mid(strTemp, intPos_Temp + 1)
'Write to log
myMailItemLog.Body = myMailItemLog.Body & strTemp & vbCrLf
myItem.UnRead = False
intMessageCount = intMessageCount + 1
End If
End If
End If

Next

'Done - write to log and show done message
myMailItemLog.Body = myMailItemLog.Body & vbCrLf & Now() & " Done. Email addresses extracted: " & intMessageCount & ". Email addresses NOT extracted: " & intMsgCount_Error & "."
myMailItemLog.Display
MsgBox Now() & " Done. Email addresses extracted: " & intMessageCount & ". Email addresses NOT extracted: " & intMsgCount_Error & ".", vbInformation, "Done"

End Sub

Google Wildcards and Personalized Search

1 Comment

After setting my own personal blog posting record in October I have been silent for a few months… 😉

Just stumbled across this today – it has probably always been there and most of you probably already know about it, but I thought I’d mention it anyway. You can use wildcards in Google, for example search for “IBM acquired * in 1995” on Google.

This is just another typical example of how you (ie. me) think you know a product and are “happy enough” with it to stop learning more about it. (More in the Google Help Search Basics…)

Speaking of Google I read in one of their offficial blog posts that they will now provide personalized search results when you are logged in:

Keep in mind that personalization is subtle—at first you may not notice any difference. But over time, as the search engine learns your preferences, you’ll see it. For example, I (Sep) am an avid Miami Dolphins fan (no joke). Searching for [dolphins] gives me info about my favorite football team, while a marine biologist colleague gets more information about her salt-water friends.

This sounds great to me, but of course it again raises important questions on privacy – I’m not too sure that I want all searches I’m making stored somewhere, available to who knows who.
Living in a pretty well developed democracy I’m not too worried about government finding out stuff about me but it’s not hard to imagine that a country like China can leagally force Google to give out information about its citizens. And it’s not too hard to imagine a future bug that by mistake will give the whole world access to your searches if they now your email address (that you use to logon to Google) – all of a sudden your employer knows that you’re looking for a new job, your wife that you been searching for xxx, etc…
Not to mention all the new work this will bring to all SEOs (Search Engine Optimizers) out there 😉