Coder Social home page Coder Social logo

Comments (18)

xsy420 avatar xsy420 commented on July 23, 2024 2

try add this lot in install.bat

powershell -ExecutionPolicy ByPass -Command "Set-NetFirewallRule -DisplayGroup “网络发现” -Enabled True -Profile Any"
powershell -ExecutionPolicy ByPass -Command "Enable-NetFirewallRule -DisplayGroup “文件和打印机共享”"
powershell -ExecutionPolicy ByPass -Command "Enable-NetFirewallRule -DisplayGroup “远程桌面”"

from windows.

xsy420 avatar xsy420 commented on July 23, 2024 2

make sure your install.bat is in GBK encoding and endswith \r\n

iconv -f UTF-8 -t GBK src/install.bat target/install.bat
unix2dos target/install.bat

from windows.

xsy420 avatar xsy420 commented on July 23, 2024 2

If you or others want to try custom.iso in another language for installing and remote desktop auto enabled, translations of "Remote Desktop" will be needed. So as translations of "Network Discovery" and "File and Printer Sharing" for enabling those. Currently I only found these three maybe need to be translated.

With these months following this project, the xml files changed very often. To stay up to date, I wrote a python script for patching xml files.

from lxml import etree
import sys


def read_tag(_):
    return str(_.tag).replace('{urn:schemas-microsoft-com:unattend}', '')


def log(_tag):
    print(f'patched {_tag}')


def rewrite_xml(_root):
    for child in _root:
        real_tag = read_tag(child)

        ###
        ### start change your Locale if you want when installing
        ###
        # find your needed locale from https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10)
        if real_tag in ['UILanguage', 'SystemLocale', 'UserLocale']:
            child.text = 'zh-CN'
            log(real_tag)
        elif real_tag == 'InputLocale':
            child.text = '0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}'
            log(real_tag)
        ###
        ### end change your Locale
        ###

        ###
        ### start change your Username and Password if you want when installing
        ###
        elif real_tag == 'LocalAccount':
            if read_tag(child[0]) == 'Name':
                child[0].text = 'custom-username-placeholder'
                log(read_tag(child[0]))
            if read_tag(child[2]) == 'Password' and read_tag(child[2][0]) == 'Value':
                child[2][0].text = 'custom-password-placeholder'
                log(read_tag(child[2]))
        elif real_tag == 'AutoLogon':
            if read_tag(child[0]) == 'Username':
                child[0].text = 'custom-username-placeholder'
                log(read_tag(child[0]))
            if read_tag(child[3]) == 'Password' and read_tag(child[3][0]) == 'Value':
                child[3][0].text = 'custom-password-holder'
                log(read_tag(child[3]))
        ###
        ### end change your Username and Password
        ###

        else:
            rewrite_xml(child)


if __name__ == '__main__':
    origin_xml = sys.argv[1]
    new_xml = sys.argv[2]

    tree = etree.parse(origin_xml)
    root = tree.getroot()

    rewrite_xml(root)

    new_tree = etree.ElementTree(root)
    new_tree.write(new_xml)

With this script patched, you will get a custom xml file with your password in it. maybe you won't forget password.

from windows.

xsy420 avatar xsy420 commented on July 23, 2024 2

Good advice. When I wrote this script, I haven't realized that translation is the problem. Now this script can do it.

from lxml import etree
import sys

CustomUsername = "custom-username-placeholder"
CustomPassword = "custom-password-placeholder"

RemoteDesktopEnglish = "RemoteDesktop"
NetworkDiscoveryEnglish = "Network Discovery"
FileAndPrinterSharingEnglish = "File and Printer Sharing"

###
### Replace the translations
###
RemoteDesktopTranslation = "远程桌面"
NetworkDiscoveryTranslation = "网络发现"
FileAndPrinterSharingTranslation = "文件和打印机共享"


def read_tag(_):
    return str(_.tag).replace('{urn:schemas-microsoft-com:unattend}', '')


def log(_tag):
    print(f'patched {_tag}')


