Advertisement
shockwaveriderz

TurnHypervisorOffOn

Jan 17th, 2020
4,506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Dim backupfile
  4. Dim record
  5. Dim myshell
  6. Dim appmyshell
  7. Dim myresult
  8. Dim myline
  9. Dim makeactive
  10. Dim makepassive
  11. Dim reboot
  12. record=""
  13. Set myshell = WScript.CreateObject("WScript.Shell")
  14.  
  15. If WScript.Arguments.Length = 0 Then
  16. Set appmyshell = CreateObject("Shell.Application")
  17. appmyshell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1
  18. WScript.Quit
  19. End if
  20.  
  21.  
  22.  
  23.  
  24. Set backupfile = CreateObject("Scripting.FileSystemObject")
  25. If Not (backupfile.FileExists("C:\bcdedit.bak")) Then
  26. Set myresult = myshell.Exec("cmd /c bcdedit /export C:\bcdedit.bak")
  27. End If
  28.  
  29. Set myresult = myshell.Exec("cmd /c bcdedit")
  30. Do While Not myresult.StdOut.AtEndOfStream
  31. myline = myresult.StdOut.ReadLine()
  32.  
  33. If myline="The boot configuration data store could not be opened." Then
  34. record=""
  35. exit do
  36. End If
  37. If Instr(myline, "identifier") > 0 Then
  38. record=""
  39. If Instr(myline, "{current}") > 0 Then
  40. record="current"
  41. End If
  42. End If
  43. If Instr(myline, "hypervisorlaunchtype") > 0 And record = "current" Then
  44. If Instr(myline, "Auto") > 0 Then
  45. record="1"
  46. Exit Do
  47. End If
  48. If Instr(myline, "On") > 0 Then
  49. record="1"
  50. Exit Do
  51. End If
  52. If Instr(myline, "Off") > 0 Then
  53. record="0"
  54. Exit Do
  55. End If
  56. End If
  57. Loop
  58.  
  59. If record="1" Then
  60. makepassive = MsgBox ("Hypervisor status is active, do you want set to passive? ", vbYesNo, "Hypervisor")
  61. Select Case makepassive
  62. Case vbYes
  63. myshell.run "cmd.exe /C bcdedit /set hypervisorlaunchtype off"
  64. reboot = MsgBox ("Hypervisor changed to passive; Computer must reboot. Reboot now? ", vbYesNo, "Hypervisor")
  65. Select Case reboot
  66. Case vbYes
  67. myshell.run "cmd.exe /C shutdown /r /t 0"
  68. End Select
  69. Case vbNo
  70. MsgBox("Not Changed")
  71. End Select
  72. End If
  73.  
  74. If record="0" Then
  75. makeactive = MsgBox ("Hypervisor status is passive, do you want set active? ", vbYesNo, "Hypervisor")
  76. Select Case makeactive
  77. Case vbYes
  78. myshell.run "cmd.exe /C bcdedit /set hypervisorlaunchtype auto"
  79. reboot = MsgBox ("Hypervisor changed to active; Computer must reboot. Reboot now?", vbYesNo, "Hypervisor")
  80. Select Case reboot
  81. Case vbYes
  82. myshell.run "cmd.exe /C shutdown /r /t 0"
  83. End Select
  84. Case vbNo
  85. MsgBox("Not Changed")
  86. End Select
  87. End If
  88.  
  89. If record="" Then
  90. MsgBox("Error: record can't find")
  91. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement