You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell脚本用凭据启动explorer.exe遇访问拒绝错误,如何解决?

问题分析与解决

1. 代码本身的语法缺陷

你的脚本里存在一个明显的拼写错误:ConvetTo-SecureString应该改为ConvertTo-SecureString(少了字母r)。虽然你提到凭据有效,但这个错误会导致脚本无法正确生成安全字符串,必须先修正。

2. 核心错误原因

你遇到的「访问被拒绝」和权限、脚本位置无关,本质是用Start-Process启动explorer.exe并指定-Credential参数的方式不被Windows支持:

  • Explorer是和当前用户桌面会话深度绑定的系统进程,Windows的会话隔离机制禁止跨凭据启动这类桌面Shell进程,哪怕你的AD凭据对共享有访问权限,也会触发权限拒绝错误。
  • 不带-Credential能运行,是因为系统缓存了你之前手动输入的凭据,访问共享时自动复用了缓存。

3. 可行的修复方案

不要通过启动Explorer来访问共享,改为先挂载共享并指定凭据,再直接启动目标软件:

方案一:使用net use挂载共享

$username = "DOMAIN\username"
$password = ConvertTo-SecureString "ThePassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($username, $password)

$sharePath = "\\192.168.X.X\folder\folder\folder"
# 挂载共享并指定凭据
net use $sharePath /user:$username $cred.GetNetworkCredential().Password

# 直接启动共享中的老旧软件(替换为实际软件路径)
Start-Process -FilePath "$sharePath\your_old_app.exe"

# 脚本结束后可选择卸载共享(按需启用)
# net use $sharePath /delete

方案二:使用New-PSDrive创建持久化映射

$username = "DOMAIN\username"
$password = ConvertTo-SecureString "ThePassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($username, $password)

$sharePath = "\\192.168.X.X\folder\folder\folder"
# 创建Z盘映射共享(可替换为其他未使用的盘符)
New-PSDrive -Name "Z" -PSProvider FileSystem -Root $sharePath -Credential $cred -Persist

# 通过盘符启动软件
Start-Process -FilePath "Z:\your_old_app.exe"

内容的提问来源于stack exchange,提问作者KJR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 09:50:10