我正在使用c#.net Microsoft Visual Vtudio .NET Framework 4.5.2版
我真的不想提出这个问题,但是我现在正在编写这个代码,编辑txt文件,然后将编辑后的txt文件写入磁盘并使用cmd和命令“certutil”来加密它。 然后它将在文本文件中的加密行的前端和末尾添加@echo(加密文本代码编辑的内容)>> C:\ users \%username%\ appdata \ file.txt。 也许我可以直接编辑资源文件?但是然后命令“certutil”无法访问该文件,因为它在.exe中。我想我需要将文件写入磁盘,然后执行“certutil”然后将文件读回资源吗?
我想为此制作构建器,所以我/其他人不需要每次都编辑它,然后加密然后编辑蝙蝠,当它将加密的文本发送到appdata并运行它。
我遇到了一些问题,因为我在一周前就开始学习。然后我发现你不能使用gui来获取c然后开始使用visual studio来制作东西。
这是错误:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
string text = Properties.Resources.bindyes;
}
else if(radioButton1.Checked)
{
string text = Properties.Resources.bindno;
}
bool downurl = textBox1;
var downexe = textBox2;
var bindurl = textBox4;
var bindexe = textBox3;
File.WriteAllText("C:\\Users\\Karl\\Desktop\\downloader.bat",);
}
}
}
我想从代码
返回此值if (radioButton2.Checked)
{
string text = Properties.Resources.bindyes;
return text;
}
else if(radioButton1.Checked)
string text = Properties.Resources.bindno;
return text;
{
但是我收到了这个错误:
错误由于'Form1.button1_Click(object,EventArgs)'返回void,因此返回关键字后面不能跟一个对象表达式。
我真的不想问这个问题,但我现在一直在努力争取这一天半/非常糟糕。
有没有解决这个问题?
所以我试着让它更清晰一点。从平板电脑写作
我想使构建器将文件写入文件的正确位置,然后使用cmd来加密文件。然后阅读\在每行“@echo”的前面加上这个,并在每行的末尾我想写“>> c:users \%username%\ appdata \ file.txt
代码的其他部分,如
Certutil decodehex(或decode)c:\ filepath \ file(已解码的文件路径)
所以我想如果statemnt这样,如果radiobox1.checked它将设置文本的字符串 如果(radiobox1.Checked) { String text = Properties.Resources.nobind 其他 String text = Properties.resources.yesbind 返回文字; } 我是从头上写的
然后我想将资源中的文件写入c:\ filepath。 但我不能回答:\
我希望能更好地解释小坑
答案 0 :(得分:0)
如果您正在询问如何将变量text
写入文件,那么您需要做的就是将变量的声明移到if-else之外。在{
.. }
块中声明变量意味着它不存在于外部。
string text; // declare it here
if (radioButton2.Checked)
{
text = Properties.Resources.bindyes;
}
else if (radioButton1.Checked)
{
text = Properties.Resources.bindno;
}
File.WriteAllText("C:\\Users\\Karl\\Desktop\\downloader.bat", text);
答案 1 :(得分:-4)
我不知道C#,但是,我认为您需要将private void button1_Click(object sender, EventArgs e)
更改为private string button1_Click(object sender, EventArgs e)
。因为'无效'意味着你什么都不回来。希望这有帮助。