0

I want to be able to create an *.rdp file from a bat file, however I just noticed that rdp files are actually encoded as USC-2 LE BOM, while my bat is producing a UTF-8 file, here's what I do:

@echo off
> file.rdp (
echo screen mode id:i:2
... bunch of echoes
echo lastparam:: )

This produces what I expected but is encoded in UTF-8, is there a way to either:

  • Create a file, set its encoding and then apend to it?
  • Produce the output from > encoded in USC-2 LE BOM directly to a file?
  • Encode the UTF-8 file into USC-2 LE BOM within the same bat file?

I want to write this and other files using a bat so I can set Read-only permissions to the generated file and cannot think of any other alternative. This way, I'll be able to deploy a bunch of preconfigured read-only rdp files.

EDIT:

Thanks to LotPigs answer and this underrated answer I was able to use powershell to change the encoding, wanted to share how I was able to include the powershell encoding within the batch

@echo off
> utf8file ( ... )
ECHO Get-Content utf8file ^> utf16.rdp > powerShellScript.ps1
powershell.exe -ExecutionPolicy Bypass -File powerShellScript.ps1
LeedMx
  • 424
  • 4
  • 19

1 Answers1

1

As suggested by montonero use powershell with default UTF16LE encoding

> Get-Content .\UTF16LEBOM.ps1
@"
screen mode id:i:2
... bunch of echoes
lastparam::
"@ > file.rdp

> hex .\file.rdp

Detected Byte Order Mark (BOM) : UTF16LE

Blk00000: File : .\file.rdp
HexOffs.:_+0_+1_+2_+3__+4_+5_+6_+7__+8_+9_+A_+B__+C_+D_+E_+F__----____----____
00000000: FF FE 73 00  63 00 72 00  65 00 65 00  6E 00 20 00  ..s.c.r.e.e.n. .
00000010: 6D 00 6F 00  64 00 65 00  20 00 69 00  64 00 3A 00  m.o.d.e. .i.d.:.
00000020: 69 00 3A 00  32 00 0D 00  0A 00 2E 00  2E 00 2E 00  i.:.2...........
00000030: 20 00 62 00  75 00 6E 00  63 00 68 00  20 00 6F 00   .b.u.n.c.h. .o.
00000040: 66 00 20 00  65 00 63 00  68 00 6F 00  65 00 73 00  f. .e.c.h.o.e.s.
00000050: 0D 00 0A 00  6C 00 61 00  73 00 74 00  70 00 61 00  ....l.a.s.t.p.a.
00000060: 72 00 61 00  6D 00 3A 00  3A 00 0D 00  0A 00        r.a.m.:.:.....
  • so powerful... it does lack the old school swag of a simple bat but i'll try it. – LeedMx May 09 '19 at 21:51
  • Well, the lower output is in fact generated by an old vbscript/batch hybrid executed in powershell console ;-) –  May 09 '19 at 21:55
  • Maybe, but there's just something about them scripts that make me feel dirty – LeedMx May 09 '19 at 21:59
  • Just edited to go back to the old school swag within a single batch... couldn't have done it without you, thanks! – LeedMx May 09 '19 at 22:55