6
I usually copy the exe
of the way:
C: Users Username source Chatwinforms Appname bin Debug Appname.exe
But when sending it to my colleagues for testing, the browser says that the file is usually dangerous and blocks. After keeping the file and trying to run, Windows Defender locks by default warning that the file may 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 really was some kind of crack, etc... Well I’m a layman, I could be wrong.
Has 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();
}
}
}
}
I believe that because it is not a popular executable the antivirus/firewall will treat as a threat, so many software you downloaded may not have triggered the alert since it is probably part of a trusted list, the output here I believe would simply add your exe to the exclusion list of your Windows Defender: https://support.microsoft.com/pt-br/help/4028485/windows-10-add-an-exclusion-to-windows-defendr-antivirus
– rodrigorf
Really, this about popularity makes sense.
– Raizant
When you use Tcpclient or any derivative, Voce needs to insert permisao into the firewall.
– HudsonPH