CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: WinSock listen() method seems to be blocked only after a reboot

    Depends upon what credentials are used from Task Scheduler to start the program. Why are you starting it from Task Manager rather than the more usual ways of starting a program when someone logs on.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.3)

  2. #17
    Join Date
    Nov 2003
    Portland, OR

    Re: WinSock listen() method seems to be blocked only after a reboot

    This is an old application (developed for Windows XP) that has `requireAdministrator`UAC request in the manifest. If I add it to the Windows run key, it won't start because of that. Thus my Band-Aid fix to run it from the task scheduler. (Note that in the future I am planning to re-write this application as a service. In the meantime I'm looking for a solution to its existing users.)

    Here's the XML for the task that does the auto-run at logon:

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
        <Description>This task was created automatically by 'myApp' software.</Description>
        <URI>\Starts 'myApp' at user logon</URI>
        <LogonTrigger id="Trigger_Starts 'myApp' at user logon">
        <Principal id="Author">
      <Actions Context="Author">
    I also made a couple of screenshots with ProcExp of my process itself.

    Here's when I run the app via Windows Explorer and it can receive incoming TCP packets:

    Name:  Capture1_1.jpg
Views: 13
Size:  37.4 KB

    here's the privileges and permissions:

    Name:  Capture1.PNG
Views: 28
Size:  29.9 KB

    And here's when it was run from the Task Scheduler and all incoming TCP packets are blocked:

    Name:  Capture2_1.jpg
Views: 12
Size:  25.6 KB

    here's the privileges and permissions:

    Name:  Capture2.PNG
Views: 31
Size:  29.7 KB

    What's interesting is that there's no difference in them, except the parent process that starts my app: either `svchost.exe` or `explorer.exe`

    Another interesting fact is that the app may sometimes work after a reboot. Like this time, it took me 3 reboots to make it not work. So it sounds like some sort of race condition, but where? Do I need to wait for some library to load before I can call WinSock methods?

  3. #18
    Join Date
    Nov 2003
    Portland, OR

    Re: WinSock listen() method seems to be blocked only after a reboot

    OK. A follow up. Please disregard what I said above... I got it solved.

    It was a race condition in my app. It was reading the port number into a local cache variable after the thread that uses that variable was started, thus creating a race condition.

    Thanks everyone who pitched in!

    PS. I was able to verify it by using this tool.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.