天天看點

開機自啟動Powershell腳本目錄前言修改系統資料庫寫批處理以管理者方式打開Posershell程式修改PS-profile最後

<a href="#%E7%9B%AE%E5%BD%95">目錄</a>

<a href="#%E5%89%8D%E8%A8%80">前言</a>

<a href="#%E4%BF%AE%E6%94%B9%E6%B3%A8%E5%86%8C%E8%A1%A8">修改系統資料庫</a>

<a href="#%E5%86%99%E6%89%B9%E5%A4%84%E7%90%86">寫批處理</a>

<a href="#%E4%BB%A5%E7%AE%A1%E7%90%86%E5%91%98%E6%96%B9%E5%BC%8F%E6%89%93%E5%BC%80posershell%E7%A8%8B%E5%BA%8F">以管理者方式打開Posershell程式</a>

<a href="#%E4%BF%AE%E6%94%B9ps-profile">修改PS-profile</a>

<a href="#%E6%9C%80%E5%90%8E">最後</a>

這絕B是個非常受用的技能。

Open Registry Editor, add a startup item

i. Locate the path“HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run”

Create a string value name Shadow

開機自啟動Powershell腳本目錄前言修改系統資料庫寫批處理以管理者方式打開Posershell程式修改PS-profile最後

ii. Right click Shadow and choose Modify…

開機自啟動Powershell腳本目錄前言修改系統資料庫寫批處理以管理者方式打開Posershell程式修改PS-profile最後

iii. Add the path of the cmd file above. For example: C:\Users\userName\Desktop\Shadow.cmd, and OK.

開機自啟動Powershell腳本目錄前言修改系統資料庫寫批處理以管理者方式打開Posershell程式修改PS-profile最後

Open a notepad and paste the command below (This file will invoke PowerShell script)

執行目前目錄下同名的.ps1腳本。

Save as shadow.cmd on your desktop.

開機自啟動Powershell腳本目錄前言修改系統資料庫寫批處理以管理者方式打開Posershell程式修改PS-profile最後

注意:并不需要照搬上面的内容,你可以在.cmd這個檔案中自定義希望被調用的Powershell腳本,就可以實作開機自啟動Powershell腳本了。後面的内容作為實驗記錄,僅供參考。

Open a notepad and paste the command below (This file will open PowerShell with administrator permission)

Save as shadow.ps1 on your desktop.

開機自啟動Powershell腳本目錄前言修改系統資料庫寫批處理以管理者方式打開Posershell程式修改PS-profile最後

Create a profile for current user’s PowerShell (This file will import module when PowerShell start)

Save as Profile.ps1 under this path “C:\Users\userName\Documents\WindowsPowerShell”, if you can’t find this folder, please create it by manual.

後部分的内容是對PS-profile的實驗内容,自啟動的原理還是在于系統資料庫的修改和.cmd檔案對指定PSScript的調用。 :-)

繼續閱讀