class CSCDisabler
{
protected enum CSC_CACHE_MODE
{
CSC_CACHE_MANUAL_REINT = 0x0000, //Automatic file-by-file reintegration is not allowed.
CSC_CACHE_AUTO_REINT = 0x0010, //File-by-file reintegration is allowed.
CSC_CACHE_VDO = 0x0020, // File opens do not need to be flowed.
CSC_CACHE_NONE = 0x0030, //CSC is disabled for this share
};
/// <summary>Setup share info (NT)</summary>
[DllImport( "netapi32", CharSet = CharSet.Unicode )]
protected static extern UInt32 NetShareSetInfo ( string lpServerName, string lpNetName, UInt32 dwLevel, byte[] buf, out IntPtr parm_err );
struct SHARE_INFO_1005
{
UInt32 shi1005_flags;
}
[System.Runtime.InteropServices.StructLayout( LayoutKind.Explicit )]
struct SHARE_INFO_1005_UNION
{
[System.Runtime.InteropServices.FieldOffset( 0 )]
public UInt32 shi1005_flags;
[System.Runtime.InteropServices.FieldOffset( 0 )]
public byte shi1005_flags_0;
[System.Runtime.InteropServices.FieldOffset( 1 )]
public byte shi1005_flags_1;
[System.Runtime.InteropServices.FieldOffset( 2 )]
public byte shi1005_flags_2;
[System.Runtime.InteropServices.FieldOffset( 3 )]
public byte shi1005_flags_3;
public SHARE_INFO_1005_UNION ( CSC_CACHE_MODE value )
{
shi1005_flags_0 = shi1005_flags_1 = shi1005_flags_2 = shi1005_flags_3 = 0;
shi1005_flags = (UInt32) value;
}
}
private static UInt32 SetCSCModeForShare ( string ServerName, string ShareName, CSC_CACHE_MODE Mode, out UInt32 ErrorParam )
{
UInt32 result = 0;
unsafe
{
int size = sizeof( SHARE_INFO_1005 );
byte[] buffer = new byte[size];
SHARE_INFO_1005_UNION p = new SHARE_INFO_1005_UNION( Mode );
buffer[0] = p.shi1005_flags_0;
buffer[1] = p.shi1005_flags_1;
buffer[2] = p.shi1005_flags_2;
buffer[3] = p.shi1005_flags_3;
UInt32 param_err;
IntPtr pparam_err = new IntPtr( ( void* ) ¶m_err );
result = NetShareSetInfo( ServerName, ShareName, 1005, buffer, out pparam_err );
ErrorParam = param_err;
}
return ( result );
}
// CSC is disabled for this share.
public static bool DisableCSCforShare ( string ServerName, string ShareName )
{
UInt32 errorParam;
return ( SetCSCModeForShare( ServerName, ShareName, CSC_CACHE_MODE.CSC_CACHE_NONE, out errorParam ) == 0 );
}
// Automatic file-by-file reintegration is not allowed.
public static bool EnableManualCSCforShare ( string ServerName, string ShareName )
{
UInt32 errorParam;
return ( SetCSCModeForShare( ServerName, ShareName, CSC_CACHE_MODE.CSC_CACHE_MANUAL_REINT, out errorParam ) == 0 );
}
// File-by-file reintegration is allowed.
public static bool EnableAutoCSCforShare ( string ServerName, string ShareName )
{
UInt32 errorParam;
return ( SetCSCModeForShare( ServerName, ShareName, CSC_CACHE_MODE.CSC_CACHE_AUTO_REINT, out errorParam ) == 0 );
}
// File opens do not need to be flowed.
public static bool EnableVDOCSCforShare ( string ServerName, string ShareName )
{
UInt32 errorParam;
return ( SetCSCModeForShare( ServerName, ShareName, CSC_CACHE_MODE.CSC_CACHE_VDO, out errorParam ) == 0 );
}
}
A>Каким образом можно включить/выключить, а также задать параметры кеширования сетевой шары на сервере? грубо говоря аналог команды net share %sharename% /cache:none (и любых других параметров — manual, documents, programs, etc...)