Discussion:
NetDfsSetClienIinfo question
(too old to reply)
Rodrigo Verissimo
2005-03-01 19:02:57 UTC
Permalink
Hi groups, i am trying to create a little app used to force the use of a
specified DFS root referral. I have seen people advising that it could be
done, However i am trying to do wrap this function in VB.
However i always get error 2662 " There is no DFS name whose entry path
matches the input Entry Path"
strings need to be wide so i use strconv, besides this strinc to pointer
conversion is implicit so i don't see what i am missing...
Thanksfor any assistance.

Here is the code :

Private Declare Function NetDfsSetClientInfo Lib "netapi32.dll" ( _
ByVal DfsEntryPath As String, _
ByVal servername As String, _
ByVal ShareName As String, _
ByVal level As Long, _
ByRef Buffer As DFS_INFO_101) As Long

Private Type DFS_INFO_101
State As Long
End Type

Private Sub Form_Load()

Dim stateDFS As DFS_INFO_101

stateDFS.State = 4
' 4 means ACTIVE

Dim rootdfs As String
Dim serverdfs As String
Dim targetdfs As String
Dim ret as long


rootdfs = \\domain.com\dfsrootname
serverdfs = "server"
targetdfs = \\server\roottarget


rootdfs = StrConv(", vbUnicode)
serverdfs = StrConv(serverdfs, vbUnicode)
targetdfs = StrConv(targetdfs, vbUnicode)


ret = NetDfsSetClientInfo(rootdfs, serverdfs, targetdfs, 101, stateDFS)

End sub
Randy Birch
2005-03-02 00:19:06 UTC
Permalink
Personally, I'd try either use byte arrays for the strings (declaring the
API string members As Long and passing the address of the byte array), or
define those as Byte() as pass the byte array. Also, you've specified "" as
the rootdfs member in the code -- was that just a typo? The MSDN states
that member is mandatory, and must be in proper format.

Also, since you're using the 101 structure there is no need to go through
hoops for the buffer parameter -- just declare it As Any (no byval) and pass
a long value rather than the UDT.

(The MSDN must be wrong, as the version I'm using has the Buffer parameter
identified as an [IN] data type, meaning it would be passed ByVal. This
contradicts both the description of the parameter (a buffer that receives
the data), as well as convention for APIs returning Levelx data.)
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"Rodrigo Verissimo" <***@nodomain.com> wrote in message news:***@TK2MSFTNGP15.phx.gbl...
: Hi groups, i am trying to create a little app used to force the use of a
: specified DFS root referral. I have seen people advising that it could be
: done, However i am trying to do wrap this function in VB.
: However i always get error 2662 " There is no DFS name whose entry path
: matches the input Entry Path"
: strings need to be wide so i use strconv, besides this strinc to pointer
: conversion is implicit so i don't see what i am missing...
: Thanksfor any assistance.
:
: Here is the code :
:
: Private Declare Function NetDfsSetClientInfo Lib "netapi32.dll" ( _
: ByVal DfsEntryPath As String, _
: ByVal servername As String, _
: ByVal ShareName As String, _
: ByVal level As Long, _
: ByRef Buffer As DFS_INFO_101) As Long
:
: Private Type DFS_INFO_101
: State As Long
: End Type
:
: Private Sub Form_Load()
:
: Dim stateDFS As DFS_INFO_101
:
: stateDFS.State = 4
: ' 4 means ACTIVE
:
: Dim rootdfs As String
: Dim serverdfs As String
: Dim targetdfs As String
: Dim ret as long
:
:
: rootdfs = \\domain.com\dfsrootname
: serverdfs = "server"
: targetdfs = \\server\roottarget
:
:
: rootdfs = StrConv(", vbUnicode)
: serverdfs = StrConv(serverdfs, vbUnicode)
: targetdfs = StrConv(targetdfs, vbUnicode)
:
:
: ret = NetDfsSetClientInfo(rootdfs, serverdfs, targetdfs, 101, stateDFS)
:
: End sub
:
:
Loading...