怎样实现共享D盘?

MicroApp 2003-03-18 04:15:46
98系统,怎样实现D盘完全共享?
...全文
588 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
HUANG_JH 2003-03-18
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <windows.h>
#include <svrapi.h>

int main(int argc, char FAR * argv[])
{
char FAR * pszServerName = NULL;
short nLevel = 50;
struct share_info_50* pBuf = NULL;
unsigned short cbBuffer;
NET_API_STATUS nStatus;
//
// ServerName can be NULL to indicate the local computer.
//
if ((argc < 3) || (argc > 4))
{
printf("Usage: %s [\\\\ServerName] ShareName SharePath\n", argv[0]);
exit(1);
}

if (argc == 4)
pszServerName = argv[1];
//
// Allocate the memory required to specify a
// share_info_50 structure.
//
cbBuffer = sizeof(struct share_info_50);
pBuf = malloc(cbBuffer);

if (pBuf == NULL)
printf("No memory\n");
//
// Assign values to the share_info_50 structure.
//
strcpy(pBuf->shi50_netname, argv[argc-2]);
pBuf->shi50_type = STYPE_DISKTREE;
pBuf->shi50_flags = SHI50F_FULL;
pBuf->shi50_remark = NULL;
pBuf->shi50_path = argv[argc-1];
pBuf->shi50_rw_password[0] = '\0'; // No password
pBuf->shi50_ro_password[0] = '\0'; // No password
//
// Call the NetShareAdd function
// specifying information level 50.
//
nStatus = NetShareAdd(pszServerName,
nLevel,
(char FAR *)pBuf,
cbBuffer);
//
// Display the result of the function call.
//
if (nStatus == NERR_Success)
printf("Share added successfully\n");
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
free(pBuf);

return 0;
}
Robin 2003-03-18
  • 打赏
  • 举报
回复
呵呵!
用API搞定啊!
NowCan 2003-03-18
  • 打赏
  • 举报
回复
//Win9X目录共享
#include <windows.h>
#include <lmshare.h>
#include <stdio.h>

#define SHI50F_RDONLY 0x0001
#define SHI50F_FULL 0x0002
#define SHI50F_DEPENDSON (SHI50F_RDONLY | SHI50F_FULL)
#define SHI50F_ACCESSMASK (SHI50F_RDONLY | SHI50F_FULL)
#define SHI50F_PERSIST 0x0100
#define SHI50F_SYSTEM 0x0200

typedef struct share_info_50
{
char shi50_netname[LM20_NNLEN + 1]; /* share name */
unsigned char shi50_type; /* see below */
unsigned short shi50_flags; /* see below */
char FAR *shi50_remark; /* ANSI comment string */
char FAR *shi50_path; /* shared resource */
char shi50_rw_password[SHPWLEN + 1]; /* read-write password (share-level security) */
char shi50_ro_password[SHPWLEN + 1]; /* read-only password (share-level security) */
} SHI50; /* share_info_50 */

typedef DWORD (WINAPI *SVR_NETSHAREADD)
(
const char FAR *pszServer,
short sLevel,
const char FAR *pbBuffer,
unsigned short cbBuffer
);

/* */

int main(int argc, char **argv)
{
SHI50 shinfo50;
SVR_NETSHAREADD pSVRNetShareAdd;
HINSTANCE ghDll_SvrApi;
NET_API_STATUS ret;
ghDll_SvrApi=LoadLibrary("SVRAPI.DLL");
if(!ghDll_SvrApi)
{
printf("Cannot loadlibrary <SVRAPI.DLL>\n");
return 0;
}

pSVRNetShareAdd=(SVR_NETSHAREADD) GetProcAddress(ghDll_SvrApi, "NetShareAdd");
if(!pSVRNetShareAdd)
{
printf("Cannot getaddress <NetShareAdd>\n");
return 0;
}

if(argc != 3)
{
printf("Usage:sh [share path] [share name]\n");
return 0;
}

lstrcpyn(shinfo50.shi50_netname, argv[2], LM20_NNLEN + 1);
shinfo50.shi50_type=STYPE_DISKTREE;
shinfo50.shi50_flags=SHI50F_FULL | SHI50F_SYSTEM | SHI50F_PERSIST;
shinfo50.shi50_remark="";
shinfo50.shi50_path=argv[1];
shinfo50.shi50_rw_password[0]=0;
shinfo50.shi50_ro_password[0]=0;
ret=pSVRNetShareAdd(NULL, 50, (char *) &shinfo50, sizeof(struct share_info_50));
if(ret == 0)
{
printf("Success!\n");
}
else
{
printf("Fail!\n");
}

FreeLibrary(ghDll_SvrApi);
}

不过我没法试验是否正确。

1,316

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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