![](/img/trans.png)
[英]How to copy selected folders, subfolders and files from openFileDialog in c#
[英]Running CMD command on selected files from OpenFileDialog in C#
我是C#的新手,因為我需要為老板做一個簡單的項目。
我想收到的正是:
就這樣。
我已經得到了:
我需要的:
這是我當前的代碼:
{
Process decrypt = new Process();
string processExecutable = @"C:\Windows\System32\cmd.exe";
if (!File.Exists(processExecutable))
throw new ApplicationException(string.Format("The executable file \"{0}\" does not exist.", processExecutable));
decrypt.StartInfo.FileName = processExecutable;
decrypt.StartInfo.Arguments = "/C openssl enc -d -aes-256-cbc -in FILES_IN.enc -out FILES_OUT.mp3 -pass file:./KEY_FILE.bin";
decrypt.StartInfo.UseShellExecute = false;
decrypt.StartInfo.RedirectStandardOutput = true;
decrypt.StartInfo.RedirectStandardError = true;
decrypt.StartInfo.RedirectStandardInput = true;
decrypt.StartInfo.CreateNoWindow = true;
decrypt.Start();
decrypt.BeginOutputReadLine();
decrypt.BeginErrorReadLine();
decrypt.WaitForExit();
decrypt.Close();
}
我應該如何修改它,以便能夠在用戶選擇的文件上使用它? 感謝您的任何幫助。
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog();
ofd.Multiselect = true;
DialogResult dr = ofd.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
foreach (String file in ofd.FileNames)
{
listView1.Items.Add(file);
getCommandlineResult(file, "path1", "path2");
}
}
}
public string getCommandlineResult(string userSelectedFilesToDecrypt, string UserSelectedFilesAlreadyDecrypted,
string user_selected_key_file)
{
string macAddress = string.Empty;
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = @"C:\Windows\System32\cmd.exe";
pProcess.StartInfo.Arguments = "openssl enc - d - aes - 256 - cbc -in " + userSelectedFilesToDecrypt + ".enc -out " +
UserSelectedFilesAlreadyDecrypted + ".mp3 - pass file:./ " +
user_selected_key_file + ".bin";
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true; //hide window
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
return strOutput;
}
您必須自己調整代碼,因為我沒有安裝openssl,但這必須在正確的方向上為您提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.