2026年2月4日水曜日

Windows 起動時に特定のページで Chrome を起動する方法

Windows 起動時に特定のページで Chrome を起動する方法

概要

ホームページにはしたくないが Windows 起動時に特定ページを開く方法を紹介します

環境

  • Windows11
  • Chrome 144.0.7559.110

shell:startup を開く

エクスプローラで「shell:startup」と入力し起動時に自動で開くフォルダを開きます

ショートカットの作成

  • 右クリック
  • 新規作成
  • ショートカット

ショートカットの設定

  • 項目の場所を入力してくださいに以下を入力
    • "C:\Program Files\Google\Chrome\Application\chrome.exe" "http://xxx.xxx.xxx.xxx"
  • 次へ
  • 適当なショートカットの名前を設定

最後に

ホームページを設定し Chrome のショートカットをスタートアップに追加してもいいですがホームページに設定すると毎回そのページからになるのでそれが嫌な場合は便利です

2026年2月3日火曜日

VSCode + Continue でエージェント開発をする

VSCode + Continue でエージェント開発をする

概要

前回 VSCode + copilot + ollama でローカル開発する方法を紹介しました
Ask モードしか使えないのが残念でした
今回は VSCode + continue + ollama で Agent 開発してみます

環境

  • M2 mac mini macOS 26.2
    • ollama 0.14.3
    • codegemma 7b
    • llama3.1 8b
  • VSCode 1.108.2

Continue のインストール

VSCode の拡張一覧から「continue」で検索しインストールすれば OK です

https://github.com/continuedev/continue

Continue の設定

  • 左メニューから Continue のアイコンを選択
  • 右上の歯車マークを選択
  • Configs
  • Local Config の歯車マークを選択
  • YAML を以下のように編集 (IP部分は適宜変更)
name: Local Config
version: 1.0.0
schema: v1
models:
  - name: codegemma
    provider: ollama
    model: codegemma:latest
    apiBase: http://192.168.1.65:11434
    roles:
      - chat
      - edit
      - apply
      - autocomplete

動作確認

あとは Continue のチャット画面に移動しチャットすれば OK です
「Agent」になっておりかつ先程設定したモデルが選択されていることを確認してからチャットしましょう

M2 mac mini 上では特にストレスなくレスポンスが返ってきました

トラブルシューティング: Agent モードが使えない

「Agent might not work well with this model」という警告が出ている場合は Agent モードが使えません

codegemma は tools に対応しているモデルではないようです
https://ollama.com/library/codegemma に「Tools」というタグが付与されていないと Agent モードは使えません

なのでモデルを変更しましょう
ただ Tools が使えるモデルは比較的大きめなのでマシンスペックが必要になるので注意しましょう

公式のおすすめモデルは https://docs.continue.dev/ide-extensions/agent/model-setup です

  • ollama run llama3.2
name: Local Config
version: 1.0.0
schema: v1
models:
  - name: llama3.2
    provider: ollama
    model: llama3.2:latest
    apiBase: http://192.168.1.65:11434
    roles:
      - chat
      - edit
      - apply
      - autocomplete
    capabilities: 
     - tool_use
     - image_input

最後に

コンテキストの渡し方 (現在選択中のファイルや別のファイル) を送信する方法などは copilot chat プラグインとは少し違うので注意しましょう

また ollama を使う場合エージェントモードが使えるモデルと使えないモデルがあり使えるモデルはそれなりの大きさのモデルが必要になるようです

gemma3 などは使えませんでした
この辺り最適なモデルの選択などは続けていきたいです

エージェントモードで動かすと回答の処理や Continue の挙動がおかしくなるのでその場合は素直に Chat モードを使いましょう

参考サイト

2026年2月2日月曜日

VSCode で copilot の無料プランの上限が来たらローカル LLM を使おう

VSCode で copilot の無料プランの上限が来たらローカル LLM を使おう

概要

ollama を使います

環境

  • M2 mac mini macOS 26.2
    • ollama 0.14.3
    • codegemma 7b
  • VSCode 1.108.2

