2

Powershell 2.0 でこれを解決しましたが、レガシー アプリ用に Perl 5.10 に移植する必要があります。

INTERACTIVELY LOGON できない Windows サービス アカウント資格情報を perl スクリプトに$Accountandとして渡しました$Password$Account変数には、ドメイン名と AD ユーザー アカウント名が含まれます。私のPowershellソリューション(ワンライナー)は次のとおりです。

PS C:\> New-PsSession -Credential (new-object -typename System.Management.Automation.PSCredential -argumentlist '$Account', (ConvertTo-SecureString '$Password' -AsPlainText -Force)); exit-PsSession;

新しい PsSession が作成されると、アカウントの検証に合格し、次のような STDOUT への出力が得られます。

 Id Name            ComputerName    State    ConfigurationName     Availability
 -- ----            ------------    -----    -----------------     ------------
  1 Session1        localhost       Opened   Microsoft.PowerShell     Available

検証が失敗した場合、STDERR に次のような出力が得られます。

[localhost] Connecting to remote server failed with the following error message
 : Access is denied. For more information, see the about_Remote_Troubleshooting
 Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:Re
   moteRunspace) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionOpenFailed

これらの結果をプログラムで解析できます。Windows 上の Perl 5.10 でも同様のことをしたいと考えています。私がやりたいのは、対話型ログオンが拒否されることを念頭に置いて、アカウントに対してパスワードが機能することをテストすることだけです。何か案は?

4

2 に答える 2

1

perl ie backticks からのシステム コールを使用する

my $a = `powershell -command "ls;exit;"`;
if ($a =~ /pl$/) {
    print "folder contains a perl file";
} else {
    print "folder contains no perl file (strange)";
}

これが機能する場合は、単純な ls コマンドをより複雑なテキストに置き換えます。おそらく、\" " ' \' "" と '' について詳しく説明する必要があるかもしれません。

于 2013-10-09T15:00:20.407 に答える