前言
类似于bat脚本,能够自动执行一些任务,但是对bat不熟悉,因此选择使用C#来实现,具体是能够通过执行特定的语句实现对文件的读写与执行
代码
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace CrackDown_BIOS
{
class Program
{
static async Task Main(string[] args)
{
try
{
var error = true;
var output = "";
var outerror = "";
string path = "";
var passwords = ReadFromLine(path,0);
var count = 0;
foreach (var word in passwords)
{
string password = word;
string strCMD = "& " + "\"" + @"C:\Program Files (x86)\HP\BIOS Configuration Utility\HPQPswd.exe" + "\" " + "/s /p" + "\"" + password + "\"" + " /f" + "\"" + "sample password.bin" + "\" exit";
Console.WriteLine(strCMD);
string crackCMD = "& " + "\"" + @"C:\Program Files (x86)\HP\BIOS Configuration Utility\BiosConfigUtility.exe" + "\" " + "/nspwdfile:" + "\"" + "\"" + " /cspwdfile:" + "\"" + "sample password.bin" + "\" exit";
Console.WriteLine(crackCMD);
if (!error)
{
}
else
{
Console.WriteLine("PASSWORD IS: " + word);
}
outerror = "";
output = "";
count++;
}
count++;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\r\n跟踪;" + ex.StackTrace);
}
}
private string GenerateWord()
{
try {
string path = "xxxx";
}
catch (Exception e) {
}
return "";
}
private static List<string> ReadFromLine(string fullPath, int lineNum)
{
int i = 0;
var content = new List<string>();
FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default))
{
var current = string.Empty;
while ((current = sr.ReadLine())!=null) {
i++;
content.Add(current);
if (i != 0)
{
lineNum = i;
}
}
}
return content;
}
}
}
参考链接
Process.StandardError 属性 C#程序调用CMD执行命令
|