JScript에서 대화 상자를 꺼냅니다 (Powershell, Windows.Forms 사용)
10899 단어 Windows.Forms자바스크립트PowerShell
예로 로그인 대화 상자
login.js
var echo = function (str) {
WScript.Echo(str);
// console.log(str)
};
var quit = function () {
WScript.Quit();
};
var CredentialDialog = function () {
var code = '\
Add-Type -AssemblyName System.Windows.Forms\r\n\
Add-Type -AssemblyName System\r\n\
\r\n\
$form = New-Object Windows.Forms.Form\r\n\
$form.Size = New-Object Drawing.Size @(400, 200)\r\n\
$form.ControlBox = $false\r\n\
$form.MinimizeBox = $false\r\n\
$form.MaximizeBox = $false\r\n\
$form.FormBorderStyle = [Windows.Forms.FormBorderStyle]::FixedDialog\r\n\
$form.Text = "ログイン"\r\n\
\r\n\
$okButton = New-Object Windows.Forms.Button\r\n\
$okButton.Location = New-Object Drawing.Size @(297, 115)\r\n\
$okButton.Size = New-Object Drawing.Size @(72, 25)\r\n\
$okButton.Font = New-Object Drawing.Font "MS UI Gothic", 12\r\n\
$okButton.TabIndex = 0\r\n\
$okButton.Text = "OK"\r\n\
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK\r\n\
$okButton.Add_Click({[System.Console]::Write("OK\t" + $userName.Text + "\t" + $password.Text)})\r\n\
$form.Controls.Add($okButton)\r\n\
$form.AcceptButton = $okButton\r\n\
\r\n\
$cancelButton = New-Object Windows.Forms.Button\r\n\
$cancelButton.Location = New-Object Drawing.Size @(192, 115)\r\n\
$cancelButton.Size = New-Object Drawing.Size @(72, 25)\r\n\
$cancelButton.Font = New-Object Drawing.Font "MS UI Gothic", 12\r\n\
$cancelButton.TabIndex = 1\r\n\
$cancelButton.Text = "Cancel"\r\n\
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel\r\n\
$form.Controls.Add($cancelButton)\r\n\
$form.CancelButton = $cancelButton\r\n\
\r\n\
$userName = New-Object Windows.Forms.TextBox\r\n\
$userName.Location = New-Object Drawing.Point @(108, 22)\r\n\
$userName.Size = New-Object Drawing.Size @(231, 25)\r\n\
$userName.Font = New-Object Drawing.Font "MS UI Gothic", 12\r\n\
$userName.TabIndex = 2\r\n\
$form.Controls.Add($userName)\r\n\
\r\n\
$password = New-Object Windows.Forms.TextBox\r\n\
$password.Location = New-Object Drawing.Point @(108, 69)\r\n\
$password.Size = New-Object Drawing.Size @(231, 25)\r\n\
$password.Font = New-Object Drawing.Font "MS UI Gothic", 12\r\n\
$password.PasswordChar = "*"\r\n\
$password.TabIndex = 3\r\n\
$form.Controls.Add($password)\r\n\
\r\n\
$label1 = New-Object System.Windows.Forms.Label\r\n\
$label1.Location = New-Object Drawing.Point @(12, 25)\r\n\
$label1.Size = New-Object Drawing.Point @(80, 16)\r\n\
$label1.Font = New-Object Drawing.Font "MS UI Gothic", 12\r\n\
$label1.Text = "ユーザーID"\r\n\
$form.Controls.Add($label1)\r\n\
\r\n\
$label2 = New-Object System.Windows.Forms.Label\r\n\
$label2.Location = New-Object Drawing.Point @(16, 72)\r\n\
$label2.Size = New-Object Drawing.Point @(80, 16)\r\n\
$label2.Font = New-Object Drawing.Font "MS UI Gothic", 12\r\n\
$label2.Text = "パスワード"\r\n\
$form.Controls.Add($label2)\r\n\
\r\n\
$result = $form.ShowDialog()\r\n\
';
var shellObj = WScript.CreateObject("WScript.Shell");
var execObj = shellObj.Exec("PowerShell -NonInteractive -WindowStyle Hidden -NoLogo -ExecutionPolicy Unrestricted -Command -");
execObj.StdIn.Write(code);
execObj.StdIn.Close();
var res = execObj.StdOut.ReadAll();
var rex = new RegExp("^(OK)\t(.*)\t(.*)$");
var rer = rex.exec(res);
if (rer) {
var cred = {
"userid": rer[2],
"password": rer[3]
}
return cred;
} else {
echo("ログイン情報を入力してください");
quit();
}
}
var cred = CredentialDialog();
echo(cred.userid + cred.password);
Reference
이 문제에 관하여(JScript에서 대화 상자를 꺼냅니다 (Powershell, Windows.Forms 사용)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tkyscsb/items/774ee88db1eb195d146a텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)