1 BOOL NetShare(char * pShareName,char * pSharePath) 2 { 3 USES_CONVERSION; 4 SHARE_INFO_502 si502; 5 NET_API_STATUS nas; 6 LPWSTR pwShareName=A2W(pShareName); //转换成unicode 字符串 7 LPWSTR pwSharePath=A2W(pSharePath); 8 9 si502.shi502_netname = (LPWSTR)pwShareName; 10 si502.shi502_type = STYPE_DISKTREE; 11 si502.shi502_remark = NULL; 12 si502.shi502_permissions = 0; 13 si502.shi502_max_uses = /*SHI_USES_UNLIMITED*/1; 14 si502.shi502_current_uses = 0; 15 si502.shi502_path = (LPWSTR)pwSharePath; 16 si502.shi502_passwd = NULL; 17 si502.shi502_reserved = 0; 18 si502.shi502_security_descriptor = NULL ; 19 20 nas = NetShareAdd( 21 NULL, // share is on local machine 22 502, // info-level 23 (LPBYTE)&si502, // info-buffer 24 NULL // don't bother with parm 25 ); 26 27 return (nas==0); 28 }
BOOL NetShareStop(char * pShareName) { USES_CONVERSION; LPWSTR pwShareName=A2W(pShareName); return NetShareDel( NULL,(LPWSTR)pwShareName,NULL); }