ollama の起動

インストールはこちら

LISTEN ポートを公開する場合はこちら

モデルのダウンロード

  • ollama pull codegemma

ollama run はしなくて OK です
API でモデルを指定して呼び出すだけなのでインタラクティブモードで放置しておかないで大丈夫です

VSCode の設定

ollama のエンドポイントを指定します
json は以下

{
  "github.copilot.chat.byok.ollamaEndpoint": "http://192.168.1.65:11434"
}

ここで一度 VSCode を再起動することをおすすめします

copilot 設定

  • 右ペインのチャットにある「Auto」から「Manage Models」を選択
  • 一覧に Ollama 上の codegemma モデルが表示されることを確認
  • 目のマークがあるのでクリックして有効にする

使用するモデルの選択

「Auto」ではなく追加したモデルを選択しましょう

Agent モードは使えない

copilot chat のプラグインにある「Agent」は使えないので「Ask」に切り替えましょう

動作確認

あとはいつも通りソースコードなどを選択して質問しれば回答してくれます

マシンスペックにもよりますが M2 mac mini + codegemma:7b で質問したらすぐにレスポンスが返ってきました

最後に

copilot + ollama を試してみました
Agent モードが使えないのは辛いです
次回は copilot + Continue を試してみます

参考サイト

2026年1月29日木曜日

Windows11 のプロキシ設定のセットアップスクリプトを Powershell で設定する

Windows11 のプロキシ設定のセットアップスクリプトを Powershell で設定する

概要

タイトルの通りです

環境

  • Windows11

Powershell スクリプト

# Windows proxy setup script configuration tool
# Usage: .\change_proxy.ps1 -ScriptURL "http://xxx.xxx.xxx.xxx/proxy.pac"
#        .\change_proxy.ps1 -Reset

param(
    [string]$ScriptURL = "http://xxx.xxx.xxx.xxx/proxy.pac",
    [switch]$Reset = $false
)

# Check admin privileges
function Test-IsAdmin {
    $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
    $principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
    return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

# Elevate to admin if needed
if (-not (Test-IsAdmin)) {
    Write-Host "Admin privileges required. Elevating..." -ForegroundColor Yellow
    $scriptPath = $MyInvocation.MyCommand.Path
    $arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`""
    if ($ScriptURL -ne "http://xxx.xxx.xxx.xxx/proxy.pac") {
        $arguments += " -ScriptURL `"$ScriptURL`""
    }
    if ($Reset) {
        $arguments += " -Reset"
    }
    Start-Process PowerShell -ArgumentList $arguments -Verb RunAs -Wait
    exit 0
}

if ($Reset) {
    # Reset proxy settings
    Write-Host "Resetting proxy settings..."
    netsh winhttp reset proxy

    # Reset registry settings
    $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    if (Test-Path $regPath) {
        Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0 -ErrorAction SilentlyContinue
        Set-ItemProperty -Path $regPath -Name AutoConfigURL -Value "" -ErrorAction SilentlyContinue
        Set-ItemProperty -Path $regPath -Name AutoDetect -Value 0 -ErrorAction SilentlyContinue
        Set-ItemProperty -Path $regPath -Name ProxyServer -Value "" -ErrorAction SilentlyContinue
        Write-Host "Proxy settings reset." -ForegroundColor Green
    }
} else {
    # Configure setup script
    Write-Host "Configuring setup script: $ScriptURL"

    $regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    if (-not (Test-Path $regPath)) {
        New-Item -Path $regPath -Force | Out-Null
    }

    # Disable direct proxy
    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0 -ErrorAction SilentlyContinue
    # Set auto-config script
    Set-ItemProperty -Path $regPath -Name AutoConfigURL -Value $ScriptURL -ErrorAction SilentlyContinue
    # Disable auto-detect
    Set-ItemProperty -Path $regPath -Name AutoDetect -Value 0 -ErrorAction SilentlyContinue

    Write-Host "Setup script configured." -ForegroundColor Green
}

