{"id":1203,"date":"2026-09-17T13:16:30","date_gmt":"2026-09-17T05:16:30","guid":{"rendered":"https:\/\/www.x4s.cn\/?p=1203"},"modified":"2026-09-17T17:09:25","modified_gmt":"2026-09-17T09:09:25","slug":"%e8%bf%9c%e7%a8%8b%e6%a1%8c%e9%9d%a2%e9%95%9c%e5%83%8f%e8%bf%9e%e6%8e%a5%e5%90%8c%e6%ad%a5%e6%93%8d%e6%8e%a7","status":"publish","type":"post","link":"https:\/\/www.x4s.cn\/?p=1203","title":{"rendered":"\u8fdc\u7a0b\u684c\u9762\u955c\u50cf\u8fde\u63a5\u540c\u6b65\u64cd\u63a7"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u65e5\u5e38\u8fd0\u7ef4\u4e2d\u8fdc\u7a0b\u684c\u9762\u662f\u7b2c\u4e00\u94fe\u63a5\uff0c\u8fdc\u7a0b\u767b\u9646\u540e\u672c\u5730\u5c06\u65e0\u6cd5\u663e\u793a\u6b63\u5e38\u754c\u9762\uff0c\u672c\u65b9\u6848\u901a\u8fc7powershell\u811a\u672c\uff0c\u5229\u7528psexec.exe\u5de5\u5177\u5b9e\u73b0\u8fdc\u7a0b\u955c\u50cf\u684c\u9762\u8fde\u63a5\u7b56\u7565\u6ce8\u5165\u548c\u76ee\u6807\u8ba1\u7b97\u673a\u7528\u6237\u4f1a\u8bdd\u5217\u8868\u7684\u62c9\u53d6\uff0c\u5e76\u7b49\u5f85\u53d1\u8d77\u7528\u6237\u8f93\u5165\u9700\u8981\u955c\u50cf\u7684\u7528\u6237ID\u4ece\u800c\u5b9e\u73b0\u672c\u5730\u4e0e\u8fdc\u7a0b\u7684\u540c\u6b65\u663e\u793a\u548c\u952e\u76d8\u9f20\u6807\u7684\u53cc\u65b9\u64cd\u63a7\uff0c\u5bf9\u9700\u8981\u4ea4\u4e92\u6f14\u793a\u7684\u8fd0\u7ef4\u63d0\u4f9b\u8f83\u5927\u7684\u4fbf\u5229\uff0c\u514d\u9664\u7b2c\u4e09\u65b9\u684c\u7ba1\u7cfb\u7edf\u7684\u90e8\u7f72\u6216\u4e34\u65f6\u8865\u5145\uff08\u5982\u684c\u7ba1\u7cfb\u7edf\u5931\u6548\u65f6\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u4ee5\u4e0b\u4e3apowershell\u53ef\u884c\u811a\u672c\uff08\u4fdd\u5b58\u4e3arpd.ps1\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\n# ====================== \u914d\u7f6e\u533a \u53ef\u81ea\u884c\u4fee\u6539 ======================\n$PSToolsPath = \"D:\\PSTools\\PsExec.exe\"\n$RemoteUser = \".\\administrator\"\n$RemotePass = \"\u7ba1\u7406\u5458\u5bc6\u7801\"\n$WaitTimeAfterWake = 5 # \u5524\u9192\u540e\u7b49\u5f85\u79d2\u6570\uff0c\u7f51\u7edc\u5dee\u53ef\u9002\u5f53\u8c03\u5927\u52308\n# =============================================================\n\n# 1. \u83b7\u53d6\u76ee\u6807\u8ba1\u7b97\u673a\u540d\n$ComputerName = Read-Host \"\u8bf7\u8f93\u5165\u76ee\u6807\u8ba1\u7b97\u673a\u540d\u6216 IP\"\nif (&#91;string]::IsNullOrWhiteSpace($ComputerName)) { \n    Write-Host \"\u8ba1\u7b97\u673a\u540d\u4e0d\u80fd\u4e3a\u7a7a\uff01\" -ForegroundColor Red\n    exit \n}\n\nWrite-Host \"----------------------------------------\" -ForegroundColor Cyan\nWrite-Host \"1. \u6b63\u5728\u8fdc\u7a0b\u914d\u7f6e\u684c\u9762\u955c\u50cf\u7b56\u7565...\" -ForegroundColor Yellow\n\n$Target = \"\\\\$ComputerName\"\n\n# \u66ff\u6362\u539f\u6709\u7684sc\u542f\u52a8\u547d\u4ee4\uff0c\u5148\u67e5\u8be2\u670d\u52a1\u72b6\u6001\u518d\u51b3\u5b9a\u662f\u5426\u542f\u52a8\ntry {\n    $serviceStatus = sc.exe \\\\$ComputerName query termservice | findstr \"STATE\"\n    if ($serviceStatus -notmatch \"RUNNING\") {\n        Start-Process -FilePath \"sc.exe\" -ArgumentList \"\\\\$ComputerName\", \"start\", \"termservice\" -NoNewWindow -Wait -ErrorAction SilentlyContinue\n    }\n} catch {}\n\n\ntry {\n    # \u5199\u5165\u514d\u786e\u8ba4\u9634\u5f71\u6743\u9650\n    $RegCmd1 = 'reg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\" \/v Shadow \/t REG_DWORD \/d 2 \/f'\n    Start-Process -FilePath $PSToolsPath -ArgumentList $Target, \"-u\", $RemoteUser, \"-p\", $RemotePass, \"-s\", \"-h\", \"cmd\", \"\/c\", $RegCmd1 -NoNewWindow -Wait -ErrorAction Stop\n    # \u5f00\u542f\u8fdc\u7a0b\u534f\u52a9\u6743\u9650\n    $RegCmd2 = 'reg add \"HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\" \/v fAllowToGetHelp \/t REG_DWORD \/d 1 \/f'\n    Start-Process -FilePath $PSToolsPath -ArgumentList $Target, \"-u\", $RemoteUser, \"-p\", $RemotePass, \"-s\", \"-h\", \"cmd\", \"\/c\", $RegCmd2 -NoNewWindow -Wait -ErrorAction Stop\n} catch {\n    Write-Host \"\u8b66\u544a: \u7b56\u7565\u914d\u7f6e\u5931\u8d25\uff0c\u53ef\u80fd\u5df2\u5b58\u5728\u914d\u7f6e\u3002\u9519\u8bef: $_\" -ForegroundColor Yellow\n}\n\n# 2. \u83b7\u53d6\u7528\u6237\u4f1a\u8bdd\u5217\u8868\nWrite-Host \"2. \u6b63\u5728\u83b7\u53d6\u76ee\u6807\u673a\u7528\u6237\u4f1a\u8bdd\u5217\u8868...\" -ForegroundColor Yellow\n$RawList = $null\n\n# \u4f18\u5148\u7528qwinsta\u83b7\u53d6\ntry {\n    $RawList = qwinsta \/server:$ComputerName 2>$null\n} catch { $RawList = $null }\n\n# qwinsta\u5931\u8d25\u5219\u7528PsExec\u8fdc\u7a0b\u83b7\u53d6\nif (-not $RawList) {\n    $TempFile = \".\\temp_user.txt\"\n    try {\n        Start-Process -FilePath $PSToolsPath -ArgumentList $Target, \"-u\", $RemoteUser, \"-p\", $RemotePass, \"-h\", \"cmd\", \"\/c\", \"query user > `\"$TempFile`\"\" -NoNewWindow -Wait -ErrorAction Stop\n        if (Test-Path $TempFile) {\n            $RawList = Get-Content $TempFile\n            Remove-Item $TempFile -ErrorAction SilentlyContinue\n        }\n    } catch { $RawList = $null }\n}\n\nif (-not $RawList) { \n    Write-Host \"\u9519\u8bef\uff1a\u65e0\u6cd5\u83b7\u53d6\u7528\u6237\u5217\u8868\uff0c\u8bf7\u68c0\u67e5\u7f51\u7edc\u6216\u51ed\u636e\u3002\" -ForegroundColor Red\n    Read-Host \"\u6309\u56de\u8f66\u952e\u9000\u51fa...\"\n    exit \n}\n\nWrite-Host \"----------------------------------------\" -ForegroundColor Cyan\n$RawList | Out-String | Write-Host\nWrite-Host \"----------------------------------------\" -ForegroundColor Cyan\n\n# 3. \u5b8c\u5168\u79fb\u9664\u81ea\u52a8\u8bc6\u522b\u903b\u8f91\uff0c\u76f4\u63a5\u7b49\u5f85\u624b\u52a8\u8f93\u5165\u4f1a\u8bddID\nWrite-Host \"\u2705 \u4f1a\u8bdd\u5217\u8868\u62c9\u53d6\u6210\u529f\uff0c\u8bf7\u6839\u636e\u4e0a\u65b9\u663e\u793a\u7684\u5217\u8868\uff0c\u624b\u52a8\u8f93\u5165\u8981\u8fde\u63a5\u7684\u4f1a\u8bddID\" -ForegroundColor Green\n$SessID = Read-Host \"\u8bf7\u8f93\u5165\u76ee\u6807\u4f1a\u8bddID\"\n\nif (&#91;string]::IsNullOrWhiteSpace($SessID)) { \n    Write-Host \"\u672a\u8f93\u5165\u6709\u6548ID\uff0c\u7a0b\u5e8f\u9000\u51fa\u3002\" -ForegroundColor Red\n    exit \n}\n\n# 4. \u4f1a\u8bdd\u5524\u9192+\u9ed1\u5c4f\u9884\u9632\u5904\u7406\n# \u5148\u5224\u65ad\u8f93\u5165\u7684\u4f1a\u8bdd\u72b6\u6001\uff0c\u81ea\u52a8\u9002\u914d\u5524\u9192\u903b\u8f91\n$IsDisc = $false\n$IsCons = $false\nforeach ($Line in $RawList) {\n    if ($Line -match \"\\s+$SessID\\s+\u65ad\u5f00\") {\n        $IsDisc = $true\n    }\n    if ($Line -match \"console\\s+\\w*\\s+$SessID\\s+\u8fd0\u884c\u4e2d\") {\n        $IsCons = $true\n    }\n}\n\nif ($IsDisc) {\n    if ($IsCons) {\n        Write-Host \"\u68c0\u6d4b\u5230Console\u4f1a\u8bdd\u9501\u5c4f\uff0c\u6b63\u5728\u5524\u9192+\u4fee\u590d\u56fe\u5f62\u6e32\u67d3\u73af\u5883...\" -ForegroundColor DarkYellow\n        # \u5524\u9192\u9501\u5c4f\u4f1a\u8bdd\n        $TsconCmd = \"tscon $SessID \/dest:console\"\n        Start-Process -FilePath $PSToolsPath -ArgumentList $Target, \"-u\", $RemoteUser, \"-p\", $RemotePass, \"-s\", \"-i\", $SessID, \"cmd\", \"\/c\", $TsconCmd -NoNewWindow -Wait\n        Start-Sleep -Seconds 2\n        # \u5f3a\u5236\u91cd\u542f\u76ee\u6807\u4f1a\u8bdd\u7684\u684c\u9762\u8fdb\u7a0b\uff0c\u89e3\u51b3\u9ed1\u5c4f\u65e0\u684c\u9762\u95ee\u9898\n        $FixExplorerCmd = \"taskkill \/f \/im explorer.exe 2>nul &amp; start explorer.exe\"\n        Start-Process -FilePath $PSToolsPath -ArgumentList $Target, \"-u\", $RemoteUser, \"-p\", $RemotePass, \"-s\", \"-i\", $SessID, \"cmd\", \"\/c\", $FixExplorerCmd -NoNewWindow -Wait\n        Start-Sleep -Seconds $WaitTimeAfterWake\n    } else {\n        Write-Host \"\u68c0\u6d4b\u5230\u65ad\u5f00\u7684RDP\u4f1a\u8bdd\uff0c\u6b63\u5728\u9759\u9ed8\u5524\u9192...\" -ForegroundColor DarkYellow\n        $RdpPath = \"$env:TEMP\\temp_shadow.rdp\"\n        # RDP\u4f18\u5316\u914d\u7f6e\uff0c\u7981\u7528\u5bb9\u6613\u5bfc\u81f4\u9ed1\u5c4f\u7684\u9009\u9879\n        $RdpContent = @(\n            \"screen mode id:i:2\",\n            \"full address:s:$ComputerName\",\n            \"username:s:$RemoteUser\",\n            \"prompt for credentials:i:0\",\n            \"audiomode:i:2\",\n            \"bitmapcachepersistenable:i:0\",\n            \"allow desktop composition:i:0\",\n            \"allow font smoothing:i:0\",\n            \"connection type:i:1\",\n            \"disable wallpaper:i:1\"\n        )\n        $RdpContent | Out-File $RdpPath -Encoding ascii -Force\n        \n        # \u4fdd\u5b58\u51ed\u636e\n        Start-Process -FilePath \"cmd.exe\" -ArgumentList \"\/c cmdkey \/generic:TERMSRV\/$ComputerName \/user:$RemoteUser \/pass:$RemotePass\" -NoNewWindow -Wait\n        # \u4e34\u65f6\u5524\u9192\u8fde\u63a5\n        $Proc = Start-Process -FilePath \"mstsc\" -ArgumentList \"`\"$RdpPath`\"\" -PassThru\n        Start-Sleep -Seconds 4\n        $Proc | Stop-Process -Force -ErrorAction SilentlyContinue\n        # \u6e05\u7406\u51ed\u636e\n        Start-Process -FilePath \"cmd.exe\" -ArgumentList \"\/c cmdkey \/delete:TERMSRV\/$ComputerName\" -NoNewWindow -Wait\n        Remove-Item $RdpPath -ErrorAction SilentlyContinue\n    }\n}\n\n# 5. \u751f\u6210\u4f18\u5316\u7248\u9634\u5f71\u8fde\u63a5\u914d\u7f6e\n$ShadowRdpPath = \"$env:TEMP\\temp_shadow_connect.rdp\"\n@(\n    \"screen mode id:i:2\",\n    \"full address:s:$ComputerName\",\n    \"bitmapcachepersistenable:i:0\",\n    \"allow desktop composition:i:0\",\n    \"connection type:i:1\",\n    \"disable wallpaper:i:1\",\n    \"disable full window drag:i:1\",\n    \"disable menu anims:i:1\",\n    \"disable themes:i:1\",\n    \"audiomode:i:0\"\n) | Out-File $ShadowRdpPath -Encoding ascii -Force\n\nWrite-Host \"3. \u6b63\u5728\u53d1\u8d77\u514d\u786e\u8ba4\u9634\u5f71\u8fde\u63a5...\" -ForegroundColor Green\nWrite-Host \"\ud83d\udca1 \u63d0\u793a\uff1a\u5982\u679c\u8fde\u63a5\u540e\u51fa\u73b0\u9ed1\u5c4f\uff0c\u8bf7\u6309\u4e0b Ctrl+Alt+End \u5524\u9192\u5b89\u5168\u684c\u9762\uff0c\u9f20\u6807\u5373\u53ef\u6062\u590d\u64cd\u4f5c\" -ForegroundColor Cyan\n\n# \u53d1\u8d77\u5e26\u4f18\u5316\u914d\u7f6e\u7684\u9634\u5f71\u8fde\u63a5\n$MstscArgs = @(\"`\"$ShadowRdpPath`\"\", \"\/shadow:$SessID\", \"\/v:$ComputerName\", \"\/control\", \"\/noConsentPrompt\")\nStart-Process -FilePath \"mstsc\" -ArgumentList $MstscArgs -Wait\n\n# \u6e05\u7406\u4e34\u65f6\u6587\u4ef6\nRemove-Item $ShadowRdpPath -ErrorAction SilentlyContinue\nWrite-Host \"\u8fde\u63a5\u5df2\u7ed3\u675f\u3002\" -ForegroundColor Cyan\nRead-Host \"\u6309\u56de\u8f66\u952e\u5173\u95ed\u7a97\u53e3...\"\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u53ef\u901a\u8fc7\u521b\u5efardp.bat\u6279\u5904\u7406\u811a\u672c\u53cc\u51fb\u8fd0\u884c\u6765\u8c03\u7528rdp.ps1\uff08\u6587\u4ef6\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@echo off\npowershell -NoProfile -ExecutionPolicy Bypass -File \"%~dp0rdp3.ps1\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u6267\u884c\u4ea4\u4e92<br>     \u53cc\u51fbrdp.bat\u6216\u76f4\u63a5\u5728powershell\u7a97\u53e3\u6267\u884c.\\rdp.ps1<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"637\" height=\"534\" src=\"https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-8.png\" alt=\"\" class=\"wp-image-1209\" srcset=\"https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-8.png 637w, https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-8-300x251.png 300w, https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-8-50x42.png 50w\" sizes=\"auto, (max-width: 637px) 100vw, 637px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u56fe\uff0cerror code 0\u5e76\u4e0d\u662f\u6267\u884c\u51fa\u9519\uff0c\u8fd9\u4e2a\u6070\u6070\u76f8\u53cd\u662f\u8be5\u8282\u70b9\u6267\u884c\u6210\u529f\u7684\u8fd4\u56de\u4ee3\u7801\u3002<br>\u7528\u6237\u4f1a\u8bdd\u5217\u8868\u62c9\u51fa\u540e\u4f1a\u663e\u793a\u76ee\u6807\u8ba1\u7b97\u673a\u5f53\u524d\u4f1a\u8bdd\u7528\u6237\uff0c\u7c7b\u578b\u4e3a\u8fd0\u884c\u4e2d\u7684ID\u72b6\u6001\u5217\u663e\u793a\u7684\u6570\u503c\u4e3a\u6709\u6548id\uff0c\u5982\u6709\u591a\u4e2a\u7528\u6237\uff0c\u5219\u5728\u4e0b\u65b9\u8f93\u5165\u9700\u8981\u8fde\u63a5\u7684\u5bf9\u5e94\u7528\u6237ID\u540e\u56de\u8f66\u5373\u8fdb\u884c\u8fde\u63a5\uff0c\u8fde\u63a5\u6210\u529f\u4f1a\u81ea\u52a8\u5f39\u51fa\u76ee\u6807\u8ba1\u7b97\u673a\u7528\u6237\u7684\u684c\u9762\u754c\u9762\u3002<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"693\" src=\"https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-9.png\" alt=\"\" class=\"wp-image-1210\" srcset=\"https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-9.png 961w, https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-9-300x216.png 300w, https:\/\/www.x4s.cn\/wp-content\/uploads\/2026\/09\/image-9-767x553.png 767w\" sizes=\"auto, (max-width: 961px) 100vw, 961px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u65e5\u5e38\u8fd0\u7ef4\u4e2d\u8fdc\u7a0b\u684c\u9762\u662f\u7b2c\u4e00\u94fe\u63a5\uff0c\u8fdc\u7a0b\u767b\u9646\u540e\u672c\u5730\u5c06\u65e0\u6cd5\u663e\u793a\u6b63\u5e38\u754c\u9762\uff0c\u672c\u65b9\u6848\u901a\u8fc7powershell\u811a\u672c\uff0c\u5229\u7528ps<br \/><a class=\"moretag\" href=\"https:\/\/www.x4s.cn\/?p=1203\">+ Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":1151,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it"],"_links":{"self":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts\/1203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1203"}],"version-history":[{"count":3,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts\/1203\/revisions"}],"predecessor-version":[{"id":1212,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/posts\/1203\/revisions\/1212"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=\/wp\/v2\/media\/1151"}],"wp:attachment":[{"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.x4s.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}