WNetAddConnection("\\servername\Sharename", "", "盘符:")
解决方案 »
- 如何选择WORD文件中的一页并复制到剪切板?
- 关于Speech SDK 5.1的问题求助
- 不安装SQL SERVER数据库(应用程序)的情况下.如何运行VB+SQL的写的程序??
- sub main的一个现象。
- 这个为什么在sql2000里可以,在access里就不行了???
- windows 里自带的记事本 的‘自动换行’功能......?(菜鸟请教!)
- 高手请进! DBEngine的CompactDatabase方法出错问题!
- 怎么使PC喇叭(注意不是音箱)发出指定的声音? beep不行,机器有声卡!!! WIN2000下也要能用啊!
- 设计书问题:
- 提问:用ado读取access数据库的某个字段,但该字段可能为空,我想用do while rs(get)=null rs.movenext loop来移动rs到字段不为空的记录。可是没用,循环语句总是不执行。
- 如何获得系统已安装的打印机和默认打印机?
- 关于VB调用VC写的DLL问题
你是映射吧,我是将本地目录共享
to danielsyq(丹尼)
没有条件,是为了导入SQL数据,服务器不在本机
Dim wsh As Object
Set wsh = CreateObject("Wscript.shell")
wsh.run "net share AAA=D:\SQLXML", 0
Set wsh = Nothing
End SubPrivate Sub Command2_Click() '取消共享
Dim wsh As Object
Set wsh = CreateObject("Wscript.shell")
wsh.run "net share AAA /delete", 0
Set wsh = Nothing
End Sub
Option ExplicitPrivate Sub Command1_Click() 'Share
Dim WshShell As IWshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "net share ShareTesting=D:\UML", 0, True
Set WshShell = Nothing
MsgBox ("OK")
End SubPrivate Sub Command2_Click() 'Unshare
Dim WshShell As IWshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "net share ShareTesting /delete", 0, True
Set WshShell = Nothing
MsgBox ("OK")
End Sub
Reference: Windows Script Host Object Model 引用找不到
Option ExplicitPrivate Sub Command1_Click() 设置共享
Dim RetVal As Long
RetVal = Shell("net share AAA=D:\SQLXML", 0) If RetVal = 0 Then
MsgBox ("Error")
Else
MsgBox ("OK")
End If
End SubPrivate Sub Command2_Click() '取消共享
Dim RetVal As Long
RetVal = Shell("net share AAA /delete", 0) ' Run Calculator.
If RetVal = 0 Then
MsgBox ("Error")
Else
MsgBox ("OK")
End If
End Sub
什么意思???
#define RTN_OK 0
#define RTN_USAGE 1
#define RTN_ERROR 13
//
// Note: UNICODE entry point and argv. This way, we don't need to bother
// with converting commandline args to Unicode
//
int
__cdecl
wmain(
int argc,
wchar_t *argv[]
)
{
LPWSTR DirectoryToShare;
LPWSTR Sharename;
LPWSTR Username;
LPWSTR Server;
PSID pSid = NULL;
DWORD cbSid;
WCHAR RefDomain[DNLEN + 1];
DWORD cchDomain = DNLEN + 1;
SID_NAME_USE peUse;
SECURITY_DESCRIPTOR sd;
PACL pDacl = NULL;
DWORD dwAclSize;
SHARE_INFO_502 si502;
NET_API_STATUS nas;
BOOL bSuccess = FALSE; // assume this function fails
if(argc < 4) {
printf("Usage: %ls [\\\\Server]\n", argv[0]);
printf(" directory is fullpath of directory to share\n");
printf(" sharename is name of share on server\n");
printf(" user/group is an WinNT user/groupname (REDMOND\\sfield, Administrators, etc)\n");
printf(" optional Server is the name of the computer to create the share on\n");
printf("\nExample: %ls c:\\public public Everyone\n", argv[0]);
printf("c:\\public shared as public granting Everyone full access\n");
printf("\nExample: %ls c:\\private cool$ REDMOND\\sfield \\\\WINBASE\n", argv[0]);
printf("c:\\private on \\\\WINBASE shared as cool$ (hidden) granting REDMOND\\sfield access\n");
return RTN_USAGE;
}
//
// since the commandline was Unicode, just provide pointers to
// the relevant items
//
DirectoryToShare = argv[1];
Sharename = argv[2];
Username = argv[3];
if( argc > 4 ) {
Server = argv[4];
} else {
Server = NULL; // local machine
}
//
// initial allocation attempt for Sid
//
#define SID_SIZE 96
cbSid = SID_SIZE;
pSid = (PSID)HeapAlloc(GetProcessHeap(), 0, cbSid);
if(pSid == NULL) {
printf("HeapAlloc error!\n");
return RTN_ERROR;
}
//
// get the Sid associated with the supplied user/group name
// force Unicode API since we always pass Unicode string
//
if(!LookupAccountNameW(
NULL, // default lookup logic
Username, // user/group of interest from commandline
pSid, // Sid buffer
&cbSid, // size of Sid
RefDomain, // Domain account found on (unused)
&cchDomain, // size of domain in chars
&peUse
)) {
//
// if the buffer wasn't large enough, try again
//
if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
pSid = (PSID)HeapReAlloc(GetProcessHeap(), 0, pSid, cbSid);
if(pSid == NULL) {
printf("HeapReAlloc error!\n");
goto cleanup;
}
cchDomain = DNLEN + 1;
if(!LookupAccountNameW(
NULL, // default lookup logic
Username, // user/group of interest from commandline
pSid, // Sid buffer
&cbSid, // size of Sid
RefDomain, // Domain account found on (unused)
&cchDomain, // size of domain in chars
&peUse
)) {
printf("LookupAccountName error! (rc=%lu)\n", GetLastError());
goto cleanup;
}
} else {
printf("LookupAccountName error! (rc=%lu)\n", GetLastError());
goto cleanup;
}
}
//
// compute size of new acl
//
dwAclSize = sizeof(ACL) +
1 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) ) +
GetLengthSid(pSid) ;
//
// allocate storage for Acl
//
pDacl = (PACL)HeapAlloc(GetProcessHeap(), 0, dwAclSize);
if(pDacl == NULL) goto cleanup;
if(!InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
goto cleanup;
//
// grant GENERIC_ALL (Full Control) access
//
if(!AddAccessAllowedAce(
pDacl,
ACL_REVISION,
GENERIC_ALL,
pSid
)) goto cleanup;
if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
goto cleanup;
if(!SetSecurityDescriptorDacl(&sd, TRUE, pDacl, FALSE)) {
fprintf(stderr, "SetSecurityDescriptorDacl error! (rc=%lu)\n",
GetLastError());
goto cleanup;
}
//
// setup share info structure
//
si502.shi502_netname = (LPTSTR) Sharename;
si502.shi502_type = STYPE_DISKTREE;
si502.shi502_re = NULL;
si502.shi502_permissions = 0;
si502.shi502_max_uses = SHI_USES_UNLIMITED;
si502.shi502_current_uses = 0;
si502.shi502_path = (LPTSTR) DirectoryToShare;
si502.shi502_passwd = NULL;
si502.shi502_reserved = 0;
si502.shi502_security_descriptor = &sd;
nas = NetShareAdd(
(LPTSTR) Server, // share is on local machine
502, // info-level
(LPBYTE)&si502, // info-buffer
NULL // don't bother with parm
);
if(nas != NO_ERROR) {
printf("NetShareAdd error! (rc=%lu)\n", nas);
goto cleanup;
}
bSuccess = TRUE; // indicate success
cleanup:
//
// free allocated resources
//
if(pDacl != NULL)
HeapFree(GetProcessHeap(), 0, pDacl);
if(pSid != NULL)
HeapFree(GetProcessHeap(), 0, pSid);
if(!bSuccess) {
return RTN_ERROR;
}
return RTN_OK;