【问题标题】:How does one execute the windows runas command from inside cygwin如何从 cygwin 内部执行 windows runas 命令
【发布时间】:2013-09-16 08:46:45
【问题描述】:

如果我尝试从 Cygwin 内部使用 Windows runas 命令,输入密码行会打印到标准输出,但它不会等待我将密码输入 System.in

有没有办法解决这个问题?

【问题讨论】:

  • 你不能以管理员身份运行 cygwin shell 吗?
  • 我不需要以管理员身份执行 Windows shell,我需要以具有不同权限的特定帐户执行。
  • 那么,您不能以特定帐户运行 cygwin shell 吗?
  • cygstart --action=runas 工作吗?
  • 我应该如何通过cygstart --action=runas 传递特定用户?真的没有解决办法吗?我需要在现有的 cygwin shell 中启动一个脚本,该脚本作为不同(特定)用户执行。

标签: windows bash cygwin runas


【解决方案1】:

我想我可以使用 2 个嵌套的命令提示符窗口弹出窗口来运行更改密码的脚本,

cygstart cmd /c "runas /user:DOMAIN\\USER \"powershell %cd%\\changepw.ps1\" & pause"

changepw.ps1 脚本如下,

# http://serverfault.com/questions/570476/how-can-a-standard-windows-user-change-their-password-from-the-command-line
# cygstart cmd /c "runas /user:DOMAIN\\USER \"powershell %cd%\\changepw.ps1\" & pause"

param (
    [string]$oldPassword = $( Read-Host "Old password"),
    [string]$newPassword = $( Read-Host "New password")
)

$ADSystemInfo = New-Object -ComObject ADSystemInfo
$type = $ADSystemInfo.GetType()
$user = [ADSI] "LDAP://$($type.InvokeMember('UserName', 'GetProperty', $null, $ADSystemInfo, $null))"
try {
    $user.ChangePassword($oldPassword, $newPassword)
} catch [Exception] {
    # echo $_.Exception.GetType().FullName, $_.Exception.Message
    echo $_.Exception | format-list -force
}
write-host "Press any key to continue..."
[void][System.Console]::ReadKey($true)

【讨论】:

    【解决方案2】:

    您可以启动“Cygwin Console”,而不是启动“Cygwin 终端”。你可以通过执行来做到这一点

    c:\cygwin\bin\bash.exe --Login
    

    然后,您应该能够运行本机 Windows 命令,例如 runas

    (但是,您会失去一些 POSIX 兼容性,因为 shell 将在 Windows 控制台窗口中运行,而不是在 MinTTY 终端中。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 2012-05-17
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多