开机自启动Powershell脚本
2016-02-14 03:30 云物互联 阅读(124) 评论(0) 编辑 收藏 举报目录
前言
这绝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
ii. Right click Shadow and choose Modify…
iii. Add the path of the cmd file above. For example: C:\Users\userName\Desktop\Shadow.cmd, and OK.
写批处理
Open a notepad and paste the command below (This file will invoke PowerShell script)
执行当前目录下同名的.ps1脚本。
@set Path=%Path%;%SystemRoot%\system32\WindowsPowerShell\v1.0\ & powershell -ExecutionPolicy Unrestricted -NoProfile %~dpn0.ps1
exit
Save as shadow.cmd on your desktop.
注意:并不需要照搬上面的内容,你可以在.cmd这个文件中自定义希望被调用的Powershell脚本,就可以实现开机自启动Powershell脚本了。后面的内容作为实验记录,仅供参考。
以管理员方式打开Posershell程序
Open a notepad and paste the command below (This file will open PowerShell with administrator permission)
Start-Process "$PSHOME\powershell.exe" -Verb runas
Save as shadow.ps1 on your desktop.
修改PS-profile
Create a profile for current user’s PowerShell (This file will import module when PowerShell start)
$a= (Get-Host).UI.RawUI
$a.WindowTitle="MCShadow"
$a.ForegroundColor="Green"
$b=$a.WindowSize
$b.Width="120"
$b.Height="57"
$a.WindowSize=$b
Import-Module D:\ShadowMod.psm1
Start-Shadow
Write-Host "Imported Module ShadowMod.psm1"
Write-Host "Ready to use Start or Stop Shadow”
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的调用。 :-)