Can I get an exit code from running regedit /s?

我的梦境 提交于 2019-12-11 04:14:48

问题


I have a script that changes a registry value, before doing that, it makes a backup of the registry key using regedit /e to create a .reg file.

If the script is run a second time and the .reg backup file exists, I am asking the user if they want to add their backup back into the registry.

Because I don't want to confuse users who will have no real idea of whats happening with extra prompts they might not understand, I am using the following code to do this with out asking the user if they want to import:

Set objShell = CreateObject("WScript.Shell")
objShell.Run"regedit /s "  & """" & BackupFile & """" , 0, True

Is there a way to get a exit code from the regedit command for success or failure of regedit importing the backup .reg file?


回答1:


regedit doesn't return a status code. Use reg.exe with the import subcommand instead:

rc = objShell.Run("reg import """ & BackupFile & """" , 0, True)

If rc = 0 Then
  WScript.Echo "Import successful."
Else
  WScript.Echo "Import failed. (" & rc & ")"
End If



回答2:


Use

 Return = objShell.Run("regedit /s "  & """" & BackupFile & """" , 0, True)

Return contains the returned value.



来源:https://stackoverflow.com/questions/18296926/can-i-get-an-exit-code-from-running-regedit-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!