Can WinService map to network drive using WNetAddConnection2?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Can WinService map to network drive using WNetAddConnection2?

  1. #1
    Join Date
    Jan 2006
    Posts
    3

    Can WinService map to network drive using WNetAddConnection2?

    Hello,

    I'm coding a windows service that needs to map multiple network drives so they can be accessed later. I'm using WNetAddConnection2 to connect to the network drives with the following NETRESOURCE:

    nr = New NETRESOURCE
    nr.lpRemoteName = UNCPath
    nr.lpLocalName = Nothing
    strUsername = Nothing
    strPassword = Nothing
    nr.dwType = RESOURCETYPE_DISK

    The exact same code works if I'm using Win32 Forms (verified using NET USE command to show all connections to my machine). But when I use the code in Windows Service, the WNetAddConnection2 returns the value of 0 which means 'successful operation' and when I check available connection of my machine using NETUSE the connection is not listed. What gives? the Windows service is running under my account and has privilage to the network connection. I'm coding in VB.NET Please point to me what I did wrong. Thanks.
    Last edited by btymer; 01-31-2006 at 02:00 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jan 2006
    Posts
    3
    Hi Phil,

    Thanks for the pointer. Correct me if I'm wrong, but the article I think is discussing not to use a mapped letter drive and use UNC instead.

    "A service (or any process that is running in a different security context) that must access a remote resource should use the Universal Naming Convention (UNC) name to access the resource. "

    I did a UNC path in my code and did not assign any drive letter. Any help is appreciated. Thanks.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    If you're using a UNC path, why do you need WNetAddConnection? You should be able to simply open the desired file.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Jan 2006
    Posts
    3
    I'm sorry. I should have been more specific in my application. I'm using the FileSystemWatcher to monitor network drives, and therefore I would like to maintain connection to them.

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You might see if any of these helps:
    http://www.google.com/search?q=windo...esystemwatcher
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. map network drive
    By Michael C in forum VB Classic
    Replies: 3
    Last Post: 07-30-2002, 03:15 AM
  2. How can I map a UNC path to a network drive using API from VB?
    By Filipo Novo Mór in forum VB Classic
    Replies: 3
    Last Post: 02-07-2002, 05:48 AM
  3. How can I map a UNC path to a network drive using API from VB?
    By Filipo Novo Mór in forum VB Classic
    Replies: 0
    Last Post: 02-05-2002, 12:36 PM
  4. Map network drive using code?
    By Bragi Fannar Sigurđsson in forum VB Classic
    Replies: 12
    Last Post: 04-07-2000, 03:06 PM
  5. Map network drive using code?
    By Bragi Fannar Sigurđsson in forum VB Classic
    Replies: 0
    Last Post: 04-07-2000, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center