I have a script task in an SSIS package that is supposed to retrieve a string value from the registry. If the registry value exists and has a value in it it appears to return the value fine. If the registry key does not exist or the value is blank, I can not get it to default a value for some reason. I've tried three different ways of doing it, but can't get it to work.
I've tried using Registry.GetValue and specifying a default, Registry.LocalMachine.CreateSubKey, and Registry.LocalMachine.GetValue. I've even tried explicitly checking for null or 0 length, nothing seems to work... Whan am I doing wrong?
Public Sub Main()
'Dim strValue As String = DirectCast(Registry.LocalMachine.GetValue("SOFTWARE\MyComp\SSIS\IPSEmail\strLastDate", DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")), String)
'Dim strValue As String = DirectCast(Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\MyComp\SSIS\IPSEmail", "strLastDate", DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")), String)
Dim strValue As String = DirectCast(Registry.LocalMachine.CreateSubKey("SOFTWARE\MyComp\SSIS\IPSEmail\strLastDate").GetValue("strLastDate", DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")), String)
If (strValue = Nothing Or strValue.Length = 0) Then
strValue = DateTime.Now.ToString("MMM dd, yyyy HH:mm:ss")
End If
Dts.ExecutionValue = strValue
Dts.TaskResult = Dts.Results.Success
End Sub