绿色风's Blog
专注AutoIT(Au3)
  • 首页
  • 流●年
  • 笔●记
    • 学习随记
    • 源码示例
  • 脚●本
    • UDF(收集)
    • 工作室UDF
    • 工具●教程
    • 教程之GDI
  • 作●品
  • 下●载
  • 情怀ExcelTip
11月162015

MSTSC远程自动登陆UDF

作者:绿色风   发布:2015-11-16 12:59 Monday   分类:   阅读:15760次   评论:1条  

一直想写的个东西,主要是用来做成CMD方式调用的,现将制作好的UDF公开

详见源码



#include <WinAPI.au3>

#cs
;----JY_MSTSC 远程自动登陆函数
JY_MSTSC() 
    $IP = ;连接到的IP地址
    $user = ;连接的登陆用户名
    $pw = ;连接的登陆密码
    $port = ;连接的端口
    $width = ;设置显示的分辩率 宽  默认值 800
    $height = ;设置显示的分辩率 高 默认值 600
;-------------
by: 绿色风  blog: www.JianYiIT.com
#ce
Func JY_MSTSC($IP,$user,$pw,$port,$width = 800,$height = 600)       
    Local $pwj = ""
     rdp_encrypt($pw,"psw",$pwj) ;对密码进行加密处理
    Local $mingzi = "MSTSC自动登陆-简易工作室制作";取个名称而以,请不要删除,保留一下,谢谢!!!!
    Local $SaveFile = @TempDir & "\" & $mingzi & ".rdp"
    RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\LocalDevices", $IP, "REG_DWORD", "13")
    Local $rdp = "screen mode id:i:1" & @CRLF & "desktopwidth:i:" & $width & @CRLF & "desktopheight:i:" & $height & @CRLF & _
    "session bpp:i:24" & @CRLF & "winposstr:s:0,1,163,61," & @DesktopWidth & "," & @DesktopHeight & @CRLF & "compression:i:1" & @CRLF & _
    "keyboardhook:i:2" & @CRLF & "audiocapturemode:i:0" & @CRLF & "videoplaybackmode:i:1" & @CRLF & "connection type:i:2" & @CRLF & _
    "displayconnectionbar:i:1" & @CRLF & "disable wallpaper:i:1" & @CRLF & "allow font smoothing:i:0" & @CRLF & _
    "allow desktop composition:i:0" & @CRLF & "disable full window drag:i:1" & @CRLF & "disable menu anims:i:1" & @CRLF & _
    "disable themes:i:0" & @CRLF & "disable cursor setting:i:0" & @CRLF & "bitmapcachepersistenable:i:1" & @CRLF & _
    "full address:s:" & $IP & @CRLF & "audiomode:i:2" & @CRLF & "redirectprinters:i:0" & @CRLF & "redirectcomports:i:0" & @CRLF & _
    "redirectsmartcards:i:0" & @CRLF & "redirectclipboard:i:1" & @CRLF & "redirectposdevices:i:0" & @CRLF & "redirectdirectx:i:1" & @CRLF & _
    "autoreconnection enabled:i:1" & @CRLF & "authentication level:i:0" & @CRLF & "prompt for credentials:i:0" & @CRLF & _
    "negotiate security layer:i:1" & @CRLF & "remoteapplicationmode:i:0" & @CRLF & "alternate shell:s:" & @CRLF & _
    "shell working directory:s:" & @CRLF & "gatewayhostname:s:" & @CRLF & "gatewayusagemethod:i:4" & @CRLF & _
    "gatewaycredentialssource:i:4" & @CRLF & "gatewayprofileusagemethod:i:1" & @CRLF & "promptcredentialonce:i:1" & @CRLF & _
    "use redirection server name:i:0" & @CRLF & "drivestoredirect:s:" & "" & @CRLF & "username:s:" & $user & @CRLF & _
    "server port:i:" & $port & @CRLF & "password 51:b:" & $pwj & @CRLF & " "
    FileWriteLine($SaveFile, $rdp)
    ShellExecute("mstsc.exe", " " & $SaveFile)
    Sleep(3000)
    FileDelete($SaveFile)
    RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\LocalDevices", $IP)  
