Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-r1-0528· DeepSeekHugging Face LMArena Human Preference 140K

常時稼働の自鯖があります。(windowsserver2022)これを利用して、webページを作成してそのページのボタン操作でBATファイルを稼働させる一番簡単な方法を教えてくだ…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-haiku-20241022’s answer.
  1. User

    常時稼働の自鯖があります。(windowsserver2022)これを利用して、webページを作成してそのページのボタン操作でBATファイルを稼働させる一番簡単な方法を教えてください。なんか出来合いのフリープログラムとかありそうなんですが。

  2. DeepSeek Assistant

    常時稼働しているWindows Server 2022上で、Webページのボタン操作でバッチファイルを実行する最も簡単な方法をご紹介します。セキュリティに注意しつつ、最小限の設定で実現できます。

    最も簡単で安全な方法: IIS + PowerShellスクリプト

    必要なもの

    • Windows Server 2022のIIS(Webサーバー機能)
    • PowerShellスクリプト(.ps1)
    • バッチファイル(.bat)

    手順

    1. IISのインストールと基本設定

    # PowerShell管理者モードで実行
    Install-WindowsFeature Web-Server -IncludeManagementTools
    

    2. 専用フォルダの作成

    C:\BatchRunner
    │   run.bat         # 実行したいバッチファイル
    │   Invoke-Batch.ps1 # バッチを呼び出すPowerShellスクリプト
    └── web
        index.html      # Webインターフェース
    

    3. PowerShellスクリプト作成 (C:\BatchRunner\Invoke-Batch.ps1)

    param($action)
    
    switch($action) {
        "run" {
            Start-Process -FilePath "C:\BatchRunner\run.bat" -WindowStyle Hidden
            "バッチを実行しました"
        }
        default {
            "無効なコマンドです"
        }
    }
    

    4. Webインターフェース作成 (C:\BatchRunner\web\index.html)

    <!DOCTYPE html>
    <html>
    <head>
        <title>バッチ実行ツール</title>
        <style>
            button { padding: 15px 30px; font-size: 18px; margin: 20px; }
        </style>
    </head>
    <body>
        <h1>バッチ実行コントロール</h1>
        
        <button onclick="runBatch()">バッチを実行</button>
        
        <div id="result"></div>
    
        <script>
            async function runBatch() {
                const response = await fetch('/cgi-bin/run.ps1?action=run');
                const result = await response.text();
                document.getElementById('result').innerText = result;
            }
        </script>
    </body>
    </html>
    

    5. IISの設定

    1. IISマネージャーを開く
    2. 新しいサイトを追加:
      • サイト名: BatchRunner
      • 物理パス: C:\BatchRunner\web
    3. CGIの設定:
      # PowerShell管理者モードで実行
      Install-WindowsFeature Web-CGI
      
    4. ハンドラーマッピングの追加:
      • 要求パス: *.ps1
      • モジュール: CgiModule
      • 実行可能ファイル: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Write-Host 'Content-Type: text/plain'; $env:QUERY_STRING; %{ $input } | . $env:REQUEST_FILENAME }"

    6. 権限設定(重要!)

    # PowerShell管理者モードで実行
    $acl = Get-Acl "C:\BatchRunner\run.bat"
    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS","ReadAndExecute","Allow")
    $acl.SetAccessRule($rule)
    Set-Acl "C:\BatchRunner\run.bat" $acl
    
    # PowerShellスクリプト実行ポリシー変更
    Set-ExecutionPolicy RemoteSigned -Force
    

    7. セキュリティ強化

    1. アクセス制限:

      • IISでIPアドレス制限を設定
      • Windowsファイアウォールでポート制限
    2. 認証の追加:

      Install-WindowsFeature Web-Basic-Auth
      
      • IISで基本認証を有効化
    3. HTTPS化:

      • 無料証明書(Let's Encrypt)を利用

    代替方法:既存のフリーツール

    セキュリティに注意が必要ですが、以下のツールも利用可能です:

    1. HFS (HTTP File Server)

    • ダウンロード: https://www.rejetto.com/hfs/
    • 特徴:
      • 単一実行ファイルで動作
      • 「Exec」機能でバッチファイルを実行可能
      • 簡単なWebインターフェース

    2. xampp + PHP

    • ダウンロード: https://www.apachefriends.org/
    • PHPスクリプト例:
      <?php
      if(isset($_POST['run_batch'])) {
          shell_exec('C:\\BatchRunner\\run.bat');
          echo "実行完了";
      }
      ?>
      <form method="post">
          <button name="run_batch">実行</button>
      </form>
      

    重要注意事項

    1. セキュリティリスク:

      • バッチ実行機能は非常に危険
      • 必ず認証を設定
      • インターネット公開は避け、VPN経由でのアクセスを推奨
    2. 権限最小化:

      • 専用の低権限アカウントを作成
      • 必要な権限のみ付与
    3. 監査:

      • 実行ログを必ず記録
      @echo off
      echo %date% %time% バッチ開始 >> C:\BatchRunner\log.txt
      (メイン処理)
      echo %date% %time% バッチ終了 >> C:\BatchRunner\log.txt
      
    4. バッチファイルの安全設計:

      • ユーザー入力を受け取らない
      • 固定パスのみ操作
      • 管理者権限が不要な設計に

    最初に紹介したIIS+PowerShellの方法が、Windows Server環境では最もネイティブで安全に実装できます。公開範囲を厳密に制限し、必ずテスト環境で動作確認してから本番運用してください。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.