代码: 好吧我想用控制台aplication进行配置继承我的代码,我从web重写一些模板问题是输出fille不是我想要的请求帮助:
using System;
using System.IO;
using System.Text;
namespace testwriter
{
class Program
{
static void Main()
{
try
{
FileStream fs = new FileStream("c:\\test\\test.ini", FileMode.Create);
StreamWriter writer = new StreamWriter(fs);
StringBuilder output = new StringBuilder();
int repeat = 0;
do
{
writer.WriteLine("[Settings]");
writer.WriteLine("Domain=test");
writer.WriteLine("Server=test");
writer.WriteLine("Proxy=test");
writer.WriteLine("SRTP=test");
writer.WriteLine("Transport=test");
writer.WriteLine("PublicAddr=test");
writer.WriteLine("ListenPort=test");
writer.WriteLine("DisplayName=test");
writer.WriteLine("var=");
writer.WriteLine("var1=0");
writer.WriteLine("var1=0");
writer.WriteLine("DisableLocalAccount=1");
writer.WriteLine("notification=ringin2.wav");
writer.WriteLine("ActiveTab=0");
Console.WriteLine("yourname: ");
writer.Write("Username=");
output.Append(Console.ReadLine() + "\r\n");
Console.WriteLine ("yourpass:" +"\r\n");
writer.Write("\r\n" + "Password=");
output.Append(Console.ReadLine());
writer.WriteLine(output.ToString());
output.Clear();
Console.WriteLine("Repeat? 1-Yes, 0-No : ");
repeat = Convert.ToInt32(Console.ReadLine());
} while (repeat != 0);
writer.Close();
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
当我编译exe输出时是这个结构:
如何使用户名和密码成为键入的内容。如何在程序关闭后按任意键运行一些.exe
答案 0 :(得分:0)
在writer.WriteLine
方法中输入用户输入:
//for user id
Console.WriteLine("yourname: ");
writer.WriteLine("Username=" + Console.ReadLine());
//for password
Console.WriteLine("yourpass: ");
writer.WriteLine("Password=" + Console.ReadLine());
也无需使用StringBuilder
。
启动新流程。创建Process
的实例:
System.Diagnostics.Process proc = new Process();
proc.StartInfo = new ProcessStartInfo("notepad.exe");
proc.Start();