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 ...
随机推荐
- 51nod_1100:斜率最大
题目链接 斜率最大点对横坐标必相邻 #include <bits/stdc++.h> using namespace std; ; struct point { int x, y, pos ...
- Java虚拟机:类加载机制详解
版权声明:本文为博主原创文章,转载请注明出处,欢迎交流学习! 大家知道,我们的Java程序被编译器编译成class文件,在class文件中描述的各种信息,最终都需要加载到虚拟机内存才能运行和使用,那么 ...
- 实例化bean
从bean.xml中<bean>标签内容可以看出bean其实是一个管理对象的东西,我们只需要修改xml配置文件,就可以改变对象之间的依赖关系,不需要去修改任何源代码.我觉得学习好sprin ...
- Eclipse中安装MemoryAnalyzer插件及使用
Eclipse中安装MemoryAnalyzer插件 一.简介 Eclipse作为JAVA非常好用的一款IDE,其自带的可扩展插件非常有利于JAVA程序员的工作效率提升. MemoryAnalyzer ...
- C++ STL map详解
一.解释: p { margin-bottom: 0.25cm; direction: ltr; color: #00000a; line-height: 120%; text-align: just ...
- NYOJ--114--某种序列(大数)
某种序列 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 数列A满足An = An-1 + An-2 + An-3, n >= 3 编写程序,给定A0, A1 ...
- Java Socket 编程
1. 背景 网络编程是指编写运行在多个设备(计算机)的程序,这些设备都通过网络连接起来. java.net 包中 J2SE 的 API 包含有类和接口,它们提供低层次的通信细节.你可以直接使用这些类和 ...
- 让这三个月来的更猛烈些吧,前端react同构项目
昨天一篇文章讲述了我在这三个月中由.net到java的过程,其中踩坑填坑的细节真不是三言两语可以道尽,而完成时的喜悦也远非寻常可比(仅次于涨工资).然而到这并不算完结,作为前后端分离的忠实粉丝,我认为 ...
- spring学习之spring 插件 for eclipse
1) 在公司一直使用固定的eclipse IDE版本3.3 确实太out了. eclipse官方网址:http://download.eclipse.org 奇怪的是eclipse 发布的版本顺序是 ...
- MySQL之增_insert-replace
MySQL增删改查之增insert.replace 一.INSERT语句 带有values子句的insert语句,用于数据的增加 语法: INSERT [INTO] tbl_name[(col_nam ...