Windows - HowardWhile/2022_note GitHub Wiki
Windows
遠端桌面多開的方法
https://weirenxue.github.io/2021/06/13/rdp_windows_10_multi/
連線數量的問題?

http://blog.itpub.net/9252210/viewspace-590677/
增加连接数量,即设置可连接的数量多些默认情况下允许远程终端连接的数量是2个用户,我们可以根据需要适当增加远程连接同时在线的用户数。
单击开始→运行,输入gpedit.msc打开组策略编辑器窗口,依次定位到计算机配置→管理模板→Windows 组件→遠程桌面服務→連接→限制連接的數量,再双击右侧的“限制连接数量”,将其TS允许的最大连接数设置大一些即可。記得要重新開機

Windows7 安裝沒有USB3.0驅動的問題
https://ericchannet.wordpress.com/2021/04/16/install-windows-7-add-usb-driver/
1 – 準備文件
在你的硬碟C建立一個名為 temp 的資料夾 在 temp 下建立五個資料夾,分別命名為 src , mount , winremount , hotfix 和 drivers
將 ISO 檔用 WinRAR 或 7-Zip 解壓至 C:\temp\src 到主機板官網,尋找你的主機板型號驅動程式。Eric 在此用 MSI B450 Gaming Plus Max 做例子。下載 Chipset Driver,更重要是 USB Driver

解壓縮文件,花一些時間找找 Hotfix 之類的文件,可能是 “.msu" 或 “.cab" 檔案,複製到 C:\temp\hotfix
將 USB 驅動程式檔案複製到 C:\temp\drivers
2 – 使用CMD DISM
用管理員身份打開 cmd.exe,然後輸入以下文字, 每段文字都是一行不分開 (當然是複製文字比較快)
dism /Mount-Image /ImageFile:c:\temp\src\sources\boot.wim /Index:1 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Unmount-Image /MountDir:C:\temp\mount /Commit
dism /Mount-Image /ImageFile:c:\temp\src\sources\boot.wim /Index:2 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
將 C:\temp\mount\sources 下的全部內容,複製並覆蓋到 C:\temp\src\sources,然後執行下列 DISM 指令
dism /Unmount-Image /MountDir:C:\temp\mount /commit
執行下列指令以取得 Install.wim 檔案中的索引, 然後檢查每個索引,以確定必須更新的索引數
dism /Get-WimInfo /WimFile:c:\temp\src\sources\install.wim
以下例子是4個,每段文字都是一行不分開
dism /Mount-Image /ImageFile:c:\temp\src\sources\install.wim /Index:1 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Mount-Image /ImageFile:c:\temp\mount\windows\system32\recovery\winre.wim /Index:1 /MountDir:c:\temp\winremount
dism /Image:C:\temp\winremount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\winremount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Unmount-Wim /MountDir:C:\temp\winremount /Commit
dism /Unmount-Wim /MountDir:C:\temp\mount /Commit
............ 下面是索引 2 ............
dism /Mount-Image /ImageFile:c:\temp\src\sources\install.wim /Index:2 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Mount-Image /ImageFile:c:\temp\mount\windows\system32\recovery\winre.wim /Index:1 /MountDir:c:\temp\winremount
dism /Image:C:\temp\winremount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\winremount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Unmount-Wim /MountDir:C:\temp\winremount /Commit
dism /Unmount-Wim /MountDir:C:\temp\mount /Commit
............ 下面是索引 3 ............
dism /Mount-Image /ImageFile:c:\temp\src\sources\install.wim /Index:3 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Mount-Image /ImageFile:c:\temp\mount\windows\system32\recovery\winre.wim /Index:1 /MountDir:c:\temp\winremount
dism /Image:C:\temp\winremount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\winremount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Unmount-Wim /MountDir:C:\temp\winremount /Commit
dism /Unmount-Wim /MountDir:C:\temp\mount /Commit
............ 下面是索引 4 ............
dism /Mount-Image /ImageFile:c:\temp\src\sources\install.wim /Index:4 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Mount-Image /ImageFile:c:\temp\mount\windows\system32\recovery\winre.wim /Index:1 /MountDir:c:\temp\winremount
dism /Image:C:\temp\winremount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\winremount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Unmount-Wim /MountDir:C:\temp\winremount /Commit
dism /Unmount-Wim /MountDir:C:\temp\mount /Commit
............ 下面是索引 5 ............
dism /Mount-Image /ImageFile:c:\temp\src\sources\install.wim /Index:5 /MountDir:c:\temp\mount
dism /Image:C:\temp\mount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\mount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Mount-Image /ImageFile:c:\temp\mount\windows\system32\recovery\winre.wim /Index:1 /MountDir:c:\temp\winremount
dism /Image:C:\temp\winremount /Add-Package /PackagePath:c:\temp\hotfix
dism /Image:C:\temp\winremount /Add-Driver /Driver:c:\temp\drivers /Recurse
dism /Unmount-Wim /MountDir:C:\temp\winremount /Commit
dism /Unmount-Wim /MountDir:C:\temp\mount /Commit
3 – 不要關閉CMD,在網上下載 oscdimg
載點,把 oscdimg.exe 放在 C:\Windows\System32
然後繼續CMD工作,建立新ISO檔
UEFI模式可以讓你安裝在GPT硬碟中,並且是用UEFI啟動的
選擇一:適用於 Legacy BIOS 開機模式:
oscdimg -LTEST -m -u2 -bC:\temp\src\boot\etfsboot.com C:\temp\src C:\temp\Win7.NVME.ISO
選擇二: 適用於 Legacy 和 UEFI BIOS 多重開機模式:
oscdimg -LTEST -m -u2 -bootdata:2#p0,e,bC:\temp\src\boot\etfsboot.com#pEF,e,bC:\temp\src\efi\microsoft\boot\efisys.bin C:\temp\src C:\temp\Win7.NVME.ISO
使用 ISO 檔建立可開機的 USB(FAT32 格式)或可開機的 DVD
如果 ISO 檔的大小超過 4.7 GB,請使用雙層 DVD 或藍光光碟來燒錄 ISO 檔
如果是 UEFI 開機(僅適用於 64 位元版本的 Windows 7 作業系統或更高版本),請檢查 USB 快閃記憶體隨身碟的 EFI\BOOT\ 下是否有 BOOTX64.EFI 檔案。如果沒有,請執行下列動作:
- 將 bootmgfw.efi 檔案從 C:\Windows\Boot\EFI 複製到 USB 快閃記憶體隨身碟的 EFI\BOOT\ 中
- 將檔案重新命名為 BOOTX64.EFI
4 – 安裝
Eric在此將ISO檔燒錄在光碟內,開機時按下F11 (以MSI主機板為例),選擇有UEFI字樣的光機,就成功進入安裝畫面
要注意,剛才Eric加入的是 USB 3.1 Driver,所以我的 MSI B450 主機板,只有兩個3.1插頭可用,另外的 USB 3.0 和 2.0 沒反應,是正常的
5 – 建議
安裝 KB3138612、KB3004394 及 WUFUC(WUFUC 用來關閉"不支援的硬件"提示),否則系統更新器無法正常運作
停用串口滑鼠
-
win + R 執行
regedit
-
前往路徑
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sermouse
-
將名為
Start的機碼由3改成4 -

