2009-04-24 49 views
0

我有一個腳本任務在SSIS包應該從註冊表中檢索字符串值。如果註冊表值存在並且有一個值,它似乎會返回正確的值。如果註冊表項不存在或者該值爲空白,則由於某種原因,我無法將其設置爲默認值。我嘗試了三種不同的方式來做到這一點,但無法實現它。
我試過使用Registry.GetValue並指定一個默認的Registry.LocalMachine.CreateSubKey和Registry.LocalMachine.GetValue。我什至試圖明確檢查null或0的長度,似乎沒有工作......我是否做錯了?SSIS讀取註冊表項與默認值

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 

回答

1

您試過strValue Is Nothing

如果這不起作用,請在代碼中放置一個斷點,並在聲明它時註冊表項不存在時找出strValue正在設置的位置。

+0

謝謝,我很少再做VB了。 – Jeremy 2009-04-27 15:39:25