How do i connect to a NTdomain?

Im trying to create a program that will allow me to log onto a username, and password protected NTdomain and copy certain files to a local drive.
Can annyone help me, or point me to where i can find info on doing this.

Or at least tell me if the WNetConnectionDialog1  will work to connect to the NT domain.

I currently know that the WNetAddConnection wont work because it doesnt even pass a username.


Thanks In advance,
Chris
LVL 4
CzehAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wyllikerCommented:
The WNetAddConnection2 should work for you.

CONSTANTS Needed

Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCETYPE_DISK = &H1
Public Const RESOURCETYPE_PRINT = &H2

Public Const CONNECT_UPDATE_PROFILE = &H1



TYPE needed

Public Type NETRESOURCE
        dwScope As Long
        dwType As Long
        dwDisplayType As Long
        dwUsage As Long
        lpLocalName As String
        lpRemoteName As String
        lpComment As String
        lpProvider As String
End Type


DECLARES needed

Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long

Public Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long


Dim NetRes As NETRESOURCE

NetRes.dwType = RESOURCETYPE_DISK
NetRes.lpLocalName = "D:"
NetRes.lpRemoteName = "\\server\share"
NetRes.lpProvider = ""

lpLocalName
Drive letter to Map
Set lpLocalName = "" to NOT map a drive

lpRemoteName
Substitute your remote share path

lpProvider
Set to ""  to let the operating system choose the correct provider


RetCode = WNetAddConnection2( NetRes, "password", "username", 0)

If the username you want to connect with is in a different domain use the following format: "domain\username"

The last parameter - 0 above - can also be CONNECT_UPDATE_PROFILE but only if you are mapping a drive to a share (lpLocalName) and you want the connection to be restored.   In your case I would think you wouldn't need CONNECT_UPDATE_PROFILE.


RetCode will return 0 if it succeeds.


To disconnect from the resource use:

RetCode = WNetCancelConnection2("server\share", 0, TRUE)

Substitute the share path from the WNetAddConnection2 call.

The dwFlags parameter - 0 - can also be set to CONNECT_UPDATE_PROFILE.  This will remove the "restore connection" setting (if it was used in the WNetAddConnection2 call or if you there already was a restorable connection to the share.  In your case I would think you wouldn't need CONNECT_UPDATE_PROFILE.

The fForce parameter - TRUE - will force the connection to close even if there are open files or jobs on the connection.  If you use FALSE, the function will fail if there are any open files or jobs.


Check out the documentation for WNetAddConnection2 and WNetCancelConnection2 for more information.


Let me know if this has been helpful.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CzehAuthor Commented:
Ok, this loks like it will work, but the connection seems to use the default password and user id. is there any way to make WNetAddConnection use only the defined passwords?
0
CzehAuthor Commented:
Ok, this loks like it will work, but the connection seems to use the default password and user id. is there any way to make WNetAddConnection use only the defined passwords?
0
wyllikerCommented:
WNetAddConnection2 will use the username and password that you give it.


Make sure you are NOT using WNetAddConnection.  There is a difference!!!
0
CzehAuthor Commented:
Ok i did some searching and it seems that WNetAddConnection2 will Not allow user names and passwords to be used in Windows 98, this urks me because it makes it hard to test logging onto a NTdomain from home, even though the program will eventually reside on an NT computer.

I will try and test this program on an NT machine, if it works ill give you the points, thanks for the help

P.S. Do you know of anyway to uis Win98 to connect to an NTdomain and allow non-default passwords and user names to be used?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.