Writing a custom RDP file from a Kix logon script

Written by James McDonald

November 8, 2011

I attempted use the standard kix script writeLine() function to append data to a Windows .RDP file and got garbage

I wanted to add a custom “username:s:DOMAINNAME\username” line to the end of the RDP File.

Work-a-round
Use VBScript embedded in the kix script to append the string

If InGroup("MyUsers")
        ; terminal server desktop icon
	$scName = $strDesktop + "\" + "EDI Gateway.lnk"
	$scTarg = "%windir%\system32\mstsc.exe"
	$scWorkDir = "%windir%"
	$scArg =  '"%APPDATA%\MyCustomDir\custom_rdp.rdp"' + " /v:myhostname.example.com"
	$scIconLoc = ""
	$edi_rdp = "custom_rdp.rdp"
	$target_edi_rdp = $apf_app_data + "\" + $edi_rdp
	
	CreateShortcut ($scName, $scTarg, $scWorkDir, $scArg, $scIconLoc)
        ; copy rdp file to local appdata and modify
	if not Exist($target_edi_rdp)
		copy @LSERVER + "\NETLOGON\" + $edi_rdp $target_edi_rdp
		$dom_user = "username:s:MYDOMAIN" + "\" + @USERID

                ; begin vbs code but running from kix
		$fso = CreateObject("Scripting.FileSystemObject")
		$ForAppending = 8
		$TristateTrue = -1 ; open it as unicode
		; zero is false
		$textFile = $fso.OpenTextFile($target_edi_rdp, $ForAppending, 0 , $TristateTrue )
		$textFile.WriteLine(@CRLF + $dom_user + @CRLF )
		$textFile.close
	endif

EndIf

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...