LogonUser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ZhangZQ

    LogonUser

    If I want to access the shared folder in other Windows PC, a popup dialog
    will popup to input the username and password.

    Is it possible to access the files in shared folder in coding without the
    popup dialog if I have the user name and password in that host pc?

    For examples, I want to open the file in a host, \\host\files\fi le.cpp,
    fopen(\\\host\\ files\file.cpp, 'r'); Is it possible? Should I use the
    LogonUser() first?

    Thanks.


  • pawar

    #2
    Re: LogonUser

    Yes , if \\host requires it , you should access the file under that user's
    credentials.

    "ZhangZQ" <zhangzq71@hotm ail.com> wrote in message
    news:#$YXiH6lDH A.2244@TK2MSFTN GP12.phx.gbl...[color=blue]
    > If I want to access the shared folder in other Windows PC, a popup dialog
    > will popup to input the username and password.
    >
    > Is it possible to access the files in shared folder in coding without the
    > popup dialog if I have the user name and password in that host pc?
    >
    > For examples, I want to open the file in a host, \\host\files\fi le.cpp,
    > fopen(\\\host\\ files\file.cpp, 'r'); Is it possible? Should I use the
    > LogonUser() first?
    >
    > Thanks.
    >
    >[/color]


    Comment

    • ZhangZQ

      #3
      Re: LogonUser

      yes, can you show me the example code to do that?
      I want to know which functions should be used?

      Thank you very much!


      "pawar" <NoSpam@pleas e> wrote in message
      news:OEq0Qj7lDH A.2364@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Yes , if \\host requires it , you should access the file under that[/color]
      user's[color=blue]
      > credentials.
      >
      > "ZhangZQ" <zhangzq71@hotm ail.com> wrote in message
      > news:#$YXiH6lDH A.2244@TK2MSFTN GP12.phx.gbl...[color=green]
      > > If I want to access the shared folder in other Windows PC, a popup[/color][/color]
      dialog[color=blue][color=green]
      > > will popup to input the username and password.
      > >
      > > Is it possible to access the files in shared folder in coding without[/color][/color]
      the[color=blue][color=green]
      > > popup dialog if I have the user name and password in that host pc?
      > >
      > > For examples, I want to open the file in a host, \\host\files\fi le.cpp,
      > > fopen(\\\host\\ files\file.cpp, 'r'); Is it possible? Should I use the
      > > LogonUser() first?
      > >
      > > Thanks.
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Chris P.

        #4
        Re: LogonUser

        "ZhangZQ" <zhangzq71@hotm ail.com> wrote[color=blue]
        > If I want to access the shared folder in other Windows PC, a popup dialog
        > will popup to input the username and password.
        >
        > Is it possible to access the files in shared folder in coding without the
        > popup dialog if I have the user name and password in that host pc?
        >
        > For examples, I want to open the file in a host, \\host\files\fi le.cpp,
        > fopen(\\\host\\ files\file.cpp, 'r'); Is it possible? Should I use the
        > LogonUser() first?[/color]

        You don't have to do a LogonUser() unless the creditials are going to
        conflict with what the process is running as.

        You need to do WNetAddConnecti on2()

        WNetAddConnecti on2(
        "\\\\host\\file s",
        "password",
        "username",
        dwFlags
        );

        If you want it to prompt the user if the user/pass you give it fails set the
        flags to CONNECT_INTERAC TIVE.


        Comment

        • ZhangZQ

          #5
          Re: LogonUser

          Thank you, let me try.

          "Chris P." <msdn@chrisnet. net> wrote in message
          news:uAMo5q%23l DHA.1004@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > "ZhangZQ" <zhangzq71@hotm ail.com> wrote[color=green]
          > > If I want to access the shared folder in other Windows PC, a popup[/color][/color]
          dialog[color=blue][color=green]
          > > will popup to input the username and password.
          > >
          > > Is it possible to access the files in shared folder in coding without[/color][/color]
          the[color=blue][color=green]
          > > popup dialog if I have the user name and password in that host pc?
          > >
          > > For examples, I want to open the file in a host, \\host\files\fi le.cpp,
          > > fopen(\\\host\\ files\file.cpp, 'r'); Is it possible? Should I use the
          > > LogonUser() first?[/color]
          >
          > You don't have to do a LogonUser() unless the creditials are going to
          > conflict with what the process is running as.
          >
          > You need to do WNetAddConnecti on2()
          >
          > WNetAddConnecti on2(
          > "\\\\host\\file s",
          > "password",
          > "username",
          > dwFlags
          > );
          >
          > If you want it to prompt the user if the user/pass you give it fails set[/color]
          the[color=blue]
          > flags to CONNECT_INTERAC TIVE.
          >
          >[/color]


          Comment

          • Chris P.

            #6
            Re: LogonUser

            Wait! I made a mixtake. The first parameter is the NETRESOURCE structure,
            not just a path.



            "ZhangZQ" <zhangzq71@hotm ail.com> wrote[color=blue]
            > Thank you, let me try.
            >
            > "Chris P." <msdn@chrisnet. net> wrote in message
            > news:uAMo5q%23l DHA.1004@TK2MSF TNGP09.phx.gbl. ..[color=green]
            > > "ZhangZQ" <zhangzq71@hotm ail.com> wrote[color=darkred]
            > > > If I want to access the shared folder in other Windows PC, a popup[/color][/color]
            > dialog[color=green][color=darkred]
            > > > will popup to input the username and password.
            > > >
            > > > Is it possible to access the files in shared folder in coding without[/color][/color]
            > the[color=green][color=darkred]
            > > > popup dialog if I have the user name and password in that host pc?
            > > >
            > > > For examples, I want to open the file in a host,[/color][/color][/color]
            \\host\files\fi le.cpp,[color=blue][color=green][color=darkred]
            > > > fopen(\\\host\\ files\file.cpp, 'r'); Is it possible? Should I use the
            > > > LogonUser() first?[/color]
            > >
            > > You don't have to do a LogonUser() unless the creditials are going to
            > > conflict with what the process is running as.
            > >
            > > You need to do WNetAddConnecti on2()
            > >
            > > WNetAddConnecti on2(
            > > "\\\\host\\file s",
            > > "password",
            > > "username",
            > > dwFlags
            > > );
            > >
            > > If you want it to prompt the user if the user/pass you give it fails set[/color]
            > the[color=green]
            > > flags to CONNECT_INTERAC TIVE.
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • childman

              #7
              Re: LogonUser


              NETRESOURCE nr;
              ZeroMemory(&nr, sizeof(NETRESOU RCE));
              nr.dwScope = RESOURCE_GLOBAL NET;
              nr.dwType = RESOURCETYPE_AN Y;
              nr.lpLocalName = "";
              nr.lpRemoteName = (LPTSTR)"\\\\ho st\\files";
              nr.lpProvider = NULL;
              WNetAddConnecti on2(&nr,pszPass ,pszUserName,NU LL);
              FILE* fp;
              fp = fopen("\\\\host \\files\file.cp p", 'r');


              Comment

              • ZhangZQ

                #8
                Re: LogonUser

                it is good, it runs, thank you very much!

                "childman" <childman@163.c om> wrote in message
                news:OfbWteDmDH A.3700@TK2MSFTN GP11.phx.gbl...[color=blue]
                >
                > NETRESOURCE nr;
                > ZeroMemory(&nr, sizeof(NETRESOU RCE));
                > nr.dwScope = RESOURCE_GLOBAL NET;
                > nr.dwType = RESOURCETYPE_AN Y;
                > nr.lpLocalName = "";
                > nr.lpRemoteName = (LPTSTR)"\\\\ho st\\files";
                > nr.lpProvider = NULL;
                > WNetAddConnecti on2(&nr,pszPass ,pszUserName,NU LL);
                > FILE* fp;
                > fp = fopen("\\\\host \\files\file.cp p", 'r');
                >
                >[/color]


                Comment

                • Arkady Frenkel

                  #9
                  Re: LogonUser

                  If you need programmaticall y make share directory "files" use
                  NetShareAdd() for that
                  Arkady

                  "ZhangZQ" <zhangzq71@hotm ail.com> wrote in message
                  news:#GbBNDEmDH A.2424@TK2MSFTN GP10.phx.gbl...[color=blue]
                  > it is good, it runs, thank you very much!
                  >
                  > "childman" <childman@163.c om> wrote in message
                  > news:OfbWteDmDH A.3700@TK2MSFTN GP11.phx.gbl...[color=green]
                  > >
                  > > NETRESOURCE nr;
                  > > ZeroMemory(&nr, sizeof(NETRESOU RCE));
                  > > nr.dwScope = RESOURCE_GLOBAL NET;
                  > > nr.dwType = RESOURCETYPE_AN Y;
                  > > nr.lpLocalName = "";
                  > > nr.lpRemoteName = (LPTSTR)"\\\\ho st\\files";
                  > > nr.lpProvider = NULL;
                  > > WNetAddConnecti on2(&nr,pszPass ,pszUserName,NU LL);
                  > > FILE* fp;
                  > > fp = fopen("\\\\host \\files\file.cp p", 'r');
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  Working...