Skip to content

Commit 7753411

Browse files
committed
Parameter export & delete updates
- Make sure the registry key root is opened as writable so delete procedure completes without error. - Check for existing registry export file before exporting, to prevent reg.exe from hanging. - Handle any errors produced by reg.exe.
1 parent 9988ddb commit 7753411

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

WinNUT_V2/WinNUT-Client_Common/OldParams/WinNUT_Params.vb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
'
88
' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
99

10+
Imports System.Runtime.InteropServices
1011
Imports System.Security.Cryptography
1112
Imports System.Text
13+
Imports System.Windows.Forms
1214
Imports Microsoft.Win32
1315

1416
Namespace OldParams
@@ -80,7 +82,7 @@ Namespace OldParams
8082

8183
Public Shared ReadOnly Property RegistryKeyRoot As RegistryKey
8284
Get
83-
Return Registry.CurrentUser.OpenSubKey(REG_KEY_ROOT)
85+
Return Registry.CurrentUser.OpenSubKey(REG_KEY_ROOT, True)
8486
End Get
8587
End Property
8688

@@ -127,17 +129,25 @@ Namespace OldParams
127129
''' </summary>
128130
''' <param name="destinationPath">The location of the exported file.</param>
129131
Public Shared Sub ExportParams(destinationPath As String)
132+
' Duplicate file must be removed now otherwise reg.exe will hang waiting for an input to overwrite.
133+
If IO.File.Exists(destinationPath) Then
134+
' Allow any exceptions to be passed up to caller.
135+
IO.File.Delete(destinationPath)
136+
End If
137+
130138
Dim regExpProcStartInfo As New ProcessStartInfo With {
131139
.FileName = "reg.exe",
132140
.UseShellExecute = False,
133-
.RedirectStandardOutput = True,
134141
.RedirectStandardError = True,
135142
.CreateNoWindow = True,
136143
.Arguments = "export """ & RegistryKeyRoot.Name & """ """ & destinationPath & """"
137144
}
138145

139146
Dim proc = Process.Start(regExpProcStartInfo)
140147
proc.WaitForExit()
148+
If proc.ExitCode = 1 Then
149+
Throw New InvalidOperationException("reg.exe encountered an error: " & proc.StandardError.ReadToEnd())
150+
End If
141151
End Sub
142152

143153
Public Shared Sub DeleteParams()

0 commit comments

Comments
 (0)