# Display current settings
Write-Host "`nCurrent proxy settings:" -ForegroundColor Cyan
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
if (Test-Path $regPath) {
    $proxyEnable = (Get-ItemProperty -Path $regPath -Name ProxyEnable -ErrorAction SilentlyContinue).ProxyEnable
    $autoConfigURL = (Get-ItemProperty -Path $regPath -Name AutoConfigURL -ErrorAction SilentlyContinue).AutoConfigURL
    $autoDetect = (Get-ItemProperty -Path $regPath -Name AutoDetect -ErrorAction SilentlyContinue).AutoDetect
    $proxyServer = (Get-ItemProperty -Path $regPath -Name ProxyServer -ErrorAction SilentlyContinue).ProxyServer

    Write-Host "  ProxyEnable: $proxyEnable"
    Write-Host "  AutoConfigURL: $autoConfigURL"
    Write-Host "  AutoDetect: $autoDetect"
    Write-Host "  ProxyServer: $proxyServer"
}
Write-Host ""
netsh winhttp show proxy

最後に

当然ですが管理者権限が必要になります

2026年1月24日土曜日

RDP で毎回認証を求められるがそれを回避して認証情報なしで自動で接続する方法

RDP で毎回認証を求められるがそれを回避して認証情報なしで自動で接続する方法

概要

ダウンロードした RDP ファイルをコピーして書き換えて実行します 前回の続きです

環境

  • Windows11

monitory_rdp_file.ps1

param(
    [Parameter(Mandatory=$false)]
    [string]$RDPServer = "your.rdp.server.or.ip",
    
    [Parameter(Mandatory=$false)]
    [string]$RDPUsername = "domain\username",
    
    [Parameter(Mandatory=$false)]
    [string]$RDPPassword = "xxxx",
    
    [Parameter(Mandatory=$false)]
    [switch]$TestMode = $false
)

# Basic file logging to help diagnose scheduled task behavior
$logDir = Join-Path $env:LOCALAPPDATA "RDPFileMonitor"
if (-not (Test-Path $logDir)) {
    New-Item -Path $logDir -ItemType Directory -Force | Out-Null
}
$logPath = Join-Path $logDir "monitor.log"

