Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: 修改windos密码 和 使用自定义的镜像无法使用rdp远程 #490

Open
2 tasks done
zhangchi6414 opened this issue May 14, 2024 · 18 comments
Open
2 tasks done
Labels
question Further information is requested

Comments

@zhangchi6414
Copy link

Is your question not already answered in the FAQ?

  • I made sure the question is not listed in the FAQ.

Is this a general question and not a technical issue?

  • I am sure my question is not about a technical issue.

Question

当windows设置了用户密码又忘记之后,怎么实现从外部修改密码?就像一些云主机一样可以直接在页面修改系统密码。

@zhangchi6414 zhangchi6414 added the question Further information is requested label May 14, 2024
@zhangchi6414 zhangchi6414 changed the title [Question]: [Question]: 修改windos密码 和 使用自定义的镜像无法使用rdp远程 May 14, 2024
@zhangchi6414
Copy link
Author

还有一个问题,当使用默认的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 专业版。

@kroese
Copy link
Contributor

kroese commented May 14, 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?

@xsy420
Copy link
Contributor

xsy420 commented May 14, 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 “远程桌面”"

@zhangchi6414
Copy link
Author

@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?

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

@zhangchi6414
Copy link
Author

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 “远程桌面”"

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

@xsy420
Copy link
Contributor

xsy420 commented May 15, 2024

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

@xsy420
Copy link
Contributor

xsy420 commented May 15, 2024

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.

@kroese
Copy link
Contributor

kroese commented May 15, 2024

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

@xsy420
Copy link
Contributor

xsy420 commented May 15, 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.

@xsy420
Copy link
Contributor

xsy420 commented May 15, 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.

@kroese
Copy link
Contributor

kroese commented May 15, 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.

@xsy420
Copy link
Contributor

xsy420 commented May 15, 2024

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.

@xsy420
Copy link
Contributor

xsy420 commented May 15, 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

@kroese
Copy link
Contributor

kroese commented May 15, 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?

@zhangchi6414
Copy link
Author

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.它有效!!而且您不必担心更改文件编码。

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

@xsy420
Copy link
Contributor

xsy420 commented May 16, 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?

@kroese
Copy link
Contributor

kroese commented May 16, 2024

Yes please!

@kroese
Copy link
Contributor

kroese commented May 18, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants