当我买一台新电脑时,我写了一个“脚本”来安装一些软件,这种情况经常发生。
有没有比我这样做更好的方法呢? (必须有更好的方法)我是初学者...
C:\Users\myUser\Documents\Visual Studio 2013\Projects\myProject\myProject\bin\x64\Debug
)的已编译二进制文件并将其粘贴到安装程序(setup.exe,thisSetup.exe)并手动将其全部粘贴到新桌面上的文件夹中计算机。以下是C#中的示例代码:
private void install()
{
// Array of the setups.
string[] setup = new string[] { "setup.exe",
"thisSetup.exe",
"anOtherSetup.exe",
};
// Array of the parameters for the setup.
string[] arguments = new string[] { "/passive /norestart",
"/lang=myLang /s",
"-install",
};
// Array to know if the user want to install the program.
Boolean[] idx = new Boolean[setup.Length];
// Initialising the array with false.
for (int z = 0; z < setup.Length - 1; z++)
idx[z] = false;
// If the checkbox for an application is checked, mark it as true in the array.
if (rbtsetup.Checked == true)
idx[0] = true;
if (rbtthisSetup.Checked == true)
idx[1] = true;
if (rbtanOtherSetup.Checked == true)
idx[2] = true;
// Install the applications.
try
{
Process process = new Process();
for (int i = 0; i <= setup.Length - 1; i++)
{
if (idx[i])
{
process.StartInfo.FileName = setup[i];
process.StartInfo.Arguments = arguments[i];
process.Start();
process.WaitForExit();
}
}
}
catch (Exception exception)
lbxInfos.Items.Add(exception.Message);
}