【发布时间】:2020-09-27 19:16:11
【问题描述】:
所以我试图在 C# VS Studio 2019 中编写一个脚本,其中用户输入要使用 7zip 加密的文件并选择他们的密码等,使用字符串来决定密码和要加密的文件。它将作为“encryptedfilehere.7z”保存到 c:\ 驱动器。问题是我正在努力正确格式化代码:
private string button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Assuming 7-zip is installed in C:\\Program Files\\7-Zip\\. If error message appears 7-zip is not installed in this driectory, it needs to be so.");
string sourceName = textBox1.Text;
string targetName = "c:\\encryptedmessagehere.7z";
// 1
// Initialize process information.
//
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "C:\\Program Files\\7-Zip\\7z.exe";
// 2
// Use 7-zip
// specify a=archive and -tgzip=gzip
// and then target file in quotes followed by source file in quotes
//
p.Arguments = "a -tgzip \"" + targetName + "\" \"" + sourceName + "\\" Form2.verify;
p.WindowStyle = ProcessWindowStyle.Hidden;
// 3.
// Start process and wait for it to exit
//
Process x = Process.Start(p);
x.WaitForExit();
}
密码是 Form2.verify,因为它需要用户通过名为 verify 的字符串以另一种形式输入的密码。返回的错误是:
错误 CS0161 'Form7.button2_Click(object, EventArgs)': 并非所有代码路径都返回值
使用 Form2.verify 作为密码:
错误 CS0201 只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句 ByteOribtPrivacyCannon C:\Users\keife\Downloads\ByteOrbitPrivacyCannon (2)\UniveralWindowsTextPGP\UniveralWindowsTextPGP\Form7.cs 48 Active
感谢您的帮助,谢谢。
【问题讨论】:
-
错误信息很简单。原因已经在 Stack Overflow 上被讨论到死。有关示例,请参见副本。对于您的第二个错误(这是一个完全不同的问题...不要在一个帖子中问两个问题),请执行您应该为第一个错误做的事情,即搜索该站点(或仅使用您最喜欢的网络搜索)有关错误消息的确切文本。您将获得丰富的信息。
标签: c# .net visual-studio aes 7zip