[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Create dummy service for port status check

Posted on 2015-02-05
Medium Priority
Last Modified: 2015-02-13
Hello EE,

I want to create a service that runs any old exe for the purpose of queuing a status for another peice of hardware. In essence , this service will run on port 5555 if disabled , it will invoke an event on another piece of hardware .

I will use the sc create " Some Service" binpath= " C:\path\some.exe" . I tried to create a dummy.exe and save n notepad as "dummy.exe" but the service will fail on start up .. Is there way to do a quick compile for any old exe that will start the service

This is windows 2012 server 64bit
Question by:davesnb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 23

Expert Comment

by:Michael Fowler
ID: 40592953

Author Comment

ID: 40599011
ok great , I have this installed as a service , however I need it to listen on port 5555
LVL 23

Accepted Solution

Michael Fowler earned 2000 total points
ID: 40599464
Here is a tutorial that has the code you can integrate into your service to listen on a selected port


For example

using System;
using System.ServiceProcess;
using System.Diagnostics;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;

namespace MyService
    public class MyService : ServiceBase
		private TcpListener tcpListener;
		private Thread listenThread;
		public MyService()

        protected override void OnStart(string[] args)
            this.EventLog.WriteEntry("MyService Service Has Started");
			this.tcpListener = new TcpListener(IPAddress.Any, 5555);
			this.listenThread = new Thread(new ThreadStart(ListenForClients));

        protected override void OnStop()
            this.EventLog.WriteEntry("MyService Service Has Stopped");

        private void InitializeComponent()
            this.ServiceName = "MyService";
            this.CanStop = true;
            this.AutoLog = false;
            this.EventLog.Log = "Application";
            this.EventLog.Source = "MyService";
		private void ListenForClients()

		  while (true)
			//blocks until a client has connected to the server
			TcpClient client = this.tcpListener.AcceptTcpClient();

			//create a thread to handle communication 
			//with connected client
			Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
		private void HandleClientComm(object client)
		  TcpClient tcpClient = (TcpClient)client;
		  NetworkStream clientStream = tcpClient.GetStream();

		  byte[] message = new byte[4096];
		  int bytesRead;

		  while (true)
			bytesRead = 0;

			  //blocks until a client sends a message
			  bytesRead = clientStream.Read(message, 0, 4096);
			  //a socket error has occured

			if (bytesRead == 0)
			  //the client has disconnected from the server

			//message has successfully been received
			ASCIIEncoding encoder = new ASCIIEncoding();
			System.Diagnostics.Debug.WriteLine(encoder.GetString(message, 0, bytesRead));


Open in new window


Author Comment

ID: 40600685
I am not having much luck building this, I think this is more to do with me being a newbie to programming and visual studio . is it possible to build this for me ?

Author Closing Comment

ID: 40607717
Good walk through

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Resolve DNS query failed errors for Exchange
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question