首页 > 代码库 > Hyper-V、Esxi虚机还原,远程重启(关机)
Hyper-V、Esxi虚机还原,远程重启(关机)
/// <summary> /// 还原虚拟机 /// </summary> /// <param name="RDPID"></param> /// <returns></returns> public ActionResult RevertVM(string RDPID, bool isNeedStateTOZero) { JsonResult jr = new JsonResult(); try { bool flag = false; RDPInfoFO fo = new RDPInfoFO(); RDPInfoDTO rdp = fo.GetRDPHostInfo(RDPID); if (string.IsNullOrEmpty(rdp.VMservice)) { flag = RevertESXI(RDPID); } else { flag = RevertHyper_V(RDPID); } if (flag) { //LogWriter.Info("还原快照成功" + info); if (isNeedStateTOZero) { fo.FreeRDP(RDPID); } else { fo.HasRDP(RDPID); } jr.Data = new { State = "success", Msg = "还原快照成功" }; } else { jr.Data = new { State = "error", Msg = "还原快照失败" }; //LogWriter.Info("还原快照失败" + info); } } catch (Exception ex) { //LogWriter.Info("还原快照出现异常" + info + " 异常信息:" + ex.Message); jr.Data = http://www.mamicode.com/new { State = "error", Msg = ex.Message }; } return jr; } #region Hyper-V虚拟机还原 private bool RevertHyper_V(string RDPID) { RDPInfoFO fo = new RDPInfoFO(); RDPInfoDTO rdp = fo.GetRDPHostInfo(RDPID); object result = WSHelper.InvokeWebService(rdp.VMservice, "RollBack", new string[] { rdp.VMName, rdp.HostServerIP, rdp.HostUserName, rdp.HostPassword }); bool flag = (bool)result; return flag; } #endregion #region ESXI虚拟机还原 private bool RevertESXI(string RDPID) { RDPInfoFO fo = new RDPInfoFO(); RDPInfoDTO rdp = fo.GetRDPHostInfo(RDPID); string info = "HostServerIP:" + rdp.HostServerIP + " VMName:" + rdp.VMName + " username:" + rdp.HostUserName + " password:" + rdp.HostPassword; bool rel = VMSnapshot.RevertVm(rdp.HostServerIP, rdp.VMName, rdp.HostUserName, rdp.HostPassword); return rel; } #endregion #region Windwos7重启 /// <summary> /// /// </summary> /// <param name="strname">登陆名</param> /// <param name="strpwd">密码</param> /// <param name="ip">机器IP地址</param> /// <param name="doinfo">Reboot/Shutdown</param> private void CloseComputer(string strname, string strpwd, string ip, string doinfo) { ConnectionOptions op = new ConnectionOptions(); op.Username = strname;//‘‘或者你的帐号(注意要有管理员的权限) op.Password = strpwd; //‘‘你的密码 ManagementScope scope = new ManagementScope("\\\\" + ip + "\\root\\cimv2:Win32_Service", op); try { scope.Connect(); System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem"); ManagementObjectSearcher query1 = new ManagementObjectSearcher(scope, oq); //得到WMI控制 ManagementObjectCollection queryCollection1 = query1.Get(); foreach (ManagementObject mobj in queryCollection1) { string[] str = { "" }; mobj.InvokeMethod(doinfo, str); } //MessageBox.Show("操作成功"); } catch (Exception ey) { //MessageBox.Show(ey.Message); //this.button1.PerformClick(); } } #endregion
Hyper-V、Esxi虚机还原,远程重启(关机)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。