兄弟们,C#中怎么调用外部命令?比如copy,dir???在线等待!! System.Diagnostics.Process("copy aaa.html bbb.html") ??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用API也行。using System.Runtime.InteropServices;[DllImport("Shell32.dll",EntryPoint="ShellExecute")]public static extern IntPtr ShellExecute( IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);调用:ShellExecute(handle, null, path_to_folder, null, null, SW_SHOWNORMAL);or ShellExecute(handle, "open", path_to_folder, null, null, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(handle, "explore", path_to_folder, null, null, SW_SHOWNORMAL);常数值可以从c++ 的Library中查到 更正一下:ShellExecute(this.Handle, null, path_to_folder, null, null, SW_SHOWNORMAL);or ShellExecute(this.Handle, "open", path_to_folder, null, null, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(this.Handle, "explore", path_to_folder, null, null, SW_SHOWNORMAL); project() ...5555555555看不懂。其实我就想做一个程序,比如:myexe.exe.他可以这样用:myexe.exe copy aaa.html bbb.html那么就运行 copy aaa.html bbb.htmlmyexe.exe dir *.*那么就运行dir *.*555。谁帮我写这个程序呢???告诉我关键语句也行(C#)的。 File命名空间下有很多文件操作命令。你可以去看一下。如:File.Exist(string FileName)、File.Copy... project() ,晕。我不是要copy。那只是一个例子!!就是运行时直接调用dos命令就行。!!比如:myexe dir *.*myexe rename bbb.asp ccc.bacmyexe md aaa之类的。 就是运行时直接调用dos命令就行。!!批处理不久解决? System.Diagnostics.Process proc = new System.Diagnostics.Process();proc.StartInfo.FileName = "COMMAND"; //win98proc.StartInfo.Arguments = "/C TYPE " + strFilePath + " > PRN";proc.Start();proc.WaitForExit();proc.Dispose(); 可以把命令写入一个批处理文件比如在D盘根目录下存为test.batc#中添加引用C:\WINNT\System32\wshom.ocxWshShellClass obj=new WshShellClass();obj.Exec("d:\\test.bat");就可执行文件中的一系列DOS命令 你不就是为了操作文件吗用system.io.file or system.io.fileinfo不就完了! System.Diagnostics.Process xx = new System.Diagnostics.Process(); xx.StartInfo.FileName="ping.exe"; xx.StartInfo.Arguments ="www.sina.com.cn"; xx.StartInfo.UseShellExecute=false; xx.StartInfo.CreateNoWindow = true; xx.StartInfo.RedirectStandardOutput = true; xx.Start(); xx.WaitForExit(); System.Windows.Forms.MessageBox.Show( xx.StandardOutput.ReadToEnd()); Process类似乎不能够调用内部命令吧? .net框架里面有一个file 和 fileinfo 类,这个类就能实现你向有关的文件操作。你可以查一下msdn,也可以查看一下《c#入门经典》或《c#高级编程》。 System.Diagnostics.Process.Start("notepad.exe"); C# 如何获取combobox手动输入内容 接口存在的意义!? xbap部署到IIS打开的时候出现未授予信任错误[有图],急急急~~~ c#域名解析问题,各位高手有什么好办法吗?小弟在线等。 怎么上穿Excel,并读取资料,急啊~~ 关于combobox不显示值的问题 关于session的问题 请问各位高手,一个xml中有两个DataSet,如何分别读出来? 如果将IP地址改为自动获取? Tree_View奇怪问题,那位高手来看看!解决就给分! 请教: 请高手进来看看
using System.Runtime.InteropServices;[DllImport("Shell32.dll",EntryPoint="ShellExecute")]
public static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
int nShowCmd
);调用:
ShellExecute(handle, null, path_to_folder, null, null, SW_SHOWNORMAL);or ShellExecute(handle, "open", path_to_folder, null, null, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(handle, "explore", path_to_folder, null, null, SW_SHOWNORMAL);常数值可以从c++ 的Library中查到
ShellExecute(this.Handle, null, path_to_folder, null, null, SW_SHOWNORMAL);or ShellExecute(this.Handle, "open", path_to_folder, null, null, SW_SHOWNORMAL);To explore a folder, use: ShellExecute(this.Handle, "explore", path_to_folder, null, null, SW_SHOWNORMAL);
他可以这样用:myexe.exe copy aaa.html bbb.html
那么就运行 copy aaa.html bbb.html
myexe.exe dir *.*
那么就运行dir *.*
555。谁帮我写这个程序呢???告诉我关键语句也行(C#)的。
myexe dir *.*
myexe rename bbb.asp ccc.bac
myexe md aaa
之类的。
proc.StartInfo.FileName = "COMMAND"; //win98
proc.StartInfo.Arguments = "/C TYPE " + strFilePath + " > PRN";
proc.Start();
proc.WaitForExit();
proc.Dispose();
c#中添加引用C:\WINNT\System32\wshom.ocxWshShellClass obj=new WshShellClass();
obj.Exec("d:\\test.bat");就可执行文件中的一系列DOS命令
用system.io.file or system.io.fileinfo
不就完了!
xx.StartInfo.FileName="ping.exe";
xx.StartInfo.Arguments ="www.sina.com.cn";
xx.StartInfo.UseShellExecute=false;
xx.StartInfo.CreateNoWindow = true;
xx.StartInfo.RedirectStandardOutput = true;
xx.Start();
xx.WaitForExit();
System.Windows.Forms.MessageBox.Show( xx.StandardOutput.ReadToEnd());