-
重開機
透過proxy安裝choco
ref https://docs.chocolatey.org/en-us/guides/usage/proxy-settings-for-chocolatey
先從其他台電腦下載安裝的 install.ps1 https://community.chocolatey.org/install.ps1
將安裝的指令由
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
改成
$env:chocolateyProxyLocation = '127.0.0.1:20809'
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Ne
t.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::Sec
urityProtocol -bor 3072; iex (C:\install.ps1)
安裝 OpenSSH Server
online安裝
感謝G米大力支援提供



接下來步驟就跟offline安裝的第4步一樣
offline的安裝方法
第1步 下載安裝包
https://github.com/PowerShell/Win32-OpenSSH/releases
可以直接用資料夾裡面載好的...

這邊有個坑,最新版的V8.9.1.0p1-Beta,隨然ssh可以連線但是sftp一連上就會斷線。所以還是選擇與線上安裝一致的v8.1版本。
第2步 解壓縮

解壓縮到C:\並將資料夾重新命名成OpenSSH。資料夾的內容長這樣:

不一定要解壓縮到這個路徑,只是這個路徑比較好記,之後的終端機操作時比較方便。
第3步 安裝
這邊的安裝步驟比較特別不是透過setup.msi或是setup.exe安裝,而是透過終端機執行install-sshd.ps1安裝,是具有管理員權限的powershell終端機。

具體方法如下:

用管理員身分執行powershell
執行下列指令
cd C:\OpenSSH\
.\install-sshd.ps1

此時在透過Get-Service sshpowershell的service中就可以看到sshd的服務(Stopped)出現。

如果要反安裝只要執行uninstall-sshd.ps1,
第4步 啟動
安裝完成後執行下列指令來啟動openssh-server先用預設的配置來啟動
# 啟動 sshd 服務
Start-Service sshd
# 設定 sshd 服務自動啟動
Set-Service -Name sshd -StartupType 'Automatic'
嘗試登入這台 Windows 的 OpenSSH Server
ssh localhost
第5步 配置
建立一個帳號名稱為 ar 的使用者,使用 net user 命令快速建立使用者:
net user ar * /ADD
初始化的配置檔將會出現在這個路徑當中C:\ProgramData\ssh\sshd_config
用附件中的sshd_config覆蓋後重新啟動openssh-server
Restart-Service sshd
這個配置檔的內容修改了兩處為了達成2功能
- Port
因為port 22太敏感所以改成2222

- 限制特定使用者的權限
這裡的 Match User ar 就是只針對單一使用者 ar 進行設定,最後的 ForceCommand internal-sftp 就是為了讓該 ar 使用者無法使用SSH遠端登入主機,只能使用 SFTP 傳檔而已。這裡最重要的當然就是 ChrootDirectory 設定,他會把使用者「關在」特定一個目錄下,遠端透過 SFTP 操作檔案時,是完全看不到 Windows 電腦中的任何其他資料夾!

有關防火牆
方法1 用指定應用程式的方式配置方法如下:
從控制台進入控制台\系統及安全性\Windows Defender 防火牆\允許的應用程式


方法2 用指定port的方式
開通port 2222
# 設定新的 OpenSSH Server 防火牆規則
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 2222
第6步 測試
用filezilla的sftp連線看看,主機的開頭一定要打sftp://才能指定使用sftp的通訊協定,記得從本機連線成功後,也要試試從另外一台電腦連線測是防火牆的配置是否妥當。

定時自動刪除檔案
https://pureinfotech.com/delete-files-older-than-days-windows-10/
ForFiles /p "D:\Filetime\tmp" /s /d -2 /c "cmd /c del /q @file"
https://techexpert.tips/windows/windows-create-scheduled-task-command-line/
建立每天9點執行的任務
SCHTASKS /Create /SC MINUTE /TN "定期清理" /TR "C:\test\test.bat"
SCHTASKS /Create /SC daily /tn "MYTASK-DAILY-21PM" /TR "C:\test\test.bat" /ST 21:00
工作排程器
WIN+R
taskschd.msc