Solved

WNetAddConnect & /user:domain\username

Posted on 1998-06-11
2
214 Views
Last Modified: 2008-02-01
Does anyone know how to specify the username and domain for the
WNetAddConnection2 call (or other API)?

For example:

NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = "G:"
NetR.lpRemoteName = "\\share"
WNetAddConnection2(NetR, "pass", NULL, CONNECT_UPDATE_PROFILE)

This would be the same as net use G: \\SERVER\share pass
This is fine under 95/98.


But under NT4, I need to specify the domain & username such as

net use G: \\SERVER\share /user:domain\username pass

How do I do this with VB code?  Is there something else other then
WNetAddConnection2 that can do it?

Please help!
0
Comment
Question by:scottg
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 300 total points
ID: 1463170
The third argument to WNetAddConnection2, which you have set to NULL, is the username.

Good luck!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1463171
I just tried this in a test program, and confirmed that it works.

The one thing I couldn't test is how it processes the "domain\" part of "domain\user". The only machine I have available to test with at the moment is in the same domain as I am, and the connection would succeed even if I put the wrong domain. I am assuming that was because it was trying the default domain when the ine I specified one failed, but I can't prove that. Let me know if you have problems with the domain part, and I will investigate further.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now