Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NetDfsSetClientInfo doesn't work properly

30 views
Skip to first unread message

andrea...@gmail.com

unread,
Feb 23, 2012, 6:51:08 AM2/23/12
to
Hi everybody,
I'm trying to do make a simple API call to modify the DFS cache referral... return code is 0, but no change is persisted. Following the code... There is any point I'm missing?


[DllImport("Netapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int NetDfsAdd(
[MarshalAs(UnmanagedType.LPWStr)]
string DfsEntryPath,
[MarshalAs(UnmanagedType.LPWStr)]
string ServerName,
[MarshalAs(UnmanagedType.LPWStr)]
string PathName,
[MarshalAs(UnmanagedType.LPWStr)]
string Comment,
int Flags);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct DFS_INFO_102
{
public ulong Timeout;
}

[DllImport("Netapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int NetDfsSetClientInfo(
[MarshalAs(UnmanagedType.LPWStr)]
string DfsEntryPath,
[MarshalAs(UnmanagedType.LPWStr)]
string ServerName,
[MarshalAs(UnmanagedType.LPWStr)]
string PathName,
int Level,
IntPtr Buffer);


//some other code


DFS_INFO_102 info;
info.Timeout = 1800;
IntPtr timeoutBuffer = IntPtr.Zero;
timeoutBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(info));
Marshal.StructureToPtr(info, timeoutBuffer, false);

NetDfsAdd("\\\\MyDomain\\DFS\\PathToLink", share, folder, "My link", 1);
//Successfully created the dfs entry, but the referral cache is set to
//300 sec.

int res = NetDfsSetClientInfo("\\\\MyDomain\\DFS\\PathToLink", null, null, 102, timeoutBuffer);
Console.WriteLine(res);
//0, but the referral cache value is still 300

Marshal.FreeHGlobal(timeoutBuffer);


Please help!!!!!!!
Message has been deleted

andrea...@gmail.com

unread,
Feb 28, 2012, 5:09:29 AM2/28/12
to
Solved by myself, in order to reach the goal the correct method to be invoked is NetDfsSetInfo.
0 new messages