1

there is an error when creating .ps1 and calling the script in powershell, it gives an error

const TCHAR VpnConnectionName[] = (L"C:\\Users\\illia\\\Desktop\\temp.ps1");
const TCHAR BufferStn[] = L"cd\\";
DWORD BYTES = NULL;
        
HANDLE hFile = CreateFileW(VpnConnectionName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (INVALID_HANDLE_VALUE == hFile)
    {
        std::cout << "Console:INVALID_HANDLE_VALUE" << std::endl;
    }
    WriteFile(hFile, &BufferStn, sizeof(BufferStn), &BYTES, NULL);
    CloseHandle(hFile);

when trying calls in powershell:

Error powershell

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
0xFC
  • 11
  • 1
  • `TCHAR` = UTF16 - you need to [write a BOM](https://learn.microsoft.com/en-us/windows/win32/intl/using-byte-order-marks) to the lowest offset of the file, otherwise it's indistinguishable from an ASCII-encoded file containing `c\0d\0\\\0` – Mathias R. Jessen Dec 02 '20 at 13:19
  • I already solved the problem by using char * instead of THCAR – 0xFC Dec 02 '20 at 13:23
  • That will work too (just be aware you won't be able to use Unicode characters) – Mathias R. Jessen Dec 02 '20 at 13:24

0 Answers0