❔ Win service error..

public static String GetPcName()
{
string hostName = System.Net.Dns.GetHostName();

return hostName;

}

public static String GetMacAddr()
{
string MacAddr = (from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault();

return MacAddr;
}
public static String GetPcName()
{
string hostName = System.Net.Dns.GetHostName();

return hostName;

}

public static String GetMacAddr()
{
string MacAddr = (from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault();

return MacAddr;
}
public static String GetPcName()
{
string hostName = System.Net.Dns.GetHostName();

return hostName;

}

public static String GetMacAddr()
{
string MacAddr = (from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault();

return MacAddr;
}
public static String GetPcName()
{
string hostName = System.Net.Dns.GetHostName();

return hostName;

}

public static String GetMacAddr()
{
string MacAddr = (from nic in NetworkInterface.GetAllNetworkInterfaces() where nic.OperationalStatus == OperationalStatus.Up select nic.GetPhysicalAddress().ToString()).FirstOrDefault();

return MacAddr;
}
i wonder why win32 service does not work well.. this code works well in not service i don't know what's the problem
40 Replies
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
어부지망생
어부지망생OP2y ago
help... plz
HimmDawg
HimmDawg2y ago
So you say, this code works fine in your IDE, but you wanna run it as a windows service, where it doesn't work? (also, I'll just assume, that the duplicate code above is not on purpose)
어부지망생
어부지망생OP2y ago
when i execute this code as win service, port opens successfully, but send data doesn't work..
HimmDawg
HimmDawg2y ago
Send data
Can we see some of the code? The above code just retrieves some device information and doesn't send data fluffyFoxThink
어부지망생
어부지망생OP2y ago
sry i mean device info i don't need to send data 🙂 and thanks for helping me
HimmDawg
HimmDawg2y ago
Yeah, I give my best. But we need more information. Do you know what exactly does not work? Does it not retrieve information, i.e. those functions return null? Does it crash?
어부지망생
어부지망생OP2y ago
I know Winservice doesnt support log function so i cant check specific reason why it doesnt work.. is there any way to check log??
HimmDawg
HimmDawg2y ago
By default, the service should write into the application event log, have you checked that? fluffyFoxThink you can write your own event log https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-log-information-about-services
어부지망생
어부지망생OP2y ago
Oh thanks!! i'll try it later when i go back home and tell u specific info where does not work 🙂 Maybe 2h later?? I'll be back soon😀 i wrote event log and installed winservice but when i install them, it says error 1053... i searched internet but i can't find answer.. do u know how to fix it? when u come back, mention me plz 🙂
HimmDawg
HimmDawg2y ago
What's the full error saying? Also, can you show the code?
어부지망생
어부지망생OP2y ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace RemoteComputerService
{
internal static class Program
{
/// <summary>
/// 해당 애플리케이션의 주 진입점입니다.
/// </summary>
static void Main()
{
PcRegister pcRegister= new PcRegister();

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new PcRegister()
};
ServiceBase.Run(ServicesToRun);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace RemoteComputerService
{
internal static class Program
{
/// <summary>
/// 해당 애플리케이션의 주 진입점입니다.
/// </summary>
static void Main()
{
PcRegister pcRegister= new PcRegister();

ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new PcRegister()
};
ServiceBase.Run(ServicesToRun);
}
}
}
Error 1053 the service did not respond to the start or control request
HimmDawg
HimmDawg2y ago
This can have a couple of reasons. Best would be to check if the error log has useful information
어부지망생
어부지망생OP2y ago
u mean event viewer?
HimmDawg
HimmDawg2y ago
Yes
어부지망생
어부지망생OP2y ago
nono not this one sry i can't see any log in here..
어부지망생
어부지망생OP2y ago
HimmDawg
HimmDawg2y ago
Something with an ID of 1026 perhaps?
어부지망생
어부지망생OP2y ago
ah how can i fix it?
HimmDawg
HimmDawg2y ago
어부지망생
어부지망생OP2y ago
is it event viewer?
HimmDawg
HimmDawg2y ago
Yes
어부지망생
어부지망생OP2y ago
i cant find that one in here 😦
HimmDawg
HimmDawg2y ago
this one, no?
어부지망생
어부지망생OP2y ago
어부지망생
어부지망생OP2y ago
yes but i cant type 1026 ah sry i found solution oh Application: dotnet.exe CoreCLR Version: 7.0.222.60605 .NET Version: 7.0.2 Description: The process was terminated due to an unhandled exception. Exception Info: System.Net.Sockets.SocketException (10048): 각 소켓 주소(프로토콜/네트워크 주소/포트)는 하나만 사용할 수 있습니다. at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, Boolean disconnectOnFailure, String callerName) at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at System.Net.Sockets.TcpListener.Start(Int32 backlog) at Server.PcRegister() i think this error means i had already bind port i think i need to kill process using 50520 port I killed process and restarted service but same Ah.. sry for too much question...
HimmDawg
HimmDawg2y ago
각 소켓 주소(프로토콜/네트워크 주소/포트)는 하나만 사용할 수 있습니다
what does this say exactly? Oh, already bound?
어부지망생
어부지망생OP2y ago
yhea so i killed the task but i can't solve the problem
HimmDawg
HimmDawg2y ago
can you try the following?
server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
before
server.Bind(ipep);
server.Bind(ipep);
어부지망생
어부지망생OP2y ago
ok wait a second plz same 😦
HimmDawg
HimmDawg2y ago
Is the port important or can it be chosen freely?
어부지망생
어부지망생OP2y ago
important because i used 50520 in android application How do I create a thread in C#? i think its the problem
HimmDawg
HimmDawg2y ago
Thread thread = new Thread(ThreadStart)
Thread thread = new Thread(ThreadStart)
where ThreadStart can be some delegate. Are you sure that's the problem? fluffyFoxThink
어부지망생
어부지망생OP2y ago
I'll do it tomorrow i'm so tired 😦 Have a nice day and see u tomorrow 🙂 I'll try more and ask u about it thank you very much today !!
HimmDawg
HimmDawg2y ago
Have a good and rejuvenating sleep fedora
어부지망생
어부지망생OP2y ago
i successfully created custom log and now i can check log !!
어부지망생
어부지망생OP2y ago
어부지망생
어부지망생OP2y ago
as u can see, port opened but send info has an error
while (true)
{
Socket client = sock.Accept();


eventLog1.WriteEntry("connected");

string HostInfo = (GetPcName() + "// AND //" + GetMacAddr());
int idata = client.Send(Encoding.ASCII.GetBytes(HostInfo));
String data = idata.ToString();
eventLog1.WriteEntry(data);
}
while (true)
{
Socket client = sock.Accept();


eventLog1.WriteEntry("connected");

string HostInfo = (GetPcName() + "// AND //" + GetMacAddr());
int idata = client.Send(Encoding.ASCII.GetBytes(HostInfo));
String data = idata.ToString();
eventLog1.WriteEntry(data);
}
error in here I think sock.accept has an error sk i cant see connected log Is there any problem with code? Plz mention me after u comeback 🙂
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server