在安装过程中修改批处理文件 [英] Modify a batch file during setup
本文介绍了在安装过程中修改批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有趣的要求,我需要修改安装文件夹中的批处理文件
在安装过程中数据库详细信息,此批处理文件是安装的一部分。
无论如何都可以这样做。
谢谢,
Shreyas
解决方案
之前我做过类似的事情。
使用directoryinfo获取值。 getfiles(* .bat)或类似的东西你需要这里的文件路径
这是来自内存所以可能会有一点错误,但这是怎么做的。
string batlocation = 。bat location;
string battxt = String .Empty ;
if (File.Exists(batlocation))
{
使用跨度> ( var reader = new StreamReader(batlocation))
{
battxt = reader .ReadToEnd();
// 现在以battxt为单位你拥有bat文件中的所有内容
}
}
现在你可以使用一些字符串替换或搜索或正则表达式来更改bat文件。
然后如果你想写更改只需
这样做
if (File.Exists(batlocation))
{
// 移动旧的.bat文件进行备份
File.Move(batlocation)
// 此移动命令可能是谷歌移动文件的错误。
使用( var writer = new StreamWriter(batlocation))
{
battxt = writer.Write(battxt)
// 现在你用你的chagnes回写新的bat文件
}
}
Hi,
I have an intersting requirement , where i need to modify a batch file in the installtion folder
during setup for DB details , this batch file is part of installtion.
Can this be done anyway.
Thanks,
Shreyas
解决方案
i have done something similar before.
"get the value by using directoryinfo.getfiles(*.bat)" or something like this" u need the path to the file here
this is from memory so there may be little mistakes but this is how to do.
string batlocation=".bat location"; string battxt = String.Empty; if (File.Exists(batlocation)) { using ( var reader = new StreamReader(batlocation)) { battxt = reader.ReadToEnd(); //now in battxt u have everything that was in bat file } }
now u can use some string replace or search or regex to change the bat file.
then if you would like to write changes over just
do like this
if (File.Exists(batlocation)) { //move the old .bat file for backup File.Move(batlocation) //this move command is probably wrong google for move files. using ( var writer = new StreamWriter(batlocation)) { battxt = writer.Write(battxt) //now you write back to new bat file with your chagnes in there } }
这篇关于在安装过程中修改批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文