vb.net共享对象的简单介绍
VB.NET提示“对非共享成员的引用要求对象引用”。
ColorDialog改为ColorDialog1
十年的西安网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整西安建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“西安网站设计”,“西安网站推广”以来,每个客户项目都认真落实执行。
你照抄要看仔细啊....
'--------------------
百度VB2010(VB.NET)吧建设发展中,需要你的支持和帮助!!!
快加入我们吧!发表你的疑问,经验,程序,分享..
让我们共同进步!
如果不用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编程时:出现错误: 对非共享成员的引用要求对象引用??
Imports System
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Drawing
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim blackpen As New System.Drawing.Pen(System.Drawing.Color.Black, 2)
Dim bluepen As New System.Drawing.Pen(System.Drawing.Color.Blue, 1)
Dim g As System.Drawing.Graphics
g = Me.CreateGraphics()
blackpen.StartCap = LineCap.NoAnchor’错误出现在此行
blackpen.EndCap = LineCap.ArrowAnchor'
redpen.StartCap = LineCap.NoAnchor’错误出现在此行
redpen.EndCap = LineCap.ArrowAnchor'
g.DrawLine(blackpen, LL, buttom, LL, top)
VB.NET 对非共享成员要求对象引用
在OpTree中,要调用GetInfo的ReadInfo(),可以新建一个GetInfo类的实例:
Dim GI As New GetInfo
GI.ReadInfo()
VB中实现文件共享
调用
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.net共享对象的简单介绍
网页网址:http://abwzjs.com/article/hcpshg.html