1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: C++ Windows 7 socket problem

Discussion in 'Software Development' started by Nickolodeon, Apr 27, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. Nickolodeon

    Nickolodeon Thread Starter

    Joined:
    Apr 14, 2010
    Messages:
    35
    Hi, guys.
    I'm trying to use socket(...) function in Windows 7 and get WSAEACCES=Permission denied
    error right away. Although I develop in VS and logged in into Win7 under my (admin) account, programmatic call to function (the name of it I can't recall, code is not on this machine) that returns whether user is an admin yields FALSE, that is I am not admin which is weird. I think it is the reason why socket fails.
    Any suggestions?
    Also I am looking for a way to communicate through sockets without priv_level system interference, b/c/ I need it to run under any user account.
     
  2. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    What kind of socket are you trying to create?

    On this page, it states this about your error:
    I'm helping to port a network-aware Windows app to Windows 7 so your issue is of interest to me. :)

    Peace...
     
  3. Nickolodeon

    Nickolodeon Thread Starter

    Joined:
    Apr 14, 2010
    Messages:
    35
    People say, you should setup linker options to bypass UAC, and NOT enable UAC (2 options).
    Also starting VS by "Run as administrator" menu helps. I'm going to experiment with linker options though, because I need any user to run the app, not just admin.
     
  4. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    That doesn't sound like a "well behaved" approach but if it works for you, more power to you. :)

    Good luck!

    Peace...
     
  5. Nickolodeon

    Nickolodeon Thread Starter

    Joined:
    Apr 14, 2010
    Messages:
    35
    Well, requiring to run the app as an admin isn't exactly a neat way to overcome the problem, I agree.
    But tweaking the linker configs is. In fact it is a prefered way to do it. I haven't laid my hands on it yet, though) and hope tha theory will be in accordance with practice
     
  6. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    Think about it. Your web browser opens all kinds of socket connections but it doesn't require any special privileges to run and for the browser to circumvent the UAC would be a HUGE security hole, given how the browser can serve as the ideal entry point for malware.

    Also, if you installed an older browser (think pre-Windows 7) it would probably still be able to access web sites, which means it would still be able to open socket connections.

    You never answered my question above. Are you creating some kind of special or "raw" socket?

    I'm not telling you NOT to use the linker flags you found mentioned elsewhere. I'm just saying that doesn't sound like a "well-behaved" solution to the problem you're having.

    If Windows 7 is preventing you from creating the type of socket you need in the manner you're currently doing it, there must be a reason for it (whether that reason is good or bad). Circumventing the security system doesn't sound like a good approach but that's without knowing anything about the kind of socket you're looking to create.

    In the app I'm helping to port, we're not looking to create "raw" sockets or anything of that nature. So, we probably won't run into the issue you're having. The MSDN doc on the "socket()" system call (or is it a library call on Windows?) states:
    Peace...
     
  7. Nickolodeon

    Nickolodeon Thread Starter

    Joined:
    Apr 14, 2010
    Messages:
    35
    Thanks for that quote from MSDN.
    Yes, I do use raw sockets. I need to scan some ports to determine if they are not in use, so my app can use them. Raw socket connections worked fine. The thing is that I also port the app from XP to win7 and have not experienced any problems on xp. I need it to work on win7 as well (and it seems I'm getting there))
    I'm sure the reason exists for implementing such a restriction in Win7. However I don't see more "legal" solutions yet.
     
  8. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    I'm not running my W7 box right now but does running the "ping" command invoke the UAC?

    I also found this on the MSDN site:
    I know some apps, like Malwarebytes, which require elevated privileges invoke the UAC when you run them. I guess you want your app to run without invoking the UAC, if the UAC is enabled on that system, right? Invoking the UAC from a standard user account still allows that user to run the app, it's just they have to permit the app to run.

    Have you tried the linker options to not enable UAC support in your app and does it work for you? Can you install Wireshark and see if it invokes the UAC on your W7 system when it runs?

    I know, I know, I'm getting away from the point of the thread. :)

    Peace...
     
  9. Nickolodeon

    Nickolodeon Thread Starter

    Joined:
    Apr 14, 2010
    Messages:
    35
    I have tried setting up linker options and am glad to see it's working.
    The idea here is to let users who used the app and upgraded their OS to win7 continue working without meddling around with some UAC.
    What are you using sockets for?
     
  10. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    We're porting a Windows client of a niche commercial app to Visual Studio 2008 on Windows 7. The Windows client uses a proprietary communications protocol that uses TCP/IP as its transport. So, we use TCP sockets for communication with our server components running on various platforms. :)

    Good luck with your app!

    Peace...
     
  11. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/919618

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice