Page 1 of 2
Vista - making network connections
Posted: Mon Mar 24, 2008 7:59 pm
by jvalks
Hello everybody,
Has anyone found out how to connect to a networkshare under Vista? I created a tool which connects to networkshares and it works fine in XP, but it won't work in Vista...
I found the following procedure on the forums:
Code: Select all
Procedure WNetAddConnection(UserName.s,Password.s,ShareName.s,DriveLetter.s,Persistant.l)
;/ Username / Password
;/ Sharename : \\Server\Share
;/ DriveLetter : F:
;/ Persistant : #True or #False
;/ Return 1 if success or 0 if fail
lpNetResource.NETRESOURCE
lpNetResource\dwType=1 ; RESOURCETYPE_DISK
lpNetResource\lpLocalName=@DriveLetter
lpNetResource\lpRemoteName=@ShareName
OpenLibrary(0,"Mpr.dll")
Retour=CallFunction(0,"WNetAddConnection2A",lpNetResource,Password,UserName,Persistant)
CloseLibrary(0)
If Retour=0 : Retour=1 : Else : Retour=0 : EndIf
ProcedureReturn Retour
EndProcedure
And I also tried the same function in Droopy's library but both fail in Vista. According to the information I found on MSDN the function is not changed....
Can anyone help me out here???
Posted: Mon Mar 24, 2008 9:11 pm
by maw
As you said, the function hasn't changed, however some of Vista's security "features" might be causing it. Please post the error code you get from the function, that might give a clue as to the problem!
Posted: Mon Mar 24, 2008 10:24 pm
by jvalks
Well... it does not return any errors! The mapping is just not created.. the result = 0 (Ok!)...
maw wrote:As you said, the function hasn't changed, however some of Vista's security "features" might be causing it. Please post the error code you get from the function, that might give a clue as to the problem!
Posted: Tue Mar 25, 2008 12:00 am
by maw
That's interesting..
I have used WNetAddConnection2 in several programs, though never used any of them against Vista. From Vista x64 to XP it works fine.
I will probably upgrade my home server to Server 2008 later this week, then I can try Vista to Vista and see if it works for me. I'll let you know the results!
Posted: Tue Mar 25, 2008 7:28 am
by jvalks
I'm trying to use it to map a drive from Vista to a W2003 server. It works when running it on a XP machine, but so far not on Vista.
I tried some alternative methodes last night, but no luck so far..
Posted: Wed Apr 02, 2008 8:41 am
by jvalks
I can't get it to work yet...
Posted: Wed Apr 02, 2008 9:31 am
by jpd
Hi jvalks,
I have tested the code on vista and this works without problem!
what for value return "Retour" after call WNetAddConnection2A??
I mean the real value of retour and not the value that the procedure return!
Best
jpd
/Edit
jvalks wrote:Well... it does not return any errors! The mapping is just not created.. the result = 0 (Ok!)...
return 0 is connection successfully!!
I suppose that you map a drive that are in use,
on this case the explorer point to old connection and look that the drive is connected with another precedent resource.
before using wnetaddconnection try to verify if a drive is in use or connected and disconnect or use another drive letter!.
jpd
Posted: Wed Apr 02, 2008 7:47 pm
by jvalks
Ok, things are getting more weirder...
I run a Windows 2003 domain controller in my VMware enviorment to test (I also tested it in our company's netwerk).
This is my test source:
Code: Select all
Procedure xWNetCancelConnection(DriveLetter.s,force.l)
;/ Driveletter : Ex F:
;/ Force = #True or #False ( Deconnect when file is in use )
;/ Return 1 if success or 0 if fail
OpenLibrary(0,"Mpr.dll")
Retour=CallFunction(0,"WNetCancelConnectionA",DriveLetter,force)
CloseLibrary(0)
ProcedureReturn Retour
EndProcedure
Procedure xWNetAddConnection(UserName.s,Password.s,ShareName.s,DriveLetter.s,Persistant.l)
;/ Username / Password
;/ Sharename : \\Server\Share
;/ DriveLetter : F:
;/ Persistant : #True or #False
;/ Return 1 if success or 0 if fail
;CallDebugger
lpNetResource.NETRESOURCE
lpNetResource\dwType=1 ; RESOURCETYPE_DISK
lpNetResource\lpLocalName=@DriveLetter
lpNetResource\lpRemoteName=@ShareName
OpenLibrary(0,"Mpr.dll")
Retour=CallFunction(0,"WNetAddConnection2A",lpNetResource,Password,UserName,Persistant)
CloseLibrary(0)
ProcedureReturn Retour
EndProcedure
result = xWNetCancelConnection("x:",#True)
MessageRequester("Cancel result: ","result: " + Str(result),#PB_MessageRequester_Ok)
result = xWNetAddConnection("testuser","Welkom01","\\server02\bginfo","x:",#True)
MessageRequester("Map result: ","result: " + Str(result),#PB_MessageRequester_Ok)
As expected I receive a 0 return value on both procedures. But I can't see the X: drive in my explorer. When I enter a 'Net use' on the command prompt (on a Vista machine
which is not a member of the test domain!) I see:
Unavailable X: \\server02\bginfo Microsoft Windows Network
Well.... can somebody explain what is going on? The same code works great on my XP machine (no member of the test domain)...
Posted: Thu Apr 03, 2008 7:42 am
by jpd
Hi jvalks,
when you made a connection is needed a full username,
e.x. if the domain name testdom and the user testuser
then
result = xWNetAddConnection("testdom\testuser","Welkom01","\\server02\bginfo","x:",#True)
on standalone server with name server02 use:
result = xWNetAddConnection("server02\testuser","Welkom01","\\server02\bginfo","x:",#True)
Posted: Thu Apr 03, 2008 11:43 am
by jvalks
Thank you very much for your help, I'm going to try this tonight. I post the results here later.
jpd wrote:Hi jvalks,
when you made a connection is needed a full username,
e.x. if the domain name testdom and the user testuser
then
result = xWNetAddConnection("testdom\testuser","Welkom01","\\server02\bginfo","x:",#True)
on standalone server with name server02 use:
result = xWNetAddConnection("server02\testuser","Welkom01","\\server02\bginfo","x:",#True)
Posted: Thu Apr 03, 2008 7:39 pm
by jvalks
I keep the same problem. I used server02\testuser like in the example. I receive an errorstatus 0 (should be ok). No drive visible in the explorer, on the commandline again: unavailable X:
This does not make any sense to me anymore....
**EDIT**
I tried to connect to a XP machine, same problem!!
Posted: Fri Apr 04, 2008 7:51 am
by jvalks
I just tested the same code on a clean installed Vista machine, and it worked... I did some reading last night and found out that this WNetAddconnection2A is a real pain for more developers on the Vista platform...
The next thing what I'm going to try is remove VMWare from my machine (it creates extra virtual network adapters) and try it again.
I will keep you up to date!
Posted: Fri Apr 04, 2008 8:06 am
by jpd
Hi jvalks,
I'm running the same setup as you and running fine...
vista on workgroup then VMware 6 and Win2003 Enterprise Server as domain controller.
I have some question
the programm running with another account as the logged-in user?
if so can you please running this on the same context as logged-on user?
on the Server in eventviewer | security you can see the logon/logoff process by the user can you attach some entry?
the ID 538, 540, 680 and 576 and user "testuser"
Ciao
jpd
Posted: Fri Apr 04, 2008 8:59 am
by jvalks
Don't ask me why, but the source is working now. But only from the compiled version... My mistake that I exepected that this should work from the editor as well
Thank you very much for your help!!
jpd wrote:Hi jvalks,
I'm running the same setup as you and running fine...
vista on workgroup then VMware 6 and Win2003 Enterprise Server as domain controller.
I have some question
the programm running with another account as the logged-in user?
if so can you please running this on the same context as logged-on user?
on the Server in eventviewer | security you can see the logon/logoff process by the user can you attach some entry?
the ID 538, 540, 680 and 576 and user "testuser"
Ciao
jpd
Posted: Fri Apr 04, 2008 9:28 am
by jpd
Hi jvalks,
if this a solution that satisfact then ok.
But the start problem is not solved, this can reappear...
and you dont know why
Ciao
jpd