怎样创建一个共享文件夹?
解决方案 »
- 我想相加个PNG资源,可是怎么读取它?
- GetCursorPos得到的位置是相对于屏幕还是程序当前窗口?
- 求解:dll控件要和javaScrip传递个信息,该如何实现?谢谢
- 关于数据库的类型问题。
- 高分加急!!!怎样用c++调用photoshop打开硬盘上的图片!!
- 定义了全局变量,但是链接时一直出错,求助阿~~`
- 有没有这种技术:客户端应用程序直接访问IIS服务器上的mdb数据库,条件是无法往服务器上安装DLL组件?
- ?我能使SetTimer()的单位为纳秒吗?如果不能,怎样能得到纳秒?
- 学API编程,请大家介绍本适合的书,Thank you.
- 怎样使程序启动后不在任务栏上出现任务按钮?我的程序是基于对话框的,不是SDI也不是MDI.
- 我在Com中开的线程中触发连接点事件Fire_XXXXEvent为什么程序运行时报错呢??
- 怎么实现文件的拖放?
当然最好还是用API函数来设置共享了,ServerName改一下就行了。
Option Explicit
Private Declare Function NetShareAdd Lib "netapi32" (ByVal ServerName As Long, ByVal level As Long, buf As Any, parmerr As Long) As Long
Private Type SHARE_INFO_2
shi2_netname As Long '共享名
shi2_type As Long '类型
shi2_re As Long '备注
shi2_permissions As Long '权限
shi2_max_uses As Long '最大用户
shi2_current_uses As Long '
shi2_path As Long '路径
shi2_passwd As Long '密码
End Type
Const STYPE_ALL = -1
Const STYPE_DISKTREE = 0
Const STYPE_PRINTQ = 1
Const STYPE_DEVICE = 2
Const STYPE_IPC = 3
Const STYPE_SPECIAL = &H80000000
Const ACCESS_READ = &H1
Const ACCESS_WRITE = &H2
Const ACCESS_CREATE = &H4
Const ACCESS_EXEC = &H8
Const ACCESS_DELETE = &H10
Const ACCESS_ATRIB = &H20
Const ACCESS_PERM = &H40
Const ACCESS_ALL = ACCESS_READ Or ACCESS_WRITE Or ACCESS_CREATE Or ACCESS_EXEC Or ACCESS_DELETE Or ACCESS_ATRIB Or ACCESS_PERM
' 为指定的计算机添加共享
' Server 为计算机名, SharePath 为共享路径, ShareName 为共享名, ShareRe 为备注, SharePw 为密码
Function AddShare(Server As String, SharePath As String, ShareName As String, ShareRe As String, SharePw As String) As Boolean
Dim lngServer As Long
Dim lngNetname As Long
Dim lngPath As Long
Dim lngRe As Long
Dim lngPw As Long
Dim parmerr As Long
Dim si2 As SHARE_INFO_2
lngServer = StrPtr(Server)
lngNetname = StrPtr(ShareName)
lngPath = StrPtr(SharePath)
If Len(ShareRe) > 0 Then
lngRe = StrPtr(ShareRe)
End If
If Len(SharePw) > 0 Then
lngPw = StrPtr(SharePw)
End If
With si2
.shi2_netname = lngNetname
.shi2_path = lngPath
.shi2_re = lngRe
.shi2_type = STYPE_DISKTREE
.shi2_permissions = ACCESS_ALL
.shi2_max_uses = -1
.shi2_passwd = lngPw
End With
If NetShareAdd(lngServer, 2, si2, parmerr) = 0 Then
AddShare = True
Else
AddShare = False
End If
End Function
Private Sub Command1_Click()
MkDir "c:\123"
AddShare "server", "c:\123", "C盘的一个文件夹", "这只是一个例子", ""
End Sub
LPWSTR servername,
DWORD level,
LPBYTE buf,
LPDWORD parm_err
);NET_API_STATUS NetShareDel(
LPWSTR servername,
LPWSTR netname,
DWORD reserved
);
#include <windows.h>
#include <stdio.h>
#include <lm.h>void wmain( int argc, TCHAR *argv[ ])
{
NET_API_STATUS res;
SHARE_INFO_2 p;
DWORD parm_err = 0; if(argc<2)
printf("Usage: NetShareAdd server\n");
else
{
//
// Fill in the SHARE_INFO_2 structure.
//
p.shi2_netname = TEXT("TESTSHARE");
p.shi2_type = STYPE_DISKTREE; // disk drive
p.shi2_re = TEXT("TESTSHARE to test NetShareAdd");
p.shi2_permissions = 0;
p.shi2_max_uses = 4;
p.shi2_current_uses = 0;
p.shi2_path = TEXT("C:\\");
p.shi2_passwd = NULL; // no password
//
// Call the NetShareAdd function,
// specifying level 2.
//
res=NetShareAdd(argv[1], 2, (LPBYTE) &p, &parm_err);
//
// If the call succeeds, inform the user.
//
if(res==0)
printf("Share created.\n");
// Otherwise, print an error,
// and identify the parameter in error.
//
else
printf("Error: %u\tparmerr=%u\n", res, parm_err);
}
return;
}删除一个共享#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>void wmain( int argc, TCHAR *argv[ ])
{
NET_API_STATUS res; if(argc<3)
printf("Usage: NetShareDel server share\n");
else
{
//
// Call the NetShareDel function to delete the share.
//
res=NetShareDel(argv[1], argv[2], 0);
//
// Display the result of the call.
//
if(res==0)
printf("Share Removed.\n");
else
printf("Error: %u\n", res);
}
return;
}
net share ....
net share delete....
可以参照dos帮助啊