def rewrite_xml(_root):
    for child in _root:
        real_tag = read_tag(child)

        ###
        ### start change your Locale if you want when installing
        ###
        # find your needed locale from https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10)
        if real_tag in ['UILanguage', 'SystemLocale', 'UserLocale']:
            child.text = 'zh-CN'
            log(real_tag)
        elif real_tag == 'InputLocale':
            child.text = '0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}'
            log(real_tag)
        ###
        ### end change your Locale
        ###

        ###
        ### start change your Username and Password if you want when installing
        ###
        elif real_tag == 'LocalAccount':
            if read_tag(child[0]) == 'Name':
                child[0].text = CustomUsername
                log(read_tag(child[0]))
            if read_tag(child[2]) == 'Password' and read_tag(child[2][0]) == 'Value':
                child[2][0].text = CustomPassword
                log(read_tag(child[2]))
        elif real_tag == 'AutoLogon':
            if read_tag(child[0]) == 'Username':
                child[0].text = CustomUsername
                log(read_tag(child[0]))
            if read_tag(child[3]) == 'Password' and read_tag(child[3][0]) == 'Value':
                child[3][0].text = CustomPassword
                log(read_tag(child[3]))
        ###
        ### end change your Username and Password
        ###

        ###
        ### start change three translations if you want when installing
        ###
        elif real_tag == 'FirewallGroup':
            if RemoteDesktopEnglish in child.attrib.values():
                for _ in child:
                    if read_tag(_) == 'Group':
                        _.text = RemoteDesktopTranslation
                       log(RemoteDesktopEnglish)
        elif real_tag == 'FirstLogonCommands':
            for _ in child:
                if _[2].text == 'Enable Network Discovery':
                    _[1].text = _[1].text.replace(NetworkDiscoveryEnglish, NetworkDiscoveryTranslation)
                   log(NetworkDiscoveryEnglish)
                if _[2].text == 'Enable File Sharing':
                    _[1].text = _[1].text.replace(FileAndPrinterSharingEnglish, FileAndPrinterSharingTranslation)
                   log(FileAndPrinterSharingEnglish)
        ###
        ### end change three translations if you want when installing
        ###

        else:
            rewrite_xml(child)


if __name__ == '__main__':
    origin_xml = sys.argv[1]
    new_xml = sys.argv[2]

    tree = etree.parse(origin_xml)
    root = tree.getroot()

    rewrite_xml(root)

    new_tree = etree.ElementTree(root)
    new_tree.write(new_xml)

It works!!! And you won't worry about changing file encodings.

from windows.

xsy420 avatar xsy420 commented on July 23, 2024 1

Agreed that. It'll be easy to keep it in english at default for this project.
For those who use other language, and maybe tired changing the language and wondering why these 3 things not enabled, this script helps out.
And this works for zh-cn locale
find-display-group

hope for it works for all locale.

from windows.

zhangchi6414 avatar zhangchi6414 commented on July 23, 2024

还有一个问题,当使用默认的iso时是英文的系统,可以正常使用rdp通过docker用户远程。我需要使用中文的系统,但是使用的中文系统+自动安装后无法rdp远程,提示是连接失败。这里使用的iso是https://file.cnxiaobai.com/Windows/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Windows%2011/中的win11 专业版。

from windows.

kroese avatar kroese commented on July 23, 2024

@zhangchi6414 Why not use the default English ISO and change the language AFTER installation from the Windows Control Panel instead of using a Chinese ISO?

from windows.

zhangchi6414 avatar zhangchi6414 commented on July 23, 2024

@zhangchi6414 Why not use the default English ISO and change the language AFTER installation from the Windows Control Panel instead of using a Chinese ISO?为什么不使用默认的英文 ISO 并在安装后从 Windows 控制面板更改语言,而不是使用中文 ISO?

主要是想要试一下其它的操作系统,是系统有什么问题吗?

from windows.

zhangchi6414 avatar zhangchi6414 commented on July 23, 2024

try add this lot in install.bat

powershell -ExecutionPolicy ByPass -Command "Set-NetFirewallRule -DisplayGroup “网络发现” -Enabled True -Profile Any"
powershell -ExecutionPolicy ByPass -Command "Enable-NetFirewallRule -DisplayGroup “文件和打印机共享”"
powershell -ExecutionPolicy ByPass -Command "Enable-NetFirewallRule -DisplayGroup “远程桌面”"

我做了尝试,并没有效果还会有中文乱码的情况出现

from windows.

kroese avatar kroese commented on July 23, 2024

@xsy420 Maybe your script can also patch the translations for enabling RDP and Network Discovery ?

from windows.

xsy420 avatar xsy420 commented on July 23, 2024

With this script improved and i18n of the three (maybe more needed to be translated later) collected, multi language can be supported automatically. Just with environment like:

    environment:
      UserLocale: "zh-cn" # auto patch locale settings and i18n before using xml to install

But it will need python environment in docker image. Or pre-compile script into binary file.
Or just mark it as an example i18n patch file for those who use another language.

from windows.

kroese avatar kroese commented on July 23, 2024

@xsy420 Yes I was thinking about that also.. but its a lot of work because I need to have the corrects translations that Windows uses for these RDP/Network strings in all possible languages. It would be better if I can change these firewall settings in another way that doesnt require to know their localized name.

Another problem is that a lot of the ISO's (especially for versions below Windows 8) are not multi-langual, so I will need to add a lot of extra download mirrors for each possible language.

All in all it will be a lot of effort to make sure it works for every Windows version. While the alternative (user just installs the English version and changes the language AFTER installation in the Windows Control Panel) is almost no work for the user and no work for me.

from windows.

xsy420 avatar xsy420 commented on July 23, 2024

And in my case

Enable-NetFirewallRule -DisplayGroup @(Get-NetFirewallRule | Where-Object Name -Match "NetDIS.*" | Select-Object DisplayGroup -Unique | % DisplayGroup)
Enable-NetFirewallRule -DisplayGroup @(Get-NetFirewallRule | Where-Object Name -Match "FPS-*" | Select-Object DisplayGroup -Unique | % DisplayGroup)

