在winfrom怎么用代码创建共享文件夹

evaELLIS 2004-12-02 02:57:11
我在作一个打包文件,想在展开时有一个共享文件夹,向大家问一下怎么作。最好有代码
...全文
283 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2005-02-03
  • 打赏
  • 举报
回复
楼主什么意思,嗯!

我的回答太复杂可以不给我分,但是 yuwen121(雨文天空) 和 zjsen() ( ) 的回复几呼都是一样的为什么都把分给了一个人了!

给个说法来!
yuwen121 2005-02-03
  • 打赏
  • 举报
回复

C:\test目录共享,共享名为:test
Process.Start(@"net share test=c:\test ");
删除共享名为:test的共享目录
Process.Start(@"net share test /delete ");
xiaoslong 2004-12-02
  • 打赏
  • 举报
回复
帮你顶
八爪鱼-杭州 2004-12-02
  • 打赏
  • 举报
回复
把C:\test目录共享,共享名为:test
Process.Start(@"net share test=c:\test ");
删除共享名为:test的共享目录
Process.Start(@"net share test /delete ");
dazhu2 2004-12-02
  • 打赏
  • 举报
回复
STUDY
北京的雾霾天 2004-12-02
  • 打赏
  • 举报
回复
这个是2000以下的系统的:
public enum NetError
{
NERR_Success = 0,
NERR_BASE = 2100,
NERR_UnknownDevDir = (NERR_BASE + 16),
NERR_DuplicateShare = (NERR_BASE + 18),
NERR_BufTooSmall = (NERR_BASE + 23),
NERR_NetNameNotFound = (NERR_BASE+210)
}

public enum SHARE_TYPE : ulong
{
STYPE_DISKTREE = 0,
STYPE_PRINTQ = 1,
STYPE_DEVICE = 2,
STYPE_IPC = 3,
STYPE_SPECIAL = 0x80000000,
}

[ StructLayout( LayoutKind.Sequential )]
public struct SHARE_INFO_502
{
[MarshalAs(UnmanagedType.LPWStr)]
public string shi502_netname;
public uint shi502_type;
[MarshalAs(UnmanagedType.LPWStr)]
public string shi502_remark;
public Int32 shi502_permissions;
public Int32 shi502_max_uses;
public Int32 shi502_current_uses;
[MarshalAs(UnmanagedType.LPWStr)]
public string shi502_path;
public IntPtr shi502_passwd;
public Int32 shi502_reserved;
public IntPtr shi502_security_descriptor;
}

[DllImport("Netapi32.dll")]
public static extern int NetShareAdd([MarshalAs(UnmanagedType.LPWStr)]string strServer, Int32 dwLevel, IntPtr buf, IntPtr parm_err);
//删除共享
[System.Runtime.InteropServices.DllImport("netapi32")]
private static extern int NetShareDel([MarshalAs(UnmanagedType.LPWStr)]string strServer, [MarshalAs(UnmanagedType.LPWStr)]string ShareName, int dword);
北京的雾霾天 2004-12-02
  • 打赏
  • 举报
回复
以上是2000下用API来实现目录共享及删除共享
北京的雾霾天 2004-12-02
  • 打赏
  • 举报
回复
//共享类型
private const long STYPE_ALL = -1;
private const long STYPE_DISKTREE = 0;
private const long STYPE_PRINTQ = 1;
private const long STYPE_DEVICE = 2;
private const long STYPE_IPC = 3;
private const long STYPE_SPECIAL = 0X80000000;

//权限
private const long ACCESS_READ = 0X1;
private const long ACCESS_WRITE = 0X2;
private const long ACCESS_CREATE = 0X4;
private const long ACCESS_EXEC = 0X8;
private const long ACCESS_DELETE = 0X10;
private const long ACCESS_ATRIB = 0X20;
private const long ACCESS_PERM = 0X40;
private const long ACCESS_ALL = ACCESS_READ | ACCESS_WRITE | ACCESS_CREATE | ACCESS_EXEC | ACCESS_DELETE | ACCESS_ATRIB | ACCESS_PERM;

//出错信息
private const int ERROR_ACCESS_DENIED = 5;

private const int ERROR_INVALID_LEVEL = 124;
private const int ERROR_INVALID_NAME = 123;// dderror

private const int DNS_ERROR_INVALID_NAME = ERROR_INVALID_NAME;

private const int ERROR_INVALID_PARAMETER = 87;// dderror

private const int NERR_BASE = 2100;
private const int NERR_DuplicateShare = (NERR_BASE+18); /* The name has already been shared. */

//共享信息
private struct SHARE_INFO_2
{
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_netname ; //共享名
public long shi2_type ; //类型
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_remark ; //备注
public long shi2_permissions ; //权限
public long shi2_max_uses ; //最大用户
public string shi2_current_uses ; //
public string shi2_path ; //路径
[MarshalAs(UnmanagedType.LPWStr)]
public string shi2_pswd ; //密码
}

//设置共享
[System.Runtime.InteropServices.DllImport("netapi32")]
private static extern int NetShareAdd(string ServerName,int level,ref SHARE_INFO_2 buf,long parmerr);

//删除共享
[System.Runtime.InteropServices.DllImport("netapi32")]
private static extern int NetShareDel(string ServerName, [MarshalAs(UnmanagedType.LPWStr)]ref string ShareName, int dword);
wangxt 2004-12-02
  • 打赏
  • 举报
回复
帮你顶
evaELLIS 2004-12-02
  • 打赏
  • 举报
回复
最好还是有C#的吧,VB.net我已经有段时间不用了。有点看懂了
wwei69 2004-12-02
  • 打赏
  • 举报
回复
你可以修改注册表的,把文件夹的值更改一下
lucbesson 2004-12-02
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/53/53878.shtm

楼主会vb吗 ?
c#的找不到。。。。。也没写过。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