如何用代码设置共享文件夹,在线等待,急!!

smile_ni 2002-12-28 05:42:35
在WIN2000下,将D:\TEST文件夹设置为用户“YYPPCC”只读权限???
注:程序中,要用代码实现,将权限给指定的用户
...全文
40 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
smile_ni 2002-12-29
请看清要求再回答,非常感谢!!
回复
cngxylyh 2002-12-28
改注册表
设置HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ Network\LanMan\C$\Flags"值为"00000258"("REG_DWORD")
设置HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ Network\LanMan\C$\Type"值为0("REG_DWORD")
设置HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ Network\LanMan\C$\Path"值为"C:\" ,使C:共享完全控制
回复
smile_ni 2002-12-28
有没有人知道????
回复
yinxiaodan 2002-12-28
呵呵,不错啊
回复
ityaa 2002-12-28
另一种方法不知道行不行,共享文件夹在注册表中保存为相关数据,只要依照注册表的数据来建一个相似的就可以。
回复
smile_ni 2002-12-28
netshareadd不能实现
回复
netshareadd
回复
feixuehenshui 2002-12-28
不错!
回复
smile_ni 2002-12-28
如何设置用户的权限??
回复
shawls 2002-12-28
[名称] 创建共享目录

[数据来源] 未知

[内容简介] 空

[源代码内容]

Private Const NERR_SUCCESS As Long = 0&
Private Const STYPE_ALL As Long = -1 'note: my const
Private Const STYPE_DISKTREE As Long = 0
Private Const STYPE_PRINTQ As Long = 1
Private Const STYPE_DEVICE As Long = 2
Private Const STYPE_IPC As Long = 3
Private Const STYPE_SPECIAL As Long = &H80000000
'permissions
Private Const ACCESS_READ As Long = &H1
Private Const ACCESS_WRITE As Long = &H2
Private Const ACCESS_CREATE As Long = &H4
Private Const ACCESS_EXEC As Long = &H8
Private Const ACCESS_DELETE As Long = &H10
Private Const ACCESS_ATRIB As Long = &H20
Private Const ACCESS_PERM As Long = &H40
Private Const ACCESS_ALL As Long = ACCESS_READ Or _
ACCESS_WRITE Or _
ACCESS_CREATE Or _
ACCESS_EXEC Or _
ACCESS_DELETE Or _
ACCESS_ATRIB Or _
ACCESS_PERM
Private Type SHARE_INFO_2
shi2_netname As Long
shi2_type As Long
shi2_remark 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
Private Declare Function NetShareAdd Lib "netapi32" _
(ByVal servername As Long, _
ByVal level As Long, _
buf As Any, _
parmerr As Long) As Long
Private Declare Function NetShareDelete Lib "netapi32()" (ByVal servername As Long, _
ByVal level As Long, _
buf As Any, _
parmerr As Long) As Long



Private Function ShareAdd(sServer As String, _
sSharePath As String, _
sShareName As String, _
sShareRemark As String, _
sSharePw As String) As Long
Dim dwServer As Long
Dim dwNetname As Long
Dim dwPath As Long
Dim dwRemark As Long
Dim dwPw As Long
Dim parmerr As Long
Dim si2 As SHARE_INFO_2
dwServer = StrPtr(sServer)
dwNetname = StrPtr(sShareName)
dwPath = StrPtr(sSharePath)
If Len(sShareRemark) > 0 Then
dwRemark = StrPtr(sShareRemark)
End If
If Len(sSharePw) > 0 Then
dwPw = StrPtr(sSharePw)
End If
With si2
.shi2_netname = dwNetname
.shi2_path = dwPath
.shi2_remark = dwRemark
.shi2_type = STYPE_DISKTREE
.shi2_permissions = &H1 'ACCESS_READ
.shi2_max_uses = -1
.shi2_passwd = dwPw
End With
ShareAdd = NetShareAdd(dwServer, 2, si2, parmerr)
End Function

