首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

使用VB.net备份注册表时出现Win32Exception错误

2012-12-16 
使用VB.net备份注册表时出现Win32Exception异常本帖最后由 qqqhhhhh1111 于 2012-12-01 09:04:08 编辑欲使

使用VB.net备份注册表时出现Win32Exception异常
本帖最后由 qqqhhhhh1111 于 2012-12-01 09:04:08 编辑 欲使用VB.net备份整个项HKEY_CURRENT_USER\Software\abc\def
该注册表项存在。


If SaveFileDialog1.ShowDialog = DialogResult.OK Then System.Diagnostics.Process.Start("%Systemroot%\System32\regedt32.exe /e """ & SaveFileDialog1.FileName & """ HKEY_CURRENT_USER\Software\abc\def")


结果调试时出现在 System.ComponentModel.Win32Exception 中第一次偶然出现的“System.dll”类型的异常:未处理 System.ComponentModel.Win32Exception:系统找不到指定的文件。

异常详细信息:
引用
未处理 System.ComponentModel.Win32Exception
  ErrorCode=-2147467259
  Message=系统找不到指定的文件。
  NativeErrorCode=2
  Source=System
  StackTrace:
       在 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
       在 System.Diagnostics.Process.Start()
       在 System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
       在 System.Diagnostics.Process.Start(String fileName)
       在 Timetable.OptionForm.Button1_Click(Object sender, EventArgs e) 位置 F:\Users\Poweruser\Documents\Visual Studio 2010\Projects\课程表\课程表\OptionForm.vb:行号 42
       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.RunDialog(Form form)
       在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       在 System.Windows.Forms.Form.ShowDialog()
       在 Timetable.MainForm.Button1_Click(Object sender, EventArgs e) 位置 F:\Users\Poweruser\Documents\Visual Studio 2010\Projects\课程表\课程表\MainForm.vb:行号 4


       在 System.Windows.Forms.Control.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnClick(EventArgs e)
       在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       在 System.Windows.Forms.Control.WndProc(Message& m)
       在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
       在 System.Windows.Forms.Button.WndProc(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       在 System.Windows.Forms.Application.Run(ApplicationContext context)
       在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       在 Timetable.My.MyApplication.Main(String[] Args) 位置 17d14f5c-a337-4978-8281-53493378c1071.vb:行号 81
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 



而直接在“运行”中输入System.Diagnostics.Process.Start后的参数%Systemroot%\System32\regedt32.exe /e "D:\123.reg" HKEY_CURRENT_USER\Software\abc\def是可以运行的。
[最优解释]
 Din fn as string ="regedt32.exe"
 Dim pInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()


        Dim Proc As System.Diagnostics.Process
        With pInfo
            .FileName = fn
            .Arguments = " /e D:\123.reg HKEY_CURRENT_USER\Software\abc\def"
            .WorkingDirectory = IO.Path.GetDirectoryName(fn)
        End With
        Try
            Proc = System.Diagnostics.Process.Start(pInfo)
        Catch ex As Exception
            MessageBox.Show(ex.Message & fn, "打開", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


[其他解释]
把%Systemroot%\System32\ 去掉 试一试!
[其他解释]
引用:
把%Systemroot%\System32\ 去掉 试一试!

试过了,一样
[其他解释]
或者直接用:
Dim reg As Microsoft.Win32.RegistryKey
reg = Microsoft.Win32.Registry.CurrentUser
‘--
Microsoft.Win32.Registry 这个来操作。
里面封装了很多相关的类。
[其他解释]
http://www.yesky.com/SoftChannel/72342380468240384/20030822/1723516_1.shtml

热点排行