11月162015
MSTSC远程自动登陆UDF
一直想写的个东西,主要是用来做成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
扫描二维码,在手机上阅读
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!
谢谢您的分享