关于C#调用dos命令的问题

chuanzhang5687 2012-03-19 10:33:59
由于客户不提供远程服务,所以更新的时候想做一个winform应用程序,调用一下批处理
然后将更新的文件放在指定目录下(如果有则先删除后粘贴)
还有一些调用sql,比如说我这边再库里加字段,加存储过程的,
这个该怎么弄

有没有什么链接,资料的,大家不要吝啬
...全文
268 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
能说话的哑巴 2012-03-21
  • 打赏
  • 举报
回复
6楼牛人,学习了!
nonocast 2012-03-21
  • 打赏
  • 举报
回复
cygwin+sshd / ssh
杨友山 2012-03-19
  • 打赏
  • 举报
回复
铜臂阿铁木 2012-03-19
  • 打赏
  • 举报
回复
把执行脚本顺序的存下来,存一次sql文件,到处执行。Yoooooooooooooooooo
C#调用命令的时候,替换SQL服务信息就好了。
chuanzhang5687 2012-03-19
  • 打赏
  • 举报
回复
谢谢 楼上这位仁兄!

补充一下:我这边再库里加字段,加存储过程的,要把这些新加的东西,再他那边的库里也执行一下


顶一下!
bdmh 2012-03-19
  • 打赏
  • 举报
回复
http://www.alixixi.com/program/a/2008050727420.shtml
sql那个就是数据库操作,自己google吧
ooo7880000 2012-03-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 chuanzhang5687 的回复:]

谢谢 楼上这位仁兄!

补充一下:我这边再库里加字段,加存储过程的,要把这些新加的东西,再他那边的库里也执行一下


顶一下!
[/Quote]
SQL部分:
在上家软件公司做的时候,他们是这样做的:更新补丁里的专门更新SQL的类中加判断数据库里是否有这个表,是否有这个存储过程。是否有字段。如果没有则添加呀(增删改查一样)。。后面再有更新就继续添加判断。

只要你dll更新了,运行的时候会自动提示 要升级SQL里面的字段之类的

用DOS没弄过。
coolheels 2012-03-19
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;


namespace Linx.Common.Common
{
/// <summary>
/// 执行命令
/// </summary>
public class CmdUtil
{
///
/// 执行cmd.exe命令
///
///命令文本
/// 命令输出文本
public static string ExeCommand(string commandText)
{
return ExeCommand(new string[] { commandText });
}
///
/// 执行多条cmd.exe命令
///
///命令文本数组
/// 命令输出文本
public static string ExeCommand(string[] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach (string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
//strOutput = Encoding.UTF8.GetString(Encoding.Default.GetBytes(strOutput));
p.WaitForExit();
p.Close();
}
catch (Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
///
/// 启动外部Windows应用程序,隐藏程序界面
///
///应用程序路径名称
/// true表示成功,false表示失败
public static bool StartApp(string appName)
{
return StartApp(appName, ProcessWindowStyle.Hidden);
}
///
/// 启动外部应用程序
///
///应用程序路径名称
///进程窗口模式
/// true表示成功,false表示失败
public static bool StartApp(string appName, ProcessWindowStyle style)
{
return StartApp(appName, null, style);
}
///
/// 启动外部应用程序,隐藏程序界面
///
///应用程序路径名称
///启动参数
/// true表示成功,false表示失败
public static bool StartApp(string appName, string arguments)
{
return StartApp(appName, arguments, ProcessWindowStyle.Hidden);
}
///
/// 启动外部应用程序
///
///应用程序路径名称
///启动参数
///进程窗口模式
/// true表示成功,false表示失败
public static bool StartApp(string appName, string arguments, ProcessWindowStyle style)
{
bool blnRst = false;
Process p = new Process();
p.StartInfo.FileName = appName;//exe,bat and so on
p.StartInfo.WindowStyle = style;
p.StartInfo.Arguments = arguments;
try
{
p.Start();
p.WaitForExit();
p.Close();
blnRst = true;
}
catch
{
}
return blnRst;
}

/// <summary>
/// 实现压缩,需要rar.exe上传到网站根目录
/// </summary>
/// <param name="s"></param>
/// <param name="d"></param>
/// <example>rar("e:/www.Linx.Common.cn/", "e:/www.Linx.Common.cn.rar");</example>
public static void Rar(string s, string d)
{
ExeCommand(System.Web.HttpContext.Current.Server.MapPath("~/rar.exe") + " a \"" + d + "\" \"" + s + "\" -ep1");
}

/// <summary>
/// 实现解压缩,需要rar.exe上传到网站根目录
/// </summary>
/// <param name="s"></param>
/// <param name="d"></param>
/// <example>unrar("e:/www.Linx.Common.cn.rar", "e:/");</example>
public static void UnRar(string s, string d)
{
ExeCommand(System.Web.HttpContext.Current.Server.MapPath("~/rar.exe") + " x \"" + s + "\" \"" + d + "\" -o+");
}

}

}

tan598121925 2012-03-19
  • 打赏
  • 举报
回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