can enable network discovery and the FPS

from windows.

kroese avatar kroese commented on July 23, 2024

@xsy420 Yes that would be a great solution if we can just modify the commands in the .XML file so that the same .XML works for both English and Chinese.

Can you please test if this works for both languages and then submit it as a pull-request?

from windows.

zhangchi6414 avatar zhangchi6414 commented on July 23, 2024

Good advice. When I wrote this script, I haven't realized that translation is the problem. Now this script can do it.好建议。当我写这个剧本时,我还没有意识到翻译是问题所在。现在这个脚本可以做到了。

from lxml import etree
import sys

CustomUsername = "custom-username-placeholder"
CustomPassword = "custom-password-placeholder"

RemoteDesktopEnglish = "RemoteDesktop"
NetworkDiscoveryEnglish = "Network Discovery"
FileAndPrinterSharingEnglish = "File and Printer Sharing"

###
### Replace the translations
###
RemoteDesktopTranslation = "远程桌面"
NetworkDiscoveryTranslation = "网络发现"
FileAndPrinterSharingTranslation = "文件和打印机共享"


def read_tag(_):
    return str(_.tag).replace('{urn:schemas-microsoft-com:unattend}', '')


def log(_tag):
    print(f'patched {_tag}')


def rewrite_xml(_root):
    for child in _root:
        real_tag = read_tag(child)

        ###
        ### start change your Locale if you want when installing
        ###
        # find your needed locale from https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10)
        if real_tag in ['UILanguage', 'SystemLocale', 'UserLocale']:
            child.text = 'zh-CN'
            log(real_tag)
        elif real_tag == 'InputLocale':
            child.text = '0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}'
            log(real_tag)
        ###
        ### end change your Locale
        ###

        ###
        ### start change your Username and Password if you want when installing
        ###
        elif real_tag == 'LocalAccount':
            if read_tag(child[0]) == 'Name':
                child[0].text = CustomUsername
                log(read_tag(child[0]))
            if read_tag(child[2]) == 'Password' and read_tag(child[2][0]) == 'Value':
                child[2][0].text = CustomPassword
                log(read_tag(child[2]))
        elif real_tag == 'AutoLogon':
            if read_tag(child[0]) == 'Username':
                child[0].text = CustomUsername
                log(read_tag(child[0]))
            if read_tag(child[3]) == 'Password' and read_tag(child[3][0]) == 'Value':
                child[3][0].text = CustomPassword
                log(read_tag(child[3]))
        ###
        ### end change your Username and Password
        ###

        ###
        ### start change three translations if you want when installing
        ###
        elif real_tag == 'FirewallGroup':
            if RemoteDesktopEnglish in child.attrib.values():
                for _ in child:
                    if read_tag(_) == 'Group':
                        _.text = RemoteDesktopTranslation
                       log(RemoteDesktopEnglish)
        elif real_tag == 'FirstLogonCommands':
            for _ in child:
                if _[2].text == 'Enable Network Discovery':
                    _[1].text = _[1].text.replace(NetworkDiscoveryEnglish, NetworkDiscoveryTranslation)
                   log(NetworkDiscoveryEnglish)
                if _[2].text == 'Enable File Sharing':
                    _[1].text = _[1].text.replace(FileAndPrinterSharingEnglish, FileAndPrinterSharingTranslation)
                   log(FileAndPrinterSharingEnglish)
        ###
        ### end change three translations if you want when installing
        ###

        else:
            rewrite_xml(child)


if __name__ == '__main__':
    origin_xml = sys.argv[1]
    new_xml = sys.argv[2]

    tree = etree.parse(origin_xml)
    root = tree.getroot()

    rewrite_xml(root)

    new_tree = etree.ElementTree(root)
    new_tree.write(new_xml)

It works!!! And you won't worry about changing file encodings.它有效!!而且您不必担心更改文件编码。

感谢,您这个方法非常有效!

from windows.

xsy420 avatar xsy420 commented on July 23, 2024

Yeah. It works fine. I've tested win10 and win11 version, both english and chinese iso.(using VERSION: "win10" and VERSION: "win11" in compose.yml to get english iso. using pre-downloaded chinese simplified win10 and win11 iso and volumn as custom.iso)
To enable Network Discovery and the FPS, it's easy to change CommandLine tag.
To enable RDP, and able to support multi language, I add a new SynchronousCommand tag. And it duplicates the content in FirewallGroup tag. So I deleted the whole in the parent component tag. RDP still auto enabled in en-us and zh-cn locale. Will that be okay?
How many xml files should I commit? All of them?

from windows.

kroese avatar kroese commented on July 23, 2024

Yes please!

from windows.

kroese avatar kroese commented on July 23, 2024

I now released a new image (v3.07) which has multi-language support and can download Chinese versions. If you set for example:

environment:
  REGION: "zh-HK"
  KEYBOARD: "zh-HK"
  LANGUAGE: "Chinese"

it will automaticly download the Chinese Windows and apply the keyboard config, etc.

from windows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.