WNetAddConnection2 - Crzy
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: WNetAddConnection2 - Crzy

  1. #1
    Join Date
    Mar 2017
    Posts
    5

    Lightbulb WNetAddConnection2 - Crzy

    Hi guys

    I've been problem with WNetAddConnection2 if i don't inform nr.lpProvider= NULL; Windows API return invalid password. Why???

    Look below my code

    Original code:

    Code:
    nr.dwScope=RESOURCE_GLOBALNET;
    nr.dwUsage=RESOURCEUSAGE_CONNECTABLE;
    nr.dwType=RESOURCETYPE_ANY;
    nr.lpLocalName=NULL;
    nr.lpRemoteName="\\\\MyComp10";
    nr.lpProvider=NULL;
    net=WNetAddConnection2(&nr,"password","Administrator",CONNECT_UPDATE_PROFILE);
    In this case, with nr.lpProvider=NULL WNetAddConnection2 return invalid password.


    New code:

    Code:
    nr.dwScope=RESOURCE_GLOBALNET;
    nr.dwUsage=RESOURCEUSAGE_CONNECTABLE;
    nr.dwType=RESOURCETYPE_ANY;
    nr.lpLocalName=NULL;
    nr.lpRemoteName="\\\\MyComp10";
    nr.lpProvider="Developer";
    net=WNetAddConnection2(&nr,"password","Administrator",CONNECT_UPDATE_PROFILE);
    In this case, when informed lpProvider, it is ok, no error. Why??

    The more curious is that the problem occurs in only a few workstations. What is going on?

    Thank's
    Last edited by 2kaud; March 28th, 2017 at 12:56 PM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,787

    Re: WNetAddConnection2 - Crzy

    The more curious is that the problem occurs in only a few workstations.
    What is WNetGetProviderName() https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx returning for lpProviderName?
    All advice is offered in good faith only. 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/

    C++17 Compiler: Microsoft VS2017 (15.4.1)

  3. #3
    Join Date
    Mar 2017
    Posts
    5

    Re: WNetAddConnection2 - Crzy

    When i used WNetGetProviderName(), return the same name of lpProvider.

    I made one test in Windows console (command prompt) and the problem occur as well. Look below:

    net use p: \\MyComp10\xml /usereveloper\Administrator <ENTER>
    Enter password: password

    It's ok.


    net use p: \\MyComp10\xml /user:Administrator <ENTER>
    Enter password: password
    Error invalid password

    The problem occur in command line as well. Windows BUG???

    Thank's

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,969

    Re: WNetAddConnection2 - Crzy

    Quote Originally Posted by ejunior View Post
    ...
    The problem occur in command line as well. Windows BUG???
    If you are so sure - try to file it in https://connect.microsoft.com/
    Victor Nijegorodov

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,787

    Re: WNetAddConnection2 - Crzy

    For developer\Administrator, is developer an OU within AD?
    All advice is offered in good faith only. 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/

    C++17 Compiler: Microsoft VS2017 (15.4.1)

  6. #6
    Join Date
    Mar 2017
    Posts
    5

    Re: WNetAddConnection2 - Crzy

    "Developer" is my Domain Controller

    "Administrator" is my Domain Administrator user

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,787

    Re: WNetAddConnection2 - Crzy

    and under what credentials are you trying to use net use? Is \\mycomp10 computer part of the same domain?
    All advice is offered in good faith only. 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/

    C++17 Compiler: Microsoft VS2017 (15.4.1)

  8. #8
    Join Date
    Mar 2017
    Posts
    5

    Re: WNetAddConnection2 - Crzy

    Yes \\Mycomp10 is part of the same domain.

    Domain - Windows 2012
    Mycomp10 - Windows 7

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,787

    Re: WNetAddConnection2 - Crzy

    net use p: \\MyComp10\xml /user : Developer\Administrator

    This uses account administrator on DC Developer to authenticate to \\MyComp10 (the domain administrator account). As \\MyComp10 is part of the domain with correct group membership etc then this is fine.

    net use p: \\MyComp10\xml /user:Administrator

    This uses account Administrator on \\MyComp10 to authenticate (the local adminstrator). If the password for the local Administrator account is different to that of the domain administrator account then the authentication will fail with invalid password. This only occurs on those few workstations where the password for the local administrator account is different to that of the domain administrator account. Note that it is good practice for the local and domain administrator accounts to have different passwords.
    All advice is offered in good faith only. 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/

    C++17 Compiler: Microsoft VS2017 (15.4.1)

  10. #10
    Join Date
    Mar 2017
    Posts
    5

    Re: WNetAddConnection2 - Crzy

    2kuad,

    I agree with you about best practice for domain administrator accounts and local admins in workstation, but in this post "Administrator" is only example name. I have a specific user to execute this operation. The name is SVC.Net-map and have power to maping network e copy files.

    This user exists only in my DC (AD). This is so strange, because I have 10 machines in the domain and three of them do the mapping (net use p: \\MyComp10\xml /user:SVC.Net-map) without complaining of invalid password, but the other seven do not. So crazy....

    Thank's

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,787

    Re: WNetAddConnection2 - Crzy

    I would be looking closely at how the computers are actually members of the AD domain. Is all the DNS, domain membership, group membership etc correct - and what is different between those that work and those that don't.
    All advice is offered in good faith only. 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/

    C++17 Compiler: Microsoft VS2017 (15.4.1)

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

This a Codeguru.com survey!


On-Demand Webinars (sponsored)