Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:29:44+00:00 2026-06-07T15:29:44+00:00

We have Windows Service which will be installed by installer. We have an option

  • 0

We have Windows Service which will be installed by installer. We have an option to allow user to provide a port number and select whether the service must start on completion of installation. We are having a check on installer itself for checking whether the port is open/available.

TcpClient TcpScan = new TcpClient();
TcpScan.Connect("localhost", portno);
if (TcpScan.Connected == true)
{
   TcpScan.Close();
}

My problem is if the user selects the option of not to start the service on installation and then we install another instance on the same machine with the same port as used in first one, then if we start both the services then one of the service will not work.

So is there any way I can check whether the port provided by user is already there in firewall or is already assigned to some other windows service? (Also assume the service can be in stopped state)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:29:45+00:00Added an answer on June 7, 2026 at 3:29 pm

    Finally got the answer by doing some R&D

    string OP = @"C:\Windows\Temp\ExceptionList.txt";
    
    ProcessStartInfo procStartInfo = null;
    
    string command = "netsh advfirewall firewall show rule name=all > " + OP;
    procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
    
    procStartInfo.CreateNoWindow = true;
    procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo = procStartInfo;
    proc.Start();
    proc.WaitForExit();
    
    if (File.Exists(OP))
    {
        StreamReader SR = new StreamReader(OP);
        string FileData = SR.ReadToEnd();
        SR.Close();
    
        //Logic to read the output and then fetch only records which are enabled and have LocalPort
    }
    

    Output (ExceptionList.txt) file contains data in this format

    Rule Name:                            NETTCP
    ---------------------------------------------
    Enabled:                              Yes
    Direction:                            In
    Profiles:                             Domain
    Grouping:                             
    LocalIP:                              Any
    RemoteIP:                             Any
    Protocol:                             TCP
    LocalPort:                            8080
    RemotePort:                           Any
    Edge traversal:                       No
    Action:                               Allow
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WIX installer which will install a Windows Service. I have
I have been made a windows service.in which i have been added project installer.in
i have to develop windows service which will copy files to different servers. So
I have a application written in C#, installed as a [WCF] windows service, which
I'm creating a Wix installer for a windows service which needs to have provided,
I have a Windows service application which I have installed on my machine without
I have a windows service which runs continuously and creates some threads to do
I have a Windows Service which is basically accessing a mailbox and reading the
I have a windows service which fetches data from various datasources and build a
I have two windows application, one is a windows service which create EventWaitHandle and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.