十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
网络共享文件夹不能直接用VB里的Open语句,那是为本地文件用的
10年积累的成都网站设计、成都做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有遵义免费网站建设让你可以放心的选择与我们合作。
网络文件夹用API函数OpenFile
具体用法:
FileHandle = OpenFile( "\\ " IP地址 文件路径 "\ " 文件名, lpReOpenBuff, OF_READ)
调用
net
share命令即可
在vb中
可用
shell
语句
,如
shell
"net
share
XXXXXX"
NET
SHARE
sharename
sharename=drive:path
[/USERS:number
|
/UNLIMITED]
[/REMARK:"text"]
[/CACHE:Manual
|
Documents|
Programs
|
None
]
sharename
[/USERS:number
|
/UNLIMITED]
[/REMARK:"text"]
[/CACHE:Manual
|
Documents
|
Programs
|
None]
{sharename
|
devicename
|
drive:path}
/DELETE
NET
SHARE
使网络用户可以使用某一服务器上的资源。
当不带选项使用本命令
时,它会列出该计算机上正在被共享的所有资源。对于每一种资源,Windows
都
会报告其设备名或路径名,以及与之相关的描述性注释。
sharename
指共享资源的网络名。输入
NET
SHARE
和一个共享名只会
显示那个共享的有关信息。
drive:path
指定将被共享的目录的绝对路径。
/USERS:number
设置可以同时访问共享资源的最大用户数。
/UNLIMITED
指定用户可以同时访问共享资源的不受限制的数目。
/REMARK:"text"
添加一个有关资源的描述性注释,应将文本包含在引号中。
devicename
指一个或多个被共享名所共享的打印机
(LPT1:
至
LPT9:)。
/DELETE
终止资源的共享。
/CACHE:Automatic
启用脱机客户缓存和自动重新集成
/CACHE:Manual
启用脱机客户缓存和手动重新集成
/CACHE:No
告诉客户脱机缓存不合适
NET
HELP
command
|
MORE
用于逐屏显示帮助。
首先两台电脑网邻居要互相见另外共享文件夹要设修改VB像本文件操作比读取文件:
MsgBox
FileLen("\\电脑名或IP\共享文件夹名\文件名")
载文件其实复制文件:
FileCopy
"\\电脑名或IP\共享文件夹名\文件名",
"D:\本文件夹名\文件名"
远程电脑文件夹映射本驱器更简单跟操作本文件完全比映射Z盘:
MsgBox
FileLen("Z:\文件名")
FileCopy
"Z:\文件名",
"D:\本文件夹名\文件名"
我不会VB,但是都是.net。c#的代码稍微转换一下就可以了。
C#实现访问网络共享文件夹,使用 WNetAddConnection2A 和 WNetCancelConnection2A。
在目标服务器建立共享文件夹,建立访问账号test;
public enum ERROR_ID
{
ERROR_SUCCESS = 0, // Success
ERROR_BUSY = 170,
ERROR_MORE_DATA = 234,
ERROR_NO_BROWSER_SERVERS_FOUND = 6118,
ERROR_INVALID_LEVEL = 124,
ERROR_ACCESS_DENIED = 5,
ERROR_INVALID_PASSWORD = 86,
ERROR_INVALID_PARAMETER = 87,
ERROR_BAD_DEV_TYPE = 66,
ERROR_NOT_ENOUGH_MEMORY = 8,
ERROR_NETWORK_BUSY = 54,
ERROR_BAD_NETPATH = 53,
ERROR_NO_NETWORK = 1222,
ERROR_INVALID_HANDLE_STATE = 1609,
ERROR_EXTENDED_ERROR = 1208,
ERROR_DEVICE_ALREADY_REMEMBERED = 1202,
ERROR_NO_NET_OR_BAD_PATH = 1203
}
public enum RESOURCE_SCOPE
{
RESOURCE_CONNECTED = 1,
RESOURCE_GLOBALNET = 2,
RESOURCE_REMEMBERED = 3,
RESOURCE_RECENT = 4,
RESOURCE_CONTEXT = 5
}
public enum RESOURCE_TYPE
{
RESOURCETYPE_ANY = 0,
RESOURCETYPE_DISK = 1,
RESOURCETYPE_PRINT = 2,
RESOURCETYPE_RESERVED = 8,
}
public enum RESOURCE_USAGE
{
RESOURCEUSAGE_CONNECTABLE = 1,
RESOURCEUSAGE_CONTAINER = 2,
RESOURCEUSAGE_NOLOCALDEVICE = 4,
RESOURCEUSAGE_SIBLING = 8,
RESOURCEUSAGE_ATTACHED = 16,
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
}
public enum RESOURCE_DISPLAYTYPE
{
RESOURCEDISPLAYTYPE_GENERIC = 0,
RESOURCEDISPLAYTYPE_DOMAIN = 1,
RESOURCEDISPLAYTYPE_SERVER = 2,
RESOURCEDISPLAYTYPE_SHARE = 3,
RESOURCEDISPLAYTYPE_FILE = 4,
RESOURCEDISPLAYTYPE_GROUP = 5,
RESOURCEDISPLAYTYPE_NETWORK = 6,
RESOURCEDISPLAYTYPE_ROOT = 7,
RESOURCEDISPLAYTYPE_SHAREADMIN = 8,
RESOURCEDISPLAYTYPE_DIRECTORY = 9,
RESOURCEDISPLAYTYPE_TREE = 10,
RESOURCEDISPLAYTYPE_NDSCONTAINER = 11
}
[StructLayout(LayoutKind.Sequential)]
public struct NETRESOURCE
{
public RESOURCE_SCOPE dwScope;
public RESOURCE_TYPE dwType;
public RESOURCE_DISPLAYTYPE dwDisplayType;
public RESOURCE_USAGE dwUsage;
[MarshalAs(UnmanagedType.LPStr)]
public string lpLocalName;
[MarshalAs(UnmanagedType.LPStr)]
public string lpRemoteName;
[MarshalAs(UnmanagedType.LPStr)]
public string lpComment;
[MarshalAs(UnmanagedType.LPStr)]
public string lpProvider;
}
public class NetworkConnection
{
[DllImport("mpr.dll")]
public static extern int WNetAddConnection2A (NETRESOURCE[] lpNetResource, string lpPassword, string lpUserName, int dwFlags);
[DllImport("mpr.dll")]
public static extern int WNetCancelConnection2A (string sharename, int dwFlags, int fForce);
public static int Connect (string remotePath, string localPath, string username, string password)
{
NETRESOURCE[] share_driver = new NETRESOURCE[1];
share_driver[0].dwScope = RESOURCE_SCOPE.RESOURCE_GLOBALNET;
share_driver[0].dwType = RESOURCE_TYPE.RESOURCETYPE_DISK;
share_driver[0].dwDisplayType = RESOURCE_DISPLAYTYPE.RESOURCEDISPLAYTYPE_SHARE;
share_driver[0].dwUsage = RESOURCE_USAGE.RESOURCEUSAGE_CONNECTABLE;
share_driver[0].lpLocalName = localPath;
share_driver[0].lpRemoteName = remotePath;
Disconnect(localPath);
int ret = WNetAddConnection2A(share_driver, password, username, 1);
return ret;
}
public static int Disconnect (string localpath)
{
return WNetCancelConnection2A(localpath, 1, 1);
}
调用方式:
public static void TestNetWorkConnection()
{
string localpath = "X:";
//int status = NetworkConnection.Connect(@"\\192.168.0.2\test", localpath, @"test", "test");
int status = NetworkConnection.Connect("\\\\192.168.0.2\\test", localpath, @"test", "test");
if (status == (int)ERROR_ID.ERROR_SUCCESS)
{
FileStream fs = new FileStream(localpath + @"\\123.txt", FileMode.OpenOrCreate);
using (StreamWriter stream = new StreamWriter(fs))
{
stream.WriteLine("你好呀,成功了");
stream.Flush();
stream.Close();
}
fs.Close();
}
else
{
Console.WriteLine(status);
}
NetworkConnection.Disconnect(localpath);
}
你用regsnap或者regshot软件快照下注册表,再用深度那个工具修改下注册表,再用regsnap或者regshot软件快照下注册表,对比下两次的区别后,就能找到相关的注册表项了,找到后用操作注册表的API或者wscript更改掉相关的注册项即可。
开启或者关闭局域网共享的功能,其实就是更改注册表相应的键值。