EndFunc
;对密码进行加密处理
 Func rdp_encrypt($szdatainput, $szdatadescr, ByRef $sout)   
     Local $tagdata_blob = "DWORD cbData;PTR pbData"
    Local $g_crypt32dll = DllOpen("Crypt32.dll")
    Local $nlen = StringLen($szdatainput) * 2
    Local $tbuffer = DllStructCreate(StringFormat("wchar[%d]", $nlen + 1))
    Local $tdata_blob = DllStructCreate($tagdata_blob)
    Local $tdatadescr = DllStructCreate(StringFormat("wchar[%d]", 2 * StringLen($szdatadescr) + 1))
    Local $tdataout = DllStructCreate($tagdata_blob)
    Local $tbufferout, $nret
    DllStructSetData($tbuffer, 1, $szdatainput)
    DllStructSetData($tdata_blob, "cbData", $nlen)
    DllStructSetData($tdata_blob, "pbData", DllStructGetPtr($tbuffer))
    DllStructSetData($tdatadescr, 1, $szdatadescr)
    $nret = DllCall($g_crypt32dll, "BOOL", "CryptProtectData", "ptr", DllStructGetPtr($tdata_blob), "ptr", DllStructGetPtr($tdatadescr), "ptr", 0, "ptr", 0, "ptr", 0, "DWORD", 0, "ptr", DllStructGetPtr($tdataout))
    If @error Then
        ConsoleWrite(StringFormat("DllCall Error:%d\n", @error))
        DllClose ($g_crypt32dll)
        Return False
    EndIf
    If $nret[0] = 0 Then
        ConsoleWrite(StringFormat("call CryptProtectData Error:%d\nErrorMessage:%s\n", _winapi_getlasterror(), _winapi_getlasterrormessage()))
        DllClose ($g_crypt32dll)
        Return False
    EndIf
    $tbufferout = DllStructCreate(StringFormat("BYTE[%d]", DllStructGetData($tdataout, "cbData")), DllStructGetData($tdataout, "pbData"))
    $sout = ""
    For $i = 0 To DllStructGetSize($tbufferout)
        $sout &= StringFormat("%02X", DllStructGetData($tbufferout, 1, $i + 1))
    Next
    _winapi_localfree(DllStructGetData($tdataout, "pbData"))
    DllClose ($g_crypt32dll)
    Return True
EndFunc






本文固定链接: http://www.jianyiit.com/post-150.html

blogger
该日志由 绿色风 于2015-11-16 12:59 Monday发表在 分类下。
版权所有:《绿色风's Blog》 → 《MSTSC远程自动登陆UDF》;
除特别标注,本博客很多文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:

扫描二维码,在手机上阅读
上一篇::控制窗口尺寸大小的一定的范围之下
下一篇:跟随鼠标的图型

热门文章

相关文章

  • TTS文本语音_UDF
  • 简单的动态密码设置
  • 字符串打乱顺序
  • 实用好玩AU3收款快捷页
  • ip加解密/字符串
评论列表 ↓
呦,果断人中龙凤! 戴志伟      2017-10-24 11:35 @回复
谢谢您的分享
取消回复

发表评论

亲,头像对么?

95 + 57 =

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


    站点统计
    • 运行时间: 20254 天
    • 日志总数: 365 篇
    • 评论数量: 7238 条
    • 微语数量: 6 条
    • 附件总量: 388 件
  • 逝出的青春

  • 打赏"绿色风"



      扫码关注本站公众号 可搜本站内容

  • Autoit V3 脚本交流群

      常驻群1:905774875
      常驻群2:40672266


  • 链接

    • AU3中文论坛
    • Excel资料库
    • 完美者博客
    • 顺网小哥'S Blog
    • 猛牛哥的博客
    • 网吧系统下载
  • 分类

    • 流●年(66)
    • 笔●记(0)
    • 脚●本(0)
    • 作品(21)
    • 学习随记(51)
    • 源码示例(68)
    • UDF(收集)(26)
    • 工作室UDF(30)
    • 工具●教程(62)
    • 教程之GDI(24)
Copyright © 2013 绿色风's Blog. Powered by emlog. Theme by 射雕天龙. 鄂ICP备2021011689号-1 鄂公网安备42102302000078号 sitemap