不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
C#生成远程桌面rdp文件示例
编辑:dnawo 日期:2020-03-22
复制内容到剪贴板
程序代码

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApp1
{
public static class RDPHelper
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct DATA_BLOB
{
public int cbData;
public IntPtr pbData;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct CRYPTPROTECT_PROMPTSTRUCT
{
public int cbSize;
public int dwPromptFlags;
public IntPtr hwndApp;
public string szPrompt;
}
[DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool CryptProtectData(ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy, IntPtr pvReserved, ref CRYPTPROTECT_PROMPTSTRUCT pPromptStruct, int dwFlags, ref DATA_BLOB pDataOut);
private static string Encrypt(string password)
{
byte[] bytes = Encoding.Unicode.GetBytes(password);
DATA_BLOB dATA_BLOB = default(DATA_BLOB);
DATA_BLOB dATA_BLOB2 = default(DATA_BLOB);
DATA_BLOB dATA_BLOB3 = default(DATA_BLOB);
dATA_BLOB.cbData = bytes.Length;
dATA_BLOB.pbData = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, dATA_BLOB.pbData, bytes.Length);
dATA_BLOB3.cbData = 0;
dATA_BLOB3.pbData = IntPtr.Zero;
dATA_BLOB2.cbData = 0;
dATA_BLOB2.pbData = IntPtr.Zero;
CRYPTPROTECT_PROMPTSTRUCT cRYPTPROTECT_PROMPTSTRUCT = new CRYPTPROTECT_PROMPTSTRUCT
{
cbSize = Marshal.SizeOf(typeof(CRYPTPROTECT_PROMPTSTRUCT)),
dwPromptFlags = 0,
hwndApp = IntPtr.Zero,
szPrompt = null
};
if (CryptProtectData(ref dATA_BLOB, "psw", ref dATA_BLOB3, IntPtr.Zero, ref cRYPTPROTECT_PROMPTSTRUCT, 1, ref dATA_BLOB2))
{
if (IntPtr.Zero != dATA_BLOB.pbData)
{
Marshal.FreeHGlobal(dATA_BLOB.pbData);
}
if (IntPtr.Zero != dATA_BLOB3.pbData)
{
Marshal.FreeHGlobal(dATA_BLOB3.pbData);
}
byte[] array = new byte[dATA_BLOB2.cbData];
Marshal.Copy(dATA_BLOB2.pbData, array, 0, dATA_BLOB2.cbData);
return BitConverter.ToString(array).Replace("-", string.Empty);
}
return string.Empty;
}
public static void CreateProfile(string filename, string address, string username, string password)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter streamWriter = new StreamWriter(filename, true))
{
streamWriter.WriteLine("allow desktop composition:i:0");
streamWriter.WriteLine("allow font smoothing:i:0");
streamWriter.WriteLine("alternate shell:s:");
streamWriter.WriteLine("audiocapturemode:i:0");
streamWriter.WriteLine("audiomode:i:0");//音频:0播放,2关闭
streamWriter.WriteLine("authentication level:i:2");
streamWriter.WriteLine("autoreconnection enabled:i:1");
streamWriter.WriteLine("bandwidthautodetect:i:1");
streamWriter.WriteLine("bitmapcachepersistenable:i:1");
streamWriter.WriteLine("compression:i:1");
streamWriter.WriteLine("connection type:i:7");
streamWriter.WriteLine("desktopheight:i:900");
streamWriter.WriteLine("desktopwidth:i:1440");
streamWriter.WriteLine("disable cursor setting:i:0");
streamWriter.WriteLine("disable full window drag:i:1");
streamWriter.WriteLine("disable menu anims:i:1");
streamWriter.WriteLine("disable themes:i:0");
streamWriter.WriteLine("disable wallpaper:i:0");
streamWriter.WriteLine("displayconnectionbar:i:1");
streamWriter.WriteLine("drivestoredirect:s:");
streamWriter.WriteLine("enableworkspacereconnect:i:0");
streamWriter.WriteLine("full address:s:" + address);
streamWriter.WriteLine("gatewaybrokeringtype:i:0");
streamWriter.WriteLine("gatewaycredentialssource:i:4");
streamWriter.WriteLine("gatewayhostname:s:");
streamWriter.WriteLine("gatewayprofileusagemethod:i:0");
streamWriter.WriteLine("gatewayusagemethod:i:4");
streamWriter.WriteLine("kdcproxyname:s:");
streamWriter.WriteLine("keyboardhook:i:2");
streamWriter.WriteLine("negotiate security layer:i:1");
streamWriter.WriteLine("networkautodetect:i:1");
streamWriter.WriteLine("prompt for credentials:i:0");
streamWriter.WriteLine("promptcredentialonce:i:0");
streamWriter.WriteLine("rdgiskdcproxy:i:0");
streamWriter.WriteLine("redirectclipboard:i:1");//剪贴板:1打开,0关闭
streamWriter.WriteLine("redirectcomports:i:0");
streamWriter.WriteLine("redirectposdevices:i:0");
streamWriter.WriteLine("redirectprinters:i:1"); //打印机:1打开,0关闭
streamWriter.WriteLine("redirectsmartcards:i:1");
streamWriter.WriteLine("remoteapplicationmode:i:0");
streamWriter.WriteLine("screen mode id:i:2");
streamWriter.WriteLine("session bpp:i:32");
streamWriter.WriteLine("shell working directory:s:");
streamWriter.WriteLine("use multimon:i:0");
streamWriter.WriteLine("use redirection server name:i:0");
streamWriter.WriteLine("videoplaybackmode:i:1");
streamWriter.WriteLine("winposstr:s:0,3,0,0,800,600");
if (!string.IsNullOrEmpty(username))
{
streamWriter.WriteLine("username:s:" + username);
}
if (!string.IsNullOrEmpty(password))
{
streamWriter.WriteLine("password 51:b:" + Encrypt(password));
}
}
}
}
}
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApp1
{
public static class RDPHelper
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct DATA_BLOB
{
public int cbData;
public IntPtr pbData;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct CRYPTPROTECT_PROMPTSTRUCT
{
public int cbSize;
public int dwPromptFlags;
public IntPtr hwndApp;
public string szPrompt;
}
[DllImport("crypt32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool CryptProtectData(ref DATA_BLOB pDataIn, string szDataDescr, ref DATA_BLOB pOptionalEntropy, IntPtr pvReserved, ref CRYPTPROTECT_PROMPTSTRUCT pPromptStruct, int dwFlags, ref DATA_BLOB pDataOut);
private static string Encrypt(string password)
{
byte[] bytes = Encoding.Unicode.GetBytes(password);
DATA_BLOB dATA_BLOB = default(DATA_BLOB);
DATA_BLOB dATA_BLOB2 = default(DATA_BLOB);
DATA_BLOB dATA_BLOB3 = default(DATA_BLOB);
dATA_BLOB.cbData = bytes.Length;
dATA_BLOB.pbData = Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, dATA_BLOB.pbData, bytes.Length);
dATA_BLOB3.cbData = 0;
dATA_BLOB3.pbData = IntPtr.Zero;
dATA_BLOB2.cbData = 0;
dATA_BLOB2.pbData = IntPtr.Zero;
CRYPTPROTECT_PROMPTSTRUCT cRYPTPROTECT_PROMPTSTRUCT = new CRYPTPROTECT_PROMPTSTRUCT
{
cbSize = Marshal.SizeOf(typeof(CRYPTPROTECT_PROMPTSTRUCT)),
dwPromptFlags = 0,
hwndApp = IntPtr.Zero,
szPrompt = null
};
if (CryptProtectData(ref dATA_BLOB, "psw", ref dATA_BLOB3, IntPtr.Zero, ref cRYPTPROTECT_PROMPTSTRUCT, 1, ref dATA_BLOB2))
{
if (IntPtr.Zero != dATA_BLOB.pbData)
{
Marshal.FreeHGlobal(dATA_BLOB.pbData);
}
if (IntPtr.Zero != dATA_BLOB3.pbData)
{
Marshal.FreeHGlobal(dATA_BLOB3.pbData);
}
byte[] array = new byte[dATA_BLOB2.cbData];
Marshal.Copy(dATA_BLOB2.pbData, array, 0, dATA_BLOB2.cbData);
return BitConverter.ToString(array).Replace("-", string.Empty);
}
return string.Empty;
}
public static void CreateProfile(string filename, string address, string username, string password)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter streamWriter = new StreamWriter(filename, true))
{
streamWriter.WriteLine("allow desktop composition:i:0");
streamWriter.WriteLine("allow font smoothing:i:0");
streamWriter.WriteLine("alternate shell:s:");
streamWriter.WriteLine("audiocapturemode:i:0");
streamWriter.WriteLine("audiomode:i:0");//音频:0播放,2关闭
streamWriter.WriteLine("authentication level:i:2");
streamWriter.WriteLine("autoreconnection enabled:i:1");
streamWriter.WriteLine("bandwidthautodetect:i:1");
streamWriter.WriteLine("bitmapcachepersistenable:i:1");
streamWriter.WriteLine("compression:i:1");
streamWriter.WriteLine("connection type:i:7");
streamWriter.WriteLine("desktopheight:i:900");
streamWriter.WriteLine("desktopwidth:i:1440");
streamWriter.WriteLine("disable cursor setting:i:0");
streamWriter.WriteLine("disable full window drag:i:1");
streamWriter.WriteLine("disable menu anims:i:1");
streamWriter.WriteLine("disable themes:i:0");
streamWriter.WriteLine("disable wallpaper:i:0");
streamWriter.WriteLine("displayconnectionbar:i:1");
streamWriter.WriteLine("drivestoredirect:s:");
streamWriter.WriteLine("enableworkspacereconnect:i:0");
streamWriter.WriteLine("full address:s:" + address);
streamWriter.WriteLine("gatewaybrokeringtype:i:0");
streamWriter.WriteLine("gatewaycredentialssource:i:4");
streamWriter.WriteLine("gatewayhostname:s:");
streamWriter.WriteLine("gatewayprofileusagemethod:i:0");
streamWriter.WriteLine("gatewayusagemethod:i:4");
streamWriter.WriteLine("kdcproxyname:s:");
streamWriter.WriteLine("keyboardhook:i:2");
streamWriter.WriteLine("negotiate security layer:i:1");
streamWriter.WriteLine("networkautodetect:i:1");
streamWriter.WriteLine("prompt for credentials:i:0");
streamWriter.WriteLine("promptcredentialonce:i:0");
streamWriter.WriteLine("rdgiskdcproxy:i:0");
streamWriter.WriteLine("redirectclipboard:i:1");//剪贴板:1打开,0关闭
streamWriter.WriteLine("redirectcomports:i:0");
streamWriter.WriteLine("redirectposdevices:i:0");
streamWriter.WriteLine("redirectprinters:i:1"); //打印机:1打开,0关闭
streamWriter.WriteLine("redirectsmartcards:i:1");
streamWriter.WriteLine("remoteapplicationmode:i:0");
streamWriter.WriteLine("screen mode id:i:2");
streamWriter.WriteLine("session bpp:i:32");
streamWriter.WriteLine("shell working directory:s:");
streamWriter.WriteLine("use multimon:i:0");
streamWriter.WriteLine("use redirection server name:i:0");
streamWriter.WriteLine("videoplaybackmode:i:1");
streamWriter.WriteLine("winposstr:s:0,3,0,0,800,600");
if (!string.IsNullOrEmpty(username))
{
streamWriter.WriteLine("username:s:" + username);
}
if (!string.IsNullOrEmpty(password))
{
streamWriter.WriteLine("password 51:b:" + Encrypt(password));
}
}
}
}
}
C#生成远程桌面rdp文件示例:
复制内容到剪贴板
程序代码

RDPHelper.CreateProfile(@"C:\mzwu_com.rdp", "192.168.0.100", "Administrator", "qwerty123");
mstsc调用rdp文件打开远程桌面示例:
复制内容到剪贴板
程序代码

mstsc C:\mzwu_com.rdp /console






评论: 0 | 引用: 0 | 查看次数: 60603
发表评论
请登录后再发表评论!