C#如何实现这个 C# 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/jailu/archive/2007/07/22/827058.html System.Diagnostics.Process.Start("cmd.exe", "/K echo y format B:"); // don't try it ;-) = =...楼上那个是用process执行cmd命令...和楼主要的不太一致吧... 至少我没有写format c: 现在几乎都没有A/B盘了。教训就是,要运行任意代码就要有控制权限的思想准备。 至少我没有写format c: 现在几乎都没有A/B盘了。教训就是,要运行任意代码就要有控制权限的思想准备。一般不都是有提示的么?这个没提示? /* // 使用 C# 动态编译代码和执行 static void Main(string[] args) { // 编译器 CodeDomProvider cdp = CodeDomProvider.CreateProvider("C#"); // 编译器的参数 CompilerParameters cp = new CompilerParameters(); cp.ReferencedAssemblies.Add("System.dll"); cp.GenerateExecutable = false; cp.GenerateInMemory = true; // 编译结果 CompilerResults cr = cdp.CompileAssemblyFromSource(cp, HelloWorld()); if (cr.Errors.HasErrors) Console.WriteLine("编译出错!"); else { // 编译后的程序集 Assembly ass = cr.CompiledAssembly; // 得到HelloWorld类中的SayHello方法 Type type = ass.GetType("HelloWorld.HelloWorld"); MethodInfo mi = type.GetMethod("SayHello"); // 执行 mi.Invoke(null, null); } } // 动态构建的代码 static string HelloWorld() { StringBuilder sbCode = new StringBuilder(); sbCode.AppendLine("using System;"); sbCode.AppendLine("namespace HelloWorld"); sbCode.AppendLine("{"); sbCode.AppendLine(" class HelloWorld"); sbCode.AppendLine(" {"); sbCode.AppendLine(" public static void SayHello()"); sbCode.AppendLine(" {"); sbCode.AppendLine(" Console.WriteLine(\"Hello~ World~!\");"); sbCode.AppendLine(" }"); sbCode.AppendLine(" }"); sbCode.AppendLine("}"); return sbCode.ToString(); } 命令行有个管道符 |,可以把y当成输入:echo y | formatXXX C: 命令行有个管道符 |,可以把y当成输入:echo y | formatXXX C:还打C盘主意?D盘才可能执行成功 至少我没有写format c: 现在几乎都没有A/B盘了。教训就是,要运行任意代码就要有控制权限的思想准备。+1让不太懂技术,只懂业务的最终用户随便执行代码,是一件很可怕的事情如果是要做开发工具,还是从底层开始做吧,用高级语言做开发工具,开发出来的东西还是跳不出高级语言的框架 额,你要不是C# 而是powershell 显示TextBox的多行文本//实现方法如下 private void btn_OK_Click(object sender, EventArgs e) { txt_Change.Location = new Point(0, 0);//设置文本框位置 txt_Change.Multiline = true;//设置文本框显示多行 txt_Change.Width = //设置文本框宽度 this.Width; txt_Change.Height = //设置文本框高度 ClientRectangle.Height - btn_OK.Height-15; } // 使用代码编辑器修改此方法的内容。 private void InitializeComponent() { this.btn_OK = new System.Windows.Forms.Button(); this.txt_Change = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // btn_OK // this.btn_OK.Location = new System.Drawing.Point(103, 92); this.btn_OK.Name = "btn_OK"; this.btn_OK.Size = new System.Drawing.Size(121, 23); this.btn_OK.TabIndex = 0; this.btn_OK.Text = "转换为多行文本框"; this.btn_OK.UseVisualStyleBackColor = true; this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click); // // txt_Change // this.txt_Change.Location = new System.Drawing.Point(103, 47); this.txt_Change.Name = "txt_Change"; this.txt_Change.Size = new System.Drawing.Size(121, 21); this.txt_Change.TabIndex = 1; // // Frm_Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(332, 127); this.Controls.Add(this.txt_Change); this.Controls.Add(this.btn_OK); this.Name = "Frm_Main"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "制作多行文本框"; this.ResumeLayout(false); this.PerformLayout(); } 至少我没有写format c: 现在几乎都没有A/B盘了。教训就是,要运行任意代码就要有控制权限的思想准备。+1让不太懂技术,只懂业务的最终用户随便执行代码,是一件很可怕的事情如果是要做开发工具,还是从底层开始做吧,用高级语言做开发工具,开发出来的东西还是跳不出高级语言的框架+1 C# Code Compiler,google 这个 急救,如何播放一个简单的WAV格式文件? 一直困扰我的问题,帮忙解决一下 结构体指针的使用 读取 treeview checbox选定节点值 研究petshop的一系列问题! 发布一个分页存储过程(请大家看看写得怎么样) ■■升了一个小内裤■■散分 Process.Strat()如何设置路径 300分相送!怎么在WebBrowser中嵌入word! 使用多线程写到同一个文件时出错,如何更改 寻求简历解析思路 WPF中,如何导入带动作的模型
System.Diagnostics.Process.Start("cmd.exe", "/K echo y format B:"); // don't try it ;-)
// 使用 C# 动态编译代码和执行
static void Main(string[] args)
{
// 编译器
CodeDomProvider cdp = CodeDomProvider.CreateProvider("C#"); // 编译器的参数
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.GenerateExecutable = false;
cp.GenerateInMemory = true; // 编译结果
CompilerResults cr = cdp.CompileAssemblyFromSource(cp, HelloWorld()); if (cr.Errors.HasErrors) Console.WriteLine("编译出错!");
else
{
// 编译后的程序集
Assembly ass = cr.CompiledAssembly; // 得到HelloWorld类中的SayHello方法
Type type = ass.GetType("HelloWorld.HelloWorld");
MethodInfo mi = type.GetMethod("SayHello"); // 执行
mi.Invoke(null, null);
}
} // 动态构建的代码
static string HelloWorld()
{
StringBuilder sbCode = new StringBuilder();
sbCode.AppendLine("using System;");
sbCode.AppendLine("namespace HelloWorld");
sbCode.AppendLine("{");
sbCode.AppendLine(" class HelloWorld");
sbCode.AppendLine(" {");
sbCode.AppendLine(" public static void SayHello()");
sbCode.AppendLine(" {");
sbCode.AppendLine(" Console.WriteLine(\"Hello~ World~!\");");
sbCode.AppendLine(" }");
sbCode.AppendLine(" }");
sbCode.AppendLine("}");
return sbCode.ToString();
}
命令行有个管道符 |,可以把y当成输入:
echo y | formatXXX C:
命令行有个管道符 |,可以把y当成输入:
echo y | formatXXX C:还打C盘主意?D盘才可能执行成功
+1
让不太懂技术,只懂业务的最终用户随便执行代码,是一件很可怕的事情
如果是要做开发工具,还是从底层开始做吧,用高级语言做开发工具,开发出来的东西还是跳不出高级语言的框架
//实现方法如下
private void btn_OK_Click(object sender, EventArgs e)
{
txt_Change.Location = new Point(0, 0);//设置文本框位置
txt_Change.Multiline = true;//设置文本框显示多行
txt_Change.Width = //设置文本框宽度
this.Width;
txt_Change.Height = //设置文本框高度
ClientRectangle.Height - btn_OK.Height-15;
}
// 使用代码编辑器修改此方法的内容。
private void InitializeComponent()
{
this.btn_OK = new System.Windows.Forms.Button();
this.txt_Change = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btn_OK
//
this.btn_OK.Location = new System.Drawing.Point(103, 92);
this.btn_OK.Name = "btn_OK";
this.btn_OK.Size = new System.Drawing.Size(121, 23);
this.btn_OK.TabIndex = 0;
this.btn_OK.Text = "转换为多行文本框";
this.btn_OK.UseVisualStyleBackColor = true;
this.btn_OK.Click += new System.EventHandler(this.btn_OK_Click);
//
// txt_Change
//
this.txt_Change.Location = new System.Drawing.Point(103, 47);
this.txt_Change.Name = "txt_Change";
this.txt_Change.Size = new System.Drawing.Size(121, 21);
this.txt_Change.TabIndex = 1;
//
// Frm_Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(332, 127);
this.Controls.Add(this.txt_Change);
this.Controls.Add(this.btn_OK);
this.Name = "Frm_Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "制作多行文本框";
this.ResumeLayout(false);
this.PerformLayout(); }
+1
让不太懂技术,只懂业务的最终用户随便执行代码,是一件很可怕的事情
如果是要做开发工具,还是从底层开始做吧,用高级语言做开发工具,开发出来的东西还是跳不出高级语言的框架
+1