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 7071457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:41:24+00:00 2026-05-28T05:41:24+00:00

I am trying to create a socket in the .nsi file to check whether

  • 0

I am trying to create a socket in the .nsi file to check whether the socket will get created successfully or not to check for port availability. So any help with respect to windows socket programmin in nsis is highly appreciated.

thank u

  • 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-05-28T05:41:25+00:00Added an answer on May 28, 2026 at 5:41 am
    !include LogicLib.nsh
    
    !ifndef AF_INET
    !define AF_INET 2
    !define SOCK_STREAM 1
    !define IPPROTO_TCP 6
    !define INADDR_ANY 0
    !define SOL_SOCKET 0xffff
    !define /math SO_EXCLUSIVEADDRUSE 0xffffffff ^ 0x4
    !endif
    
    Function QueryCanBindToIP4TCPPort
    Exch $0
    Push $1
    Push $2
    Push $0 ;Push port
    System::Alloc 16 ;WSADATA & sockaddr_in
    System::Call 'Ws2_32::WSAStartup(i 2,isr2)i.r0'
    ${If} $0 = 0
        System::Call 'Ws2_32::socket(i ${AF_INET},i ${SOCK_STREAM},i ${IPPROTO_TCP})i.r1 ?e'
        Pop $0
        ${If} $1 <> -1
            System::Call 'Ws2_32::setsockopt(ir1,i ${SOL_SOCKET},i ${SO_EXCLUSIVEADDRUSE},*i 1,i4)i.r0'
            System::Call 'Ws2_32::htons(iss)i.s' ;Convert port (and leaves the original push on the stack)
            ;Skipping htonl on address since INADDR_ANY is 0
            System::Call '*$2(&i2 ${AF_INET},&i2 s,&i4 ${INADDR_ANY},&i8 0)'
            System::Call 'Ws2_32::bind(ir1,ir2,i16)i.r0'
            ${If} $0 = 0
                System::Call 'Ws2_32::listen(ir1,i0)i.r0'
                ;Listening here but once we hit WSACleanup the port will be free again (This is fine if all you need to do is make sure no app is bound to the port at this moment)
                ; System::Call 'Ws2_32::closesocket(ir1)'
            ${EndIf}
        ${EndIf}
        System::Call 'Ws2_32::WSACleanup()' ;Remove this call to leave the port open for the duration of the installer
    ${EndIf}
    System::Free $2
    Pop $2 ;Throw away port
    Pop $2
    Pop $1
    Exch $0
    FunctionEnd
    
    Section
    Push 666
    call QueryCanBindToIP4TCPPort
    Pop $0
    ${If} $0 = 0
        DetailPrint "Bind OK"
    ${Else}
        DetailPrint "Bind Failed!"
    ${EndIf}
    SectionEnd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create my own subclass of socket.socket that will be able to
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I am trying to create a class for network programming. This will create a
So I'm trying to create a simple file transfer method. It's completely working for
I am trying to create a UDP listener that will listen on a separate
Im trying to create a website with Web.py but its not letting me open
I am trying to create a socket of sctp and then retrieve the socket
I am trying to create a socket with a hardcoded IP address and socket
I'm trying to create a new ObjectInputStream using an InputStream retrieved from a Socket.
I am trying to create a ftp client with uploading a file capability. But

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.