# Emit a simple startup marker
("Started: " + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')) | Out-File -FilePath (Join-Path $logDir 'started.txt') -Append -Encoding utf8

try {
    Start-Transcript -Path $logPath -Append -ErrorAction SilentlyContinue | Out-Null
} catch {}

# Get user profile path - handle both system and user context execution
$userProfile = [Environment]::GetFolderPath("UserProfile")
if (-not (Test-Path $userProfile)) {
    $userProfile = "C:\Users\username"
}
$downloadFolder = Join-Path $userProfile "Downloads"
$targetRDPFileName = "rdgateway101_vdgate_nifcloud_net.rdp"
$processedFiles = @()

Write-Host "Starting RDP file monitoring (polling method)"
Write-Host "Executed by: $env:USERNAME from host: $env:COMPUTERNAME"
Write-Host "User Profile: $userProfile"
Write-Host "Log: $logPath"
Write-Host "Target folder: $downloadFolder"
Write-Host "Target file name: $targetRDPFileName"

if ($TestMode) {
    Write-Host "Test Mode: Running one iteration only"
} else {
    Write-Host "Checking every 2 seconds..."
}

$iterationCount = 0
$maxIterations = if ($TestMode) { 1 } else { [int]::MaxValue }

while ($iterationCount -lt $maxIterations) {
    $iterationCount++
    Write-Host "Iteration $iterationCount at $(Get-Date -Format 'HH:mm:ss')" -ForegroundColor Gray
    
    try {
        if (Test-Path $downloadFolder) {
            # Clean up processed files list - remove entries for files that no longer exist
            $processedFiles = @($processedFiles | Where-Object { Test-Path $_ })
            
            $files = Get-ChildItem -Path $downloadFolder -Filter "*.rdp" -File
            
            foreach ($file in $files) {
                if ($file.Name -eq $targetRDPFileName -and $file.FullName -notin $processedFiles) {
                    Write-Host "Target file detected: $($file.Name) at $(Get-Date -Format 'HH:mm:ss')"
                    Write-Host "Full path: $($file.FullName)"
                    
                    Start-Sleep -Seconds 2
                    
                    try {
                        Write-Host "Executing RDP file: $($file.FullName)"
                        
                        # If credentials provided, cache them and modify RDP file
                        if ($RDPUsername -and $RDPPassword) {
                            Write-Host "Caching credentials for: $RDPServer"
                            
                            # Cache credentials using cmdkey (more reliable than embedding in RDP)
                            $cmdkeyCmd = "cmdkey.exe /generic:$RDPServer /user:$RDPUsername /pass:$RDPPassword"
                            Invoke-Expression $cmdkeyCmd | Out-Null
                            Write-Host "Credentials cached successfully"
                            
                            # Read original RDP file
                            $rdpContent = Get-Content -Path $file.FullName -Encoding ASCII
                            
                            # Remove or disable credential prompting settings
                            $rdpContent = $rdpContent -replace 'prompt for credentials:i:1', 'prompt for credentials:i:0'
                            $rdpContent = $rdpContent -replace 'promptcredentialonce:i:1', 'promptcredentialonce:i:0'
                            $rdpContent = $rdpContent -replace 'enablecredsspsupport:i:1', 'enablecredsspsupport:i:0'
                            
                            # Ensure username is set in RDP file
                            if ($rdpContent -notmatch 'username:s:') {
                                $rdpContent += "`r`nusername:s:$RDPUsername"
                            } else {
                                $rdpContent = $rdpContent -replace 'username:s:.*', "username:s:$RDPUsername"
                            }
                            
                            # Create temporary RDP file
                            $tempRDPPath = [System.IO.Path]::GetTempFileName() -replace '\.tmp$', '.rdp'
                            Set-Content -Path $tempRDPPath -Value $rdpContent -Encoding ASCII
                            Write-Host "Temporary RDP file created: $tempRDPPath"
                            
                            Start-Sleep -Seconds 1
                            
                            # Execute temporary RDP file with cached credentials
                            Start-Process -FilePath $tempRDPPath
                            $processedFiles += $file.FullName
                            Write-Host "Executed successfully with cached credentials"
                            
                            # Clean up temporary file after a delay
                            Start-Sleep -Seconds 3
                            Remove-Item -Path $tempRDPPath -Force -ErrorAction SilentlyContinue
                            Write-Host "Temporary RDP file cleaned up"
                        }
                        else {
                            # Execute without credentials modification
                            Write-Host "No credentials provided, executing original RDP file"
                            Start-Process -FilePath $file.FullName
                            $processedFiles += $file.FullName
                            Write-Host "Executed successfully"
                        }
                        
                        Start-Sleep -Seconds 1
                        Remove-Item -Path $file.FullName -Force
                        Write-Host "File deleted: $($file.FullName)"
                    }
                    catch {
                        Write-Error "Error executing RDP file: $($_.Exception.Message)"
                    }
                }
            }
        }
        else {
            Write-Host "Download folder not found: $downloadFolder"
        }
    }
    catch {
        Write-Error "Error during monitoring: $($_.Exception.Message)"
    }
    
    # For test mode, exit after one iteration
    if ($TestMode) {
        Write-Host "Test mode iteration complete. Exiting."
        break
    }
    
    # Normal mode: sleep before next iteration
    Start-Sleep -Seconds 2
}

Write-Host "RDP file monitor stopped at $(Get-Date -Format 'HH:mm:ss')"
Stop-Transcript -ErrorAction SilentlyContinue

最後に

RDP ファイルは中身はテキストなのでいろいろハックできます

2026年1月23日金曜日

ダウンロードフォルダを監視し RDP ファイルを自動で開く Powershell スクリプト

ダウンロードフォルダを監視し RDP ファイルを自動で開く Powershell スクリプト

概要

今の chrome ではできないので自作する必要があります

環境

  • Windows 11

ダウンロードフォルダを監視し特定の rdp ファイルが出現したら自動で実行する Powershell

  • vim monitor_rdp_file.ps1
param()

# Basic file logging to help diagnose scheduled task behavior
$logDir = Join-Path $env:LOCALAPPDATA "RDPFileMonitor"
if (-not (Test-Path $logDir)) {
    New-Item -Path $logDir -ItemType Directory -Force | Out-Null
}
$logPath = Join-Path $logDir "monitor.log"
# Emit a simple startup marker regardless of transcript support
("Started: " + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss')) | Out-File -FilePath (Join-Path $logDir 'started.txt') -Append -Encoding utf8
try {
    Start-Transcript -Path $logPath -Append -ErrorAction SilentlyContinue | Out-Null
} catch {}

$downloadFolder = [Environment]::GetFolderPath("UserProfile") + "\Downloads"
$targetRDPFileName = "your-rdp-filename.rdp"
$processedFiles = @()

Write-Host "Starting RDP file monitoring (polling method)"
Write-Host "Log: $logPath"
Write-Host "Target folder: $downloadFolder"
Write-Host "Target file name: $targetRDPFileName"
Write-Host "Checking every 2 seconds..."

while ($true) {
    try {
        if (Test-Path $downloadFolder) {
            $files = Get-ChildItem -Path $downloadFolder -Filter "*.rdp" -File
            
            foreach ($file in $files) {
                if ($file.Name -eq $targetRDPFileName -and $file.FullName -notin $processedFiles) {
                    Write-Host "Target file detected: $($file.Name) at $(Get-Date -Format 'HH:mm:ss')"
                    Write-Host "Full path: $($file.FullName)"
                    
                    Start-Sleep -Seconds 2
                    
                    try {
                        Write-Host "Executing RDP file: $($file.FullName)"
                        # Use Start-Process for reliability in scheduled tasks
                        Start-Process -FilePath $file.FullName
                        $processedFiles += $file.FullName
                        Write-Host "Executed successfully"
                        
                        Start-Sleep -Seconds 1
                        Remove-Item -Path $file.FullName -Force
                        Write-Host "File deleted: $($file.FullName)"
                    }
                    catch {
                        Write-Error "Error executing RDP file: $($_.Exception.Message)"
                    }
                }
            }
        }
    }
    catch {
        Write-Error "Error during monitoring: $($_.Exception.Message)"
    }
    
    Start-Sleep -Seconds 2
}
finally {
    try { Stop-Transcript | Out-Null } catch {}
}

上記ファイルを実行する bat ファイル

権限を付与して実行する必要があるのでラッパー用のバッチファイルを作成します

  • vim monitor_rdp_file.bat
@echo off
REM This batch file launches the RDP file monitor PowerShell script
REM It will be called by Task Scheduler at user login

REM Ensure we start in the script directory (useful for relative paths)
pushd "C:\Users\username\path\to\powershell_script\"

REM Prepare simple logs for troubleshooting
set "LOGDIR=%LOCALAPPDATA%\RDPFileMonitor"
if not exist "%LOGDIR%" mkdir "%LOGDIR%" >nul 2>&1

REM Launch the PowerShell monitor hidden with execution policy bypass and redirect output to logs
powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\Users\username\path\to\powershell_script\monitor_rdp_file.ps1" 1>>"%LOGDIR%\ps_out.log" 2>>"%LOGDIR%\ps_err.log"

popd
exit /b 0

バッチファイルをタスクスケジューラに登録する Powershell

タスクスケジューラで動かす場合はバッチファイルを登録します

  • vim register_scheduled_task.ps1
# Create scheduled task for RDP file monitor at user login
# This script should be run with administrator privileges

$taskName = "RDP File Monitor"
$taskPath = "\"
$scriptPath = "C:\Users\username\path\to\powershell_script\monitor_rdp_file.bat"

Write-Host "Creating scheduled task for RDP file monitor..."

# Check if task already exists
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue

if ($existingTask) {
    Write-Host "Task already exists. Removing..."
    Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
}

# Create task trigger (at user login)
$trigger = New-ScheduledTaskTrigger -AtLogOn

# Create task action
$workingDir = Split-Path -Path $scriptPath -Parent
$action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c `"$scriptPath`"" -WorkingDirectory $workingDir

# Create task settings
$settings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew -StartWhenAvailable

# Register the task with highest privilege
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERNAME" -RunLevel Highest -LogonType Interactive

Register-ScheduledTask -TaskName $taskName -Trigger $trigger -Action $action -Settings $settings -Principal $principal -Force

Write-Host "Task created successfully!"
Write-Host "Task name: $taskName"
Write-Host "Batch file: $scriptPath"
Write-Host "Trigger: At user login"
Write-Host ""
Write-Host "The task will now run automatically when you log in to Windows."

タスクスケジューラ登録

Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -Command `"& 'C:\Users\username\path\to\powershell_script\register_scheduled_task.ps1'`"" -Verb RunAs -Wait

最後に

これでログインすると自動で起動し監視を開始します
cmdkey などと組み合わせると自動でログインまでしてくれます
ただ rdp ファイルの prompt for credentials:i:1 が 0 になっていないとダメです
(1 でも自動入力する方法はないのだろうか)

2026年1月20日火曜日

Ubuntu24.04 に MySQL8.4 をインストールする方法

Ubuntu24.04 に MySQL8.4 をインストールする方法

概要

apt でインストールできます
ついでに unattended-upgrade にも対応しておきます

環境

  • Ubuntu 24.04
  • MySQL 8.4.7

インストール方法

curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.36-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.36-1_all.deb
sudo apt -y update
sudo apt -y install mysql-server

確認項目

  • root パスワードの設定
  • 既存の設定ファイル (my.cnf など) がある場合は上書きするか

動作確認

  • dpkg -l | grep 'mysql'
ii  default-libmysqlclient-dev:amd64       1.1.0build1                             amd64        MySQL database development files (metapackage)
ii  libmysqlclient-dev                     8.4.7-1ubuntu24.04                      amd64        MySQL development headers
ii  libmysqlclient24:amd64                 8.4.7-1ubuntu24.04                      amd64        MySQL shared client libraries
ii  mysql-apt-config                       0.8.36-1                                all          Auto configuration for MySQL APT Repo.
ii  mysql-client                           8.4.7-1ubuntu24.04                      amd64        MySQL Client meta package depending on latest version
ii  mysql-common                           8.4.7-1ubuntu24.04                      amd64        Common files shared between packages
ii  mysql-community-client                 8.4.7-1ubuntu24.04                      amd64        MySQL Client
ii  mysql-community-client-core            8.4.7-1ubuntu24.04                      amd64        MySQL Client Core Binaries
ii  mysql-community-client-plugins         8.4.7-1ubuntu24.04                      amd64        MySQL Client plugin
ii  mysql-community-server                 8.4.7-1ubuntu24.04                      amd64        MySQL Server
ii  mysql-community-server-core            8.4.7-1ubuntu24.04                      amd64        MySQL Server Core Binaries
ii  mysql-server                           8.4.7-1ubuntu24.04                      amd64        MySQL Server meta package depending on latest version

unattended-upgrade

  • grep -e 'Origin:' -e 'Suite:' /var/lib/apt/lists/repo.mysql.com_apt_ubuntu_dists_noble_*
/var/lib/apt/lists/repo.mysql.com_apt_ubuntu_dists_noble_InRelease:Origin: MySQL
  • sudo vim /etc/apt/apt.conf.d/58unattended-upgrades-mysql-packages
Unattended-Upgrade::Allowed-Origins {
        "MySQL:noble";
};

最後に

8.0 は 2026/04 で EOL なのでアップグレードしましょう

参考サイト