vb.net共享方法 vbnet shared
vb中怎麼把文件夹设为共享
NET SHARE命令设置共享路径,如将D盘设为共享
创新互联从2013年成立,先为儋州等服务建站,儋州等地企业,进行企业商务咨询服务。为儋州企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
所以你可以使用shell "net share D$"
Vb.net 请问如何快速时时读取共享文件夹资料
File.WriteAllText("\\10.1.37.222\shared\temp.txt", "");
如果能生成就没问题。
如果不用net use的方法,vb.net 有办法访问共享文件或者共享文件夹吗
我不会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);
}
vb.net 怎么实现多个控件共同使用一个变量
把变量定义时增加Shared关键字即可.如:
Private
Shared
AAA
As
String
Public
Shared
AAA
As
String
......
这样AAA在一个应用程序里就是公用的.
------------------------------------------------------
补充:
不可能没用,我都是这样做的.
该控件使用中,自己看吧:
Public
Class
CMB_MemoryTextBox
Inherits
TextBox
#Region
"
变量定义
"
Private
Shared
p_HisData
As
STRU_DATA
'用数据表保存所有控件的历史记录
Private
Shared
p_FileName
As
String
'保存历史记录的文件名
......
vb.net里面老是看到什么“共享方法”“共享属性”是什么意思?
可以直接从类调用共享方法,而不必首先创建该类的实例。共享属性与之类似,可以在一创建类实例的情况下访问,并且即使有了多个实例,共享属性仍然只有一个,就是说,设置了该属性后,对所有实例有效。类似于全局变量。
使用vb.net将以太网共享给虚拟wifi网络
最简单的办法是用句柄操作窗体,这种方法就好比是计算机在代替你在打开设置窗口,完成设置。
比较难实现的方法是用API,不过我不知道用那些API,而且还要驱动支持
因为vb。net是高级语言,不能直接操作驱动,所以直接写汇编是不可行的
分享标题:vb.net共享方法 vbnet shared
本文链接:http://ybzwz.com/article/hiepcg.html