111,126
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MessageTransfer
{
/// <summary>
/// 共享连接类
/// </summary>
public class ConnShareRes
{
private readonly static Encrypt dncrypt = new Encrypt();
private readonly static string userName = dncrypt.DecryptString("nuHRWBOdemdSagmhp59pUw==");
private readonly static string userPwd = dncrypt.DecryptString("QLsFwBVPFoM11MhrTr3kaA==");
/// <summary>
/// 服务器URL
/// </summary>
public readonly static string shareResDictionary = dncrypt.DecryptString("E1ETohnoMgtZwSkf7+/INwC/0cb7addJpEWhSxGhJZzWkg+rkadr5sWcZAIHzLV2");
//构造函数
public ConnShareRes()
{
}
[StructLayout(LayoutKind.Sequential)]
public struct NETRESOURCEA
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int 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 override String ToString()
{
String str = "LocalName: " + lpLocalName + " RemoteName: " + lpRemoteName + " Comment: " + lpComment + " lpProvider: " + lpProvider;
return (str);
}
}
[DllImport("mpr.dll")]
public static extern int WNetAddConnection2([MarshalAs(UnmanagedType.LPArray)] NETRESOURCEA[] lpNetResource, [MarshalAs(UnmanagedType.LPStr)] string lpPassword, [MarshalAs(UnmanagedType.LPStr)] string UserName, int dwFlags);
[DllImport("mpr.dll")]
public static extern int WNetCancelConnection2(string lpName, int dwFlags, bool fForce);
//开始远程连接
public bool RemoteConnect(bool bConnected)
{
int res;
NETRESOURCEA[] n = new NETRESOURCEA[1];
n[0] = new NETRESOURCEA();
n[0].dwType = 1;
int dwFlags = 1; // CONNECT_INTERACTIVE;
//n[0].lpLocalName = @"X:";
n[0].lpLocalName = @"";
n[0].lpRemoteName = shareResDictionary;
//n[0].lpRemoteName = @"\\wanglh\manageshare";
n[0].lpProvider = null;
//Console.WriteLine(n[0]);
if (bConnected)
{
res = WNetAddConnection2(n, userPwd, userName, dwFlags);
}
else
{
res = WNetCancelConnection2(shareResDictionary, 1, true);
}
return (res == 0) ? true : false;
}
}
}