I usually copy the exe
of the path:
C: \ Users \ Username \ source \ repos \ ChatWinForms \ AppName \ bin \ Debug \ AppName.exe
But when I send it to my coworkers to test it, the browser says the file is often dangerous and blocks. After holding the file and trying to run, Windows Defender blocks by default warning that the file can be dangerous.
I even heard that this is because the app was not signed, but I've used several unsigned programs and it never happened, only when it was really some kind of crack, etc ... Well I'm a layman, I may be wrong.
Is there a way to minimize this effect without buying a certificate?
Maybe it's because my app uses the network?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ChatWinForms
{
public partial class ChatWinForms : Form
{
private IPAddress address;
private TcpClient client;
private StreamWriter writer;
private StreamReader reader;
private int tcpPort;
private System.Media.SoundPlayer newUser = new System.Media.SoundPlayer(@"c:\Windows\Media\Windows Notify Calendar.wav");
private System.Media.SoundPlayer newMsg = new System.Media.SoundPlayer(@"c:\Windows\Media\Windows Unlock.wav");
private void ConectaServidor()
{
try
{
address = IPAddress.Parse(serverIp.Text);
tcpPort = 25565;
client = new TcpClient();
client.Connect(address, tcpPort);
writer = new StreamWriter(client.GetStream());
reader = new StreamReader(client.GetStream());
writer.WriteLine(userInput.Text);
writer.Flush();
var response = reader.ReadLine();
if (response.Substring(0, 2).Contains("01"))
{
DesconectaServidor();
MessageBox.Show("Esse usuário já está em uso, tente outro nome.", "Usuário em uso.", MessageBoxButtons.OK, MessageBoxIcon.Information);
} else
{
msgBox.AppendText(userInput.Text + response.Substring(3) + "\r\n");
btnConnect.Text = "Desconectar";
btnSend.Enabled = true;
msgText.Enabled = true;
}
}
catch (Exception e)
{
MessageBox.Show("Erro:" + e.Message, "Erro ao se conectar com o Servidor Remoto", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void DesconectaServidor()
{
reader.Close();
client.Close();
msgBox.AppendText("Você foi desconectado..." + "\r\n");
btnConnect.Text = "Conectar";
btnSend.Enabled = false;
msgText.Enabled = false;
}
private void EnviaMensagem()
{
if (msgText.Lines.Length >= 1)
{
writer.WriteLine(msgText.Text);
writer.Flush();
msgBox.AppendText("Você diz: " + msgText.Text + "\r\n");
msgText.Lines = null;
}
msgText.Text = "";
}
private async void RecebeMensagens()
{
while (client.Connected)
{
try
{
var data = await reader.ReadLineAsync();
if (!string.IsNullOrEmpty(data.Substring(3)))
{
if (data.Substring(0, 2).Contains("02"))
{
newUser.Play();
}
if (data.Substring(0, 2).Contains("03"))
{
newMsg.Play();
}
msgBox.AppendText(data.Substring(3) + "\r\n");
}
}
catch (Exception Ex)
{
if (Ex is IOException)
{
DesconectaServidor();
}
if(Ex is ObjectDisposedException)
{
client.Close();
}
}
}
}
public ChatWinForms()
{
InitializeComponent();
}
private void btnSend_Click(object sender, EventArgs e)
{
EnviaMensagem();
}
private void btnConnect_Click(object sender, EventArgs e)
{
if(btnConnect.Text == "Conectar")
{
ConectaServidor();
RecebeMensagens();
} else
{
DesconectaServidor();
}
}
private void msgText_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
EnviaMensagem();
}
}
}
}