c#防软件多开源码
By
admin
at 2023-08-23 • 0人收藏 • 524人看过
打开program.cs启动文件, 修改里面的代码:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp3
{
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool createdNew;
Mutex mutex = new Mutex(true, "MyAppMutexabc", out createdNew);
if (!createdNew)
{
// 应用程序已经在运行中,激活其主窗口
Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
if (processes.Length > 0)
{
Process process = processes[0];
ShowWindowAsync(process.MainWindowHandle, SW_RESTORE);
SetForegroundWindow(process.MainWindowHandle);
}
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainForm());//Form1
mutex.ReleaseMutex();
}
[DllImport("user32.dll")]
static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
const int SW_RESTORE = 9;
}
}
2 个回复 | 最后更新于 2025-03-17
public static string BytesToString(byte[] bytes)
{
// 移除所有连字符并插入空格
string hexStringWithSpaces = string.Join(" ", bytes.Select(b => b.ToString("X2")));
return hexStringWithSpaces;
}public static byte[] StringToBytes(string str)
{
string[] hexValues = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
// 创建一个字节数组来存储转换后的值
byte[] bytes = new byte[hexValues.Length];
// 遍历字符串数组,将每个16进制字符串转换为字节
for (int i = 0; i < hexValues.Length; i++)
{
bytes[i] = Convert.ToByte(hexValues[i], 16);
}
return bytes;
}登录后方可回帖
public static string BytesToString(byte[] bytes) { // 移除所有连字符并插入空格 string hexStringWithSpaces = string.Join(" ", bytes.Select(b => b.ToString("X2"))); return hexStringWithSpaces; }public static byte[] StringToBytes(string str) { string[] hexValues = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // 创建一个字节数组来存储转换后的值 byte[] bytes = new byte[hexValues.Length]; // 遍历字符串数组,将每个16进制字符串转换为字节 for (int i = 0; i < hexValues.Length; i++) { bytes[i] = Convert.ToByte(hexValues[i], 16); } return bytes; }