|
前言在日常开发中,如果能熟练掌握以下这些使用频率很高的脚本,那工作起来真的是手拿把攥,事半功倍,接下来给大家介绍一些我们日常使用率很高的一些脚本!常用脚本(Batchfile&VBScript)1.一键启动.bat一次双击开启多个软件,不用逐个软件双击打开,非常方便!@echooffmodeconlines=30cols=100title=一键启动:mainclscolor2eecho%time%echo.Martin'sBloghttps://javakam.github.iocolor1fecho.-----------------------------------------------------------echoStartingQQ...start"""C:\ProgramFiles(x86)\Tencent\QQ\Bin\QQScLauncher.exe"echoStartingWeChat...start"""C:\ProgramFiles\Tencent\WeChat\WeChat.exe":endecho执行完成12345678910111213141516171819202.Win11改用传统右键菜单.bat切换Win11的右键菜单或Win10旧版菜单。例如切换到Win10旧版右键菜单echooff>nul2>&1"%SYSTEMROOT%\system32\cacls.exe""%SYSTEMROOT%\system32\config\system"if'%errorlevel%'NEQ'0'(gotoUACPrompt)else(gotogotAdmin):UACPromptechoSetUAC=CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"echoUAC.ShellExecute"%~s0","","","runas",1>>"%temp%\getadmin.vbs""%temp%\getadmin.vbs"exit/B:gotAdminifexist"%temp%\getadmin.vbs"(del"%temp%\getadmin.vbs")@echooffecho.echo=============================================echo右键菜单类型echo1(Win10旧版右键菜单)echo2(Win11新版右键菜单)echo=============================================:selectset/popt=请选择操作:if%opt%==1(echo正在开启Win10旧版右键菜单》》》》》》》》》 regadd"HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"/f/ve)if%opt%==2(echo正在恢复Win11新版右键菜单》》》》》》》》》 regdelete"HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}"/f)@echooffecho*************************************echo**echo*重启任务管理器...*echo**echo*************************************taskkill/f/imexplorer.exe&startexplorer.exepause123456789101112131415161718192021222324252627282930313233343536373839404142两种菜单样式随时切换,很方便。3.Java多版本切换①以java1.8和java17为例,目录结构为:②环境变量配置Path:③SwitchJDK.bat源码及运行效果echooff%1mshtavbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c%~s0::","","runas",1)(window.close)&exitcd/d"%~dp0"@echooffrem---BaseConfig配置JDK的安装目录---:initsetJAVA_HOME8=C:\fastwork\Java\jdk1.8setJAVA_HOME17=C:\fastwork\Java\jdk17:startecho当前使用的JDK版本:java-versionecho.echo=============================================echojdk版本列表echo1(1.8)echo2(17)echo=============================================:selectset/popt=请选择jdk版本:if%opt%==1(setTARGET_JAVA_HOME=%JAVA_HOME8%)if%opt%==2(setTARGET_JAVA_HOME=%JAVA_HOME17%)echo当前选择的Java路径:%TARGET_JAVA_HOME%wmicENVIRONMENTwhere"name='JAVA_HOME'"deletewmicENVIRONMENTcreatename="JAVA_HOME",username="",VariableValue="%TARGET_JAVA_HOME%"rem--refreshenv---callRefreshEnvecho请按任意键退出!pause>nul1234567891011121314151617181920212223242526272829303132333435363738注:修改环境变量后,必须使用Win+R打开cmd的新窗口,再输入java-version进行验证才准确。此时AndroidStudio中的Terminal验证显示仍是旧的java环境,重启AS即可。4.Windows设置/取消定时关机定时关机.bat@echooff%1mshtavbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c%~s0::","","runas",1)(window.close)&exitcd/d"%~dp0"@echooffecho.echo=============================================echo定时关机echo0(取消所有定时关机)echo1小时(3600)echo2小时(7200)echo3小时(10800)echo4小时(14400)echo5小时(18000)echo6小时(21600)echo7小时(25200)echo8小时(28800)echo9小时(32400)echo10小时(36000)echo=============================================:prompt:selectset/popt=请选择:if%opt%==0( setSHUTDOWN_DELAY=0)elseif%opt%==1( setSHUTDOWN_DELAY=1)elseif%opt%==2( setSHUTDOWN_DELAY=2)elseif%opt%==3( setSHUTDOWN_DELAY=3)elseif%opt%==4( setSHUTDOWN_DELAY=4)elseif%opt%==5( setSHUTDOWN_DELAY=5)elseif%opt%==6( setSHUTDOWN_DELAY=6)elseif%opt%==7( setSHUTDOWN_DELAY=7)elseif%opt%==8( setSHUTDOWN_DELAY=8)elseif%opt%==9( setSHUTDOWN_DELAY=9)elseif%opt%==10( setSHUTDOWN_DELAY=10)else(echo输入无效!请输入有效的选择。gotoprompt)setlocalenabledelayedexpansionif%SHUTDOWN_DELAY%==0( echo已取消所有自动关机!!! Shutdown-a)else( echo%SHUTDOWN_DELAY%小时后自动关机》》》》》》》》》 set/aresult=%SHUTDOWN_DELAY%*3600 Shutdown-s-f-t!result!)echo操作已完成!可再次修改设置。gotoprompt::pause123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566效果图:定时关机_N小时.bat@REMecho定时关机@REMecho0(取消所有定时关机)@REMecho1小时(3600)@REMecho2小时(7200)@REMecho3小时(10800)@REMecho4小时(14400)@REMecho5小时(18000)@REMecho6小时(21600)@REMecho7小时(25200)@REMecho8小时(28800)@REMecho9小时(32400)@REMecho10小时(36000)Shutdown-s-f-t108001234567891011121314定时关机_取消.batShutdown-a15.控制某个服务的开启/关闭以某品牌移动硬盘的服务为例:右键开始选择计算机管理->服务和应用程序中双击服务->找到指定服务并查看属性*把服务名称放到netstart/stop后面即可echooff>nul2>&1"%SYSTEMROOT%\system32\cacls.exe""%SYSTEMROOT%\system32\config\system"if'%errorlevel%'NEQ'0'(gotoUACPrompt)else(gotogotAdmin):UACPromptechoSetUAC=CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"echoUAC.ShellExecute"%~s0","","","runas",1>>"%temp%\getadmin.vbs""%temp%\getadmin.vbs"exit/B:gotAdminifexist"%temp%\getadmin.vbs"(del"%temp%\getadmin.vbs")@echooffecho.echo=============================================echo操作类型echo1(开启服务)echo2(关闭服务)echo=============================================:selectset/popt=请选择操作:if%opt%==1(echo开启服务netstart"TosHddscSvc")if%opt%==2(echo关闭服务netstop"TosHddscSvc")::pausesetlocalenabledelayedexpansionecho执行结束,脚本5秒后自动退出...set/acount=5:loopecho剩余时间:%count%秒timeout/t1>nulset/acount-=1if%count%gtr0(gotoloop)else(echo脚本退出)endlocalexit1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950执行效果(此处设置了bat倒计时自动退出):6.设置开机启动脚本①新建xxx.vbs,设置需要开机启动的bat文件名:setws=wscript.createobject("wscript.shell")ws.run"xxxxxx.bat/start",012②把vbs脚本源文件或快捷方式放到C:\Users\用户名\AppData\Roaming\Microsoft\Windows\StartMenu\Programs\Startup(Win+R输入:shell:startup可快速打开)目录下,开机后会自动执行。如下图所示:附1:jupyter开机启动vbsjupyter_startup.vbsDimwshSetwsh=createobject("wscript.Shell")'1.使用配置文件启动jupyter_notebook_config.py'wsh.run"cmd/cjupyternotebook--no-browser",0,true'2.直接进入路径启动[推荐]wsh.run"cmd/cjupyternotebook--notebook-dir='C:\fastwork\Python\JupyterNotebook'--no-browser",0,trueSetwsh=Nothing1234567其中JupyterNotebook为存放*.ipynb文件的目录:附2:redis开机启动vbsservice_redis_startup.vbssetws=wscript.createobject("wscript.shell")ws.run"service_start.bat/start",012service_start.bat::启动redis的命令@echooff::这是简单的输出,相当于java中的system.out.println()echoredis-serverstart......::设置启动窗口的titleredis-server::定义一个变量ENV_HOMEsetENV_HOME="C:\fastwork\Redis"C:::设置启动窗口的颜色color0acd%ENV_HOME%redis-server.exeredis.windows.confexit12345678910111213147.常用jar包源码地址:javakam/FileCleaner使用方法:java-jarxxx.jarFileCleaner.jar用于清理Android/Java项目的临时编译目录,如buildclassestarget等。FileSizeCalculator.jar用于查看目录中所有文件的大小,目前仅支持MB为单位,便于删除大文件。8.Python脚本、源码、资料包直通车:学习资料已打包,需要的小伙伴可以戳这里[学习资料]或扫描下方码!!!!!!!
|
|