Discussion:
NetDfsSetClientInfo doesn't work properly
(too old to reply)
a***@gmail.com
2012-02-23 11:51:08 UTC
Permalink
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!!!!!!!
a***@gmail.com
2012-02-28 10:08:32 UTC
Permalink
Post by a***@gmail.com
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!!!!!!!
Solved by myself, in order to obtain the goal the correct method to be invoked is NetDfsSetInfo.
a***@gmail.com
2012-02-28 10:09:29 UTC
Permalink
Post by a***@gmail.com
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!!!!!!!
Solved by myself, in order to reach the goal the correct method to be invoked is NetDfsSetInfo.
Loading...