Support for diacritics in scripts


  • I'm trying to simply create a .lnk files on Public Desktop, but inside a folder with diacritics for my language. Sadly it creates messed up names and I haven't found out how to make it work with correct letters. Has anyone figured it out?


  • In Notepad++ I found that setting the script contents to show in ANSI while being encoded in UTF8 creates exactly the same problem with letters with diacritics as the Powershell script.
    Still no way to fix it though.


  • are these .lnk files being copied with a filecopy module during deploy or created via one of the code modules?


  • @tyler I tried to create them via Powershell script module.


  • @eruthon Does the script code work as intended if you put it on the machine and run it locally?


  • @tyler Yep


  • @eruthon I haven't fully fleshed out this idea but you may be able to patch the issue in the short term by casting the string around until it's right. The specifics depend on what exactly is happening, From the info so far it sounds like the data is utf8 but something is assuming it's ANSI

    The syntax in powershell for this should be

    $temp = [System.Text.Encoding]::ANSI.GetBytes("text")
    $out = [System.Text.Encoding]::UTF8.GetString($temp)
    

    This will assume the binary data of "text" is encoded as ANSI, put that binary in a generic form, and then produce a UTF8 string using those bytes. You could of course collapse this into a single line, I expanded it for readability.

    It may actually be correct to do UTF8.GetBytes(), I don't have the text on hand to test. You should be able to test the method by copying the characters you see in Notepad++


  • Probably has something to do with the way the script is being saved from the webui. I would just create the script and save as a file and run a file copy module then a command module to run it.


  • @theopenem_admin I tried that, adding powershell.exe as command and a whole bunch of arguments to run it with execution bypass and adding path to application, name of the .lnk file and location to save the .lnk to.
    After adding the argument with the name of the location for the .lnk, namely "Výučbový softvér", TOEMS was unable run this instant module.
    707276eb-ea2f-4751-bccb-6b13b6b8d9fd-image.png

    Command: powershell.exe
    Arguments:

    -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file "C:\CIT\Scripts\shortcut-script.ps1" -SoftwarePath "C:\Program Files\Wireshark\Wireshark.exe" -ShortcutDirectory "Výučbový softvér" -ShortcutName "Wireshark.lnk"
    

    Script contents:

    param(
        [string]$SoftwarePath,
        [string]$ShortcutDirectory,
        [string]$ShortcutName
    )
    
    $publicDesktopPath = [System.Environment]::GetFolderPath('CommonDesktopDirectory')
    
    # Create a WScript Shell object
    $shell = New-Object -ComObject WScript.Shell
    
    # Create the software directory if it doesn't exist
    $softwareDirectory = "$publicDesktopPath\$ShortcutDirectory"
    if (-not (Test-Path -Path $softwareDirectory -PathType Container)) {
        New-Item -Path $softwareDirectory -ItemType Directory -Force
    }
    
    # Create a shortcut object
    $shortcut = $shell.CreateShortcut("$softwareDirectory\$ShortcutName")
    
    # Set the target path for the shortcut
    $shortcut.TargetPath = $SoftwarePath
    
    # Save the shortcut
    $shortcut.Save()
    
    Write-Host "Shortcut for software created on the public desktop."
    Exit 0
    

    I could try to create a singular script for every shortcut then.


  • @eruthon You want to avoid passing Výučbový softvér through Theopenem at all; either have it hardcoded in the script file, or have the script get it from somewhere else like an SMB server.