GHO2VMDK转换工具分享含VS2010源码
平常经常用到虚拟机,每次从gho转换为vmdk时都要输入cmd代码,觉得麻烦,自己动手做了个gho2vmdk转换工具,集成ghost32.exe文件,可以一键转换,省时省事。运行时会将ghost32.exe保存到Program FIles文件夹里,运行完自动删除ghost32.exe。觉得还不错,在此分享一下,有什么好的建议,欢迎反馈。代码贴上。需要完整工程的请留言邮箱。开发工具为VS2010,没用任何第三方插件。觉得有帮助举手点个推荐。
程序下载地址:链接:http://pan.baidu.com/s/1bp2HBw7 密码:jpw4
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using GHO2VMDK转换工具.Properties; namespace GHO2VMDK转换工具
{
public partial class Form1 : Form
{
private string _ghost32ExeFullName; public Form1()
{
InitializeComponent();
} /// <summary>
/// Form1_Load
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
//启用拖放
txtGhoFullName.AllowDrop = true;
//在拖入边界时发生
txtGhoFullName.DragEnter += (s1, e1) =>
{
if (e1.Data.GetDataPresent(DataFormats.FileDrop))
{
e1.Effect = DragDropEffects.Link;
}
else
{
e1.Effect = DragDropEffects.None;
}
}; //在拖放完成时发生
txtGhoFullName.DragDrop += (s1, e1) =>
{
//攻取gho文件路径
string tmpPath = ((Array) (e1.Data.GetData(DataFormats.FileDrop))).GetValue(0).ToString();
string extension = Path.GetExtension(tmpPath);
if (extension.ToLower() == ".gho")
txtGhoFullName.Text = tmpPath;
else
MessageBox.Show("请拖放GHO文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
};
} /// <summary>
/// txtGhoFullName_TextChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtGhoFullName_TextChanged(object sender, EventArgs e)
{
//根据gho文件路径,自动设置vmdk文件默认保存路径
string ghoFullName = txtGhoFullName.Text;
string directoryName = Path.GetDirectoryName(ghoFullName);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(ghoFullName);
if (directoryName != null)
{
string vmdkFullName = Path.Combine(directoryName, fileNameWithoutExtension + ".vmdk");
txtVmdkFullName.Text = vmdkFullName;
}
} /// <summary>
/// btnStartConvert_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStartConvert_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否开始将GHO文件转换为VMDK文件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
//获取ProgramFiles路径
string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
//设置ghost32.exe文件临时保存路径
_ghost32ExeFullName = Path.Combine(path, "ghost32.exe");
if (!File.Exists(_ghost32ExeFullName))
{
//从资源文件读取ghost32.exe并保存到_ghost32ExeFullName路径
FileStream str = new FileStream(_ghost32ExeFullName, FileMode.OpenOrCreate);
str.Write(Resources.Ghost32, 0, Resources.Ghost32.Length);
str.Close();
} //设置ghost32.exe运行参数
string cmdText = string.Format("-clone,mode=restore,src=\"{0}\",dst=\"{1}\" -batch -sure",
txtGhoFullName.Text, txtVmdkFullName.Text);
//隐蔽窗口
WindowState = FormWindowState.Minimized;
Hide();
//运行ghost32.exe
RunCmd(_ghost32ExeFullName, cmdText);
Show();
//显示窗口
WindowState = FormWindowState.Normal;
//删除ghost32.exe
if (File.Exists(_ghost32ExeFullName))
File.Delete(_ghost32ExeFullName); MessageBox.Show("操作完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} /// <summary>
/// 运行cmd命令
/// 不会显示命令窗口
/// </summary>
/// <param name="cmdExe">指定应用程序的完整路径</param>
/// <param name="cmdStr">执行命令行参数</param>
private static bool RunCmd(string cmdExe, string cmdStr)
{
bool result = false;
try
{
using (Process myPro = new Process())
{
//指定启动进程是调用的应用程序和命令行参数
ProcessStartInfo psi = new ProcessStartInfo(cmdExe, cmdStr);
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true; myPro.StartInfo = psi;
myPro.Start();
myPro.WaitForExit();
result = true;
}
}
catch
{
result = false;
}
return result;
} /// <summary>
/// 运行cmd命令
/// 不显示命令窗口
/// </summary>
/// <param name="cmdExe">指定应用程序的完整路径</param>
/// <param name="cmdStr">执行命令行参数</param>
private static bool RunCmd2(string cmdExe, string cmdStr)
{
bool result = false;
try
{
using (Process myPro = new Process())
{
myPro.StartInfo.FileName = "cmd.exe";
myPro.StartInfo.UseShellExecute = false;
myPro.StartInfo.RedirectStandardInput = true;
myPro.StartInfo.RedirectStandardOutput = true;
myPro.StartInfo.RedirectStandardError = true;
myPro.StartInfo.CreateNoWindow = true;
myPro.Start();
//如果调用程序路径中有空格时,cmd命令执行失败,可以用双引号括起来 ,在这里两个引号表示一个引号(转义)
string str = string.Format(@"""{0}"" {1} {2}", cmdExe, cmdStr, "&exit"); myPro.StandardInput.WriteLine(str);
myPro.StandardInput.AutoFlush = true;
myPro.WaitForExit(); result = true;
}
}
catch
{
result = false;
}
return result;
} private void chbTopMost_CheckedChanged(object sender, EventArgs e)
{
//窗口置顶
TopMost = chbTopMost.Checked;
} private void btnBrowseGhoFile_Click(object sender, EventArgs e)
{
//浏览gho文件
string ghoFullName = txtGhoFullName.Text; OpenFileDialog f = new OpenFileDialog
{
Title = "浏览GHO文件...",
Filter = "GHO文件(*.gho)|*.gho",
FileName = ghoFullName,
InitialDirectory = ghoFullName
};
if (f.ShowDialog() == DialogResult.OK)
{
txtGhoFullName.Text = f.FileName;
}
} private void btnBrowseVmdkFile_Click(object sender, EventArgs e)
{
//浏览VMDK文件
string vmdkFullName = txtVmdkFullName.Text;
SaveFileDialog f = new SaveFileDialog
{
Title = "设置VMDK文件保存路径...",
Filter = "VMDK文件(*.vmdk)|*.vmdk",
FileName = vmdkFullName,
InitialDirectory = vmdkFullName
};
if (f.ShowDialog() == DialogResult.OK)
{
txtVmdkFullName.Text = f.FileName;
}
}
}
}
--版权信息--
转载请标明文章出处,谢谢!
文章作者:易几 http://www.cnblogs.com/InfoStudio/
--版权信息--
GHO2VMDK转换工具分享含VS2010源码的更多相关文章
- 微信小程序中如何使用WebSocket实现长连接(含完整源码)
本文由腾讯云技术团队原创,感谢作者的分享. 1.前言 微信小程序提供了一套在微信上运行小程序的解决方案,有比较完整的框架.组件以及 API,在这个平台上面的想象空间很大.腾讯云研究了一番之后,发现 ...
- Omega System Trading and Development Club内部分享策略Easylanguage源码 (第二期)
更多精彩内容,欢迎关注公众号:数量技术宅,也可添加技术宅个人微信号:sljsz01,与我交流. 我们曾经在前文(链接),为大家分享我们精心整理的私货:"System Trading and ...
- SpringMVC关于json、xml自动转换的原理研究[附带源码分析 --转
SpringMVC关于json.xml自动转换的原理研究[附带源码分析] 原文地址:http://www.cnblogs.com/fangjian0423/p/springMVC-xml-json-c ...
- JAVA全套资料含视频源码(持续更新~)
本文旨在免费分享我所搜集到的Java学习资源,所有资源都是通过正规渠道获取,不存在侵权.现在整理分享给有所需要的人. 希望对你们有所帮助!有新增资源我会更新的~大家有好的资源也希望分享,大家互帮互助共 ...
- Tyrion中文文档(含示例源码)
Tyrion是一个基于Python实现的支持多个WEB框架的Form表单验证组件,其完美的支持Tornado.Django.Flask.Bottle Web框架.Tyrion主要有两大重要动能: 表单 ...
- 【腾讯Bugly干货分享】深入源码探索 ReactNative 通信机制
Bugly 技术干货系列内容主要涉及移动开发方向,是由 Bugly 邀请腾讯内部各位技术大咖,通过日常工作经验的总结以及感悟撰写而成,内容均属原创,转载请标明出处. 本文从源码角度剖析 RNA 中 J ...
- SpringMVC关于json、xml自动转换的原理研究[附带源码分析]
目录 前言 现象 源码分析 实例讲解 关于配置 总结 参考资料 前言 SpringMVC是目前主流的Web MVC框架之一. 如果有同学对它不熟悉,那么请参考它的入门blog:http://www.c ...
- 微信公众账号开发教程(四)自定义菜单(含实例源码)——转自http://www.cnblogs.com/yank/p/3418194.html
微信公众账号开发教程(四)自定义菜单 请尊重作者版权,如需转载,请标明出处. 应大家强烈要求,将自定义菜单功能课程提前. 一.概述: 如果只有输入框,可能太简单,感觉像命令行.自定义菜单,给我们提供了 ...
- 最近在研究电台类app,分享2个源码大家一起讨论
好像去年有一阵,电台类的app特别火爆,喜马拉雅和蜻蜓FM互相还撕逼.听老罗,听好好说话,都得在电台app里,所以我想研究研究这些app.我没那么多资源,只好从app的开发架构方面去研究. 我看api ...
随机推荐
- 【SqlServer系列】集合运算
1 概述 已发布[SqlServer系列]文章如下: [SqlServer系列]SQLSERVER安装教程 [SqlServer系列]数据库三大范式 [SqlServer系列]表单查询 [SqlS ...
- css3-d ,动画,圆角
一.3D 开启元素3D transform-style: preserve-3d; Z轴 正数 屏幕外,反之屏幕内 近大远小 perspective: length (必须大于等于0) -- 在3D元 ...
- H5微信通过百度地图API实现导航方式二
要有服务器才行哦 <!DOCTYPE html><html><head> <meta http-equiv="Content-Type&quo ...
- SQL Server Alwayson创建代理作业注意事项
介绍 Always On 可用性组活动辅助功能包括支持在辅助副本上执行备份操作. 备份操作可能会给 I/O 和 CPU 带来很大的压力(使用备份压缩). 将备份负荷转移到已同步或正在同步的辅助副本后, ...
- WAS 部署 Birt 报表出现 error.CannotStartupOSGIPlatform 和 更新web.xml
在WAS7.0中部署Birt报表会出现error.CannotStartupOSGIPlatform错误,通常需要这样修改 1.依次打开Applications->WebSphere enter ...
- mybatis入门介绍二
相信看过我的上一篇博客的同学都已经对mybatis有一个初步的认识了.这篇博客主要是对mybatis的mapper代理做一下简单的介绍,希望能够帮助大家共同学习. 我的上一篇博客:mybatis入门介 ...
- nodeJS之crypto加密
前面的话 加密模块提供了 HTTP 或 HTTPS 连接过程中封装安全凭证的方法.也提供了 OpenSSL 的哈希,hmac, 加密(cipher), 解密(decipher), 签名(sign) 和 ...
- 记录easyui一些用法
自己备注,省的之后忘记.用到一个写一个,不断添加 1.form里的一些控件如textbox.combobox等添加额外的一些事件,如鼠标事件(mouseover.click等),键盘事件(keydow ...
- JS基础学习篇(一)
近来一直在学习js和jquery.刚刚进入前端工作还没有多久,虽然大学里学习的是编程自认为也学的还可以,但前端接触的不多,一直认为前端十分简单.其实不然,特别是工作的时候要自己设计一个完整的项目前端, ...
- iframe嵌入页面不能全部展示
在嵌入页面不能全部展示的问题中,可以通过js改变iframe的高度 html部分代码: <iframe src="#" name="i" id=" ...