Private Sub Command1_Click()
Dim fpath As String
Dim sharename As String
fpath = "e:\"
sharename = "1234"

ShareAdd "", fpath, sharename, "", ""
End Sub


以上代码保存于: SourceCode Explorer(源代码数据库)
复制时间: 2002-12-28 17:45:52
软件版本: 1.0.805
软件作者: Shawls
个人主页: Http://Shawls.Yeah.Net
E-Mail: ShawFile@163.Net
QQ: 9181729
回复
shawls 2002-12-28
[名称] 建立磁盘/目录的資源分享/共享

[语言种类] Visual Basic

[类别一] VBAPI

[类别二] 网络通信

[类别三] 系统操控

[数据来源] www.vbguide.com.tw

[保存时间] 2002-06-18

[关键字一] 资源共享

[关键字二] 磁盘/目录

[关键字三] 空

[内容简介]
如何判断共享文件夹的存在,并且把共享文件夹设置为不共享!
1要求得知共享文件夹的真正路径和文件名,以及虚拟文件名。
2如何不需要重起机器,就可以把共享文件夹设置为不共享!

[源代码内容]

在【檔案總管】或【我的電腦】中,我們都可以直接在磁碟機或目錄上按滑鼠右鍵,選【內容】,在【資源分享】頁中設定磁碟機或目錄的資源分享,如圖:

 90.09.15 加註:
 此範例只適用於 Win95/98/Me!


我在集團的資訊部門工作,要處理一二十家以上的公司系統,在正常的狀況下,為了方便,我們在機器交給使用者使用時,會替他們將某個磁碟機或某個目錄設定可以資源分享,但是並不是每個使用者都喜歡開放自己的電腦讓別人存取,於是他們便會將資源分享的功能取消,造成資訊人員些許不方便。

這時候,也不必和使用者爭得臉紅脖子粗的,反正山不轉路轉,我們就不知不覺地,讓使用者自己在莫名其妙的情形下,按照您的意思,在某個磁碟機或某個目錄設定您想要設定的資源分享,然後又神不知鬼不覺地取消資源分享!

要怎麼做呢?其實很簡單,就是將設定/取消資源分享的功能寫在 VB 程式中,像人事差勤系統是每個使用者都要使用的系統,我們就在這些系統的 VB 程式中,去設定/取消資源分享!而且使用者完全沒有感覺!

下面這個模組檔案中 (.bas檔) 已經有完整的宣告及完成的二個模組,只要呼叫這二個模組,就可以建立/取消磁碟機或目錄的資料分享:

Source Code 下載

這二個模組說明如下:

Public Function CreateShare _ ' 建立資源分享模組
(ByVal sSharePath As String, _ ' 完整路徑
ByVal sShareName As String, _ ' 資源分享名稱
ByVal sRemark As String, _ ' 說明
ByVal sROPass As String, _ ' 唯讀密碼
ByVal sRWPass As String) As Long ' 完整存取密碼

Public Function DeleteShare _ ' 取消資源分享模組
(ByVal sShareName As String) As Long ' 資源分享名稱

呼叫範例如下:

Private Sub Command1_Click()
' 建立資源分享 CDISK
CreateShare "C:\ ", "CDISK ", "小紀的 C 磁碟機 ", "JWHR ", "JWHRW "
End Sub

Private Sub Command2_Click()
' 取消資源分享 CDISK
DeleteShare "CDISK "
End Sub
註:就像一般教人家做壞事的書或電視節目一樣,我也要聲明一下:
註:以上方式請用於正途 (系統需要),請勿使用以上方法來不當竊取不該看的檔案!


以上代码保存于: SourceCode Explorer(源代码数据库)
复制时间: 2002-12-28 17:45:27
软件版本: 1.0.805
软件作者: Shawls
个人主页: Http://Shawls.Yeah.Net
E-Mail: ShawFile@163.Net
QQ: 9181729
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7452

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告