0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Windowsで「パスを通す」ための操作 - by GUI and CUI

Last updated at Posted at 2023-09-23

0. 動機

PowerShellスクリプトをWindowsキー + Rの「ファイル名を指定して実行」からすぐに起動できるようにしたいな、と思ってやってみました。この記事以外にもパスの通し方について解説している記事はごまんとあるのは承知ですが、一応私の言葉でも書いておこうと思います。


なお個人PCと社内PCでは設定する変数が違う可能性があるので、設定する際は自分のPCの画面をよく見てトライしてみてください。(私はド素人なので最初この辺ごっちゃになって結構混乱しました)

1. Windowsのエディション

  • Windows 10 EnterPrise

2. 設定後の環境

  • 「ファイル名を指定して実行」で追加したパスに保存されているスクリプト名を入力すると実行できるようになります。起動までの工程が少なくて非常に楽です。
    image.png

3. GUIでの設定方法

  • 「設定」を開いて(Windowsキー + i)から「システム」を選択
    image.png

  • 「詳細情報」から「システムの詳細設定」を選択
    image.png

  • 「詳細設定」タブから「環境変数」を選択
    image.png

  • 「ユーザー環境変数」または「システム環境変数」の"Path"(変数名)にスクリプトが保管してあるパスを追加
    image.png

  • 参考:追加したパスの中身
    image.png

4. CUIでの設定方法

  • PSコンソールを管理者権限で起動後下記を実行。
#既存の環境変数Pathを変数に格納 (ユーザー環境変数の場合は最後の"Machine"を"User"に変更)
$oldPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")

#自分が追加したいパスを追加
$oldPath += 'C:\Users\XX_Path\;'

#既存の環境変数Pathを変数に格納 (システム環境変数の場合は最後の"Machine"を"User"に変更)
[System.Environment]::SetEnvironmentVariable("Path", $oldPath, "Machine")

5. おわりに

基本自分用メモですがどこかの誰かの役に立てば幸いです。Qiitaは編集しやすくていいですね。

私は非IT企業の非IT職種(専攻も非IT)の人間なのですが、PowerShellの件気軽に相談できる人が周り(社内)にいないこともあり、もし「こここうやってやるともっと楽だよ」とか「こういう改善加えてみました」みたいな意見もしあれば是非教えてください!

6. 余談

  • PowerShellスクリプトをダブルクリックで実行できるようにしたい場合は下記参照

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?