avatar

趣味性脚本

bat脚本区域

新建txt文件,将代码复制后另存为ANSL编码格式的文件,因为电脑默认是utf-8,有时候运行不出来就是这个原因。然后将.txt后缀名改为.bat即可点击运行。

计算当前目录大小

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@echo off
:: 智能路径处理
set "TARGET_PATH=%~1"
if "%~1"=="" set "TARGET_PATH=%~dp0"
if "%TARGET_PATH:~-1%"=="\" set "TARGET_PATH=%TARGET_PATH:~0,-1%"

:: 调用 PowerShell 计算大小(完全修复版)
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$target = '%TARGET_PATH%'; " ^
"if (-not (Test-Path -LiteralPath $target)) { " ^
" Write-Host ('[错误] 路径不存在: ' + $target) -ForegroundColor Red; " ^
" exit 1; " ^
"}; " ^
"$isFile = (Get-Item -LiteralPath $target) -is [System.IO.FileInfo]; " ^
"if ($isFile) { " ^
" $size = (Get-Item -LiteralPath $target).Length; " ^
" $sizeGB = $size / 1GB; " ^
" if ($sizeGB -ge 1) { " ^
" $displaySize = \"{0:N2} GB\" -f $sizeGB; " ^
" } else { " ^
" $displaySize = \"{0:N2} MB\" -f ($size / 1MB); " ^
" }; " ^
" [PSCustomObject]@{ " ^
" Name = [System.IO.Path]::GetFileName($target); " ^
" Size = $displaySize " ^
" } | Format-Table -AutoSize; " ^
" exit 0; " ^
"}; " ^
"$items = Get-ChildItem -LiteralPath $target -Force; " ^
"$results = @(); $totalBytes = 0; " ^
"foreach ($item in $items) { " ^
" try { " ^
" if ($item.PSIsContainer) { " ^
" $size = (Get-ChildItem -LiteralPath $item.FullName -Recurse -File -Force -ErrorAction Stop | " ^
" Measure-Object -Property Length -Sum -ErrorAction Stop).Sum; " ^
" } else { " ^
" $size = $item.Length; " ^
" }; " ^
" $totalBytes += $size; " ^
" if ($size -ge 1GB) { " ^
" $displaySize = \"{0:N2} GB\" -f ($size / 1GB); " ^
" } elseif ($size -ge 1MB) { " ^
" $displaySize = \"{0:N2} MB\" -f ($size / 1MB); " ^
" } else { " ^
" $displaySize = \"{0:N2} KB\" -f ($size / 1KB); " ^
" }; " ^
" $results += [PSCustomObject]@{ " ^
" Name = $item.Name; " ^
" Size = $displaySize; " ^
" RawSize = $size " ^
" }; " ^
" } catch { " ^
" $results += [PSCustomObject]@{ " ^
" Name = $item.Name + ' [拒绝访问]'; " ^
" Size = 'N/A'; " ^
" RawSize = -1 " ^
" }; " ^
" }; " ^
"}; " ^
"$results | Sort-Object -Property RawSize -Descending | Format-Table Name, Size -AutoSize; " ^
"$totalGB = $totalBytes / 1GB; " ^
"$totalMB = $totalBytes / 1MB; " ^
"$totalKB = $totalBytes / 1KB; " ^
"if ($totalGB -ge 1) { " ^
" $summary = \"总大小: {0:N2} GB ({1:N2} MB)\" -f $totalGB, $totalMB; " ^
"} elseif ($totalMB -ge 1) { " ^
" $summary = \"总大小: {0:N2} MB ({1:N0} KB)\" -f $totalMB, $totalKB; " ^
"} else { " ^
" $summary = \"总大小: {0:N0} KB\" -f $totalKB; " ^
"}; " ^
"Write-Host \"`n$summary`n详细统计: $totalBytes 字节\""

pause

运行结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Name                                 Size
---- ----
Program Files 4.57 GB
Program Files (x86) 2.21 GB
database 1.90 GB
software 113.14 MB
softwarenodejs 102.12 MB
压缩包 87.72 MB
WinRAR 5.75 MB
DumpStack.log.tmp 8.00 KB
$RECYCLE.BIN 0.13 KB
System Volume Information [拒绝访问] N/A



总大小: 8.99 GB (9,207.64 MB)
详细统计: 9654907173 字节
请按任意键继续. . .

右键菜单支持点击

注册表脚本

reg文件是一种“注册表脚本”,专用于修改 Windows 注册表。

  • 后缀名是 .reg
  • 本质上是 注册表项 + 命令 的文本文件
  • 运行方式:双击导入 或用 regedit /s xxx.reg 命令执行
  • 功能类似于:
    • bat 脚本作用于命令行
    • reg 脚本作用于注册表

执行步骤如下:

  1. 创建一个支持参数的 .bat 脚本
  2. 写一个 .reg 文件将它注册进右键菜单
  3. 运行 .reg 文件导入注册表即可
添加右键菜单

创建一个”添加右键菜单.reg”文件,保存位置不限制,最好跟bat脚本保存在一起,方便执行。文件代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Windows Registry Editor Version 5.00

; 1.文件夹右键菜单
[HKEY_CLASSES_ROOT\Directory\shell\计算目录大小]
@="计算目录大小"
[HKEY_CLASSES_ROOT\Directory\shell\计算目录大小\command]
@="cmd.exe /c \"\"F:\\好玩脚本程序\\计算当前目录大小.bat\" \"%1\"\""

; 2.磁盘右键菜单(如 C:\ D:\)
[HKEY_CLASSES_ROOT\Drive\shell\计算目录大小]
@="计算目录大小"
[HKEY_CLASSES_ROOT\Drive\shell\计算目录大小\command]
@="cmd.exe /c \"\"F:\\好玩脚本程序\\计算当前目录大小.bat\" \"%1\"\""

; 3.空白区域右键菜单(当前所在路径)
[HKEY_CLASSES_ROOT\Directory\Background\shell\计算目录大小]
@="计算目录大小"
[HKEY_CLASSES_ROOT\Directory\Background\shell\计算目录大小\command]
@="cmd.exe /c \"\"F:\\好玩脚本程序\\计算当前目录大小.bat\" \"%V\"\""
删除右键菜单

同样的,创建一个”删除右键菜单.reg”文件,代码如下:

1
2
3
4
5
6
7
8
9
10
Windows Registry Editor Version 5.00

; 删除文件夹右键菜单
[-HKEY_CLASSES_ROOT\Directory\shell\计算目录大小]

; 删除磁盘右键菜单
[-HKEY_CLASSES_ROOT\Drive\shell\计算目录大小]

; 删除空白区域右键菜单
[-HKEY_CLASSES_ROOT\Directory\Background\shell\计算目录大小]

win10一键垃圾清理

新建txt文件,将代码复制后另存为ANSL编码格式的文件,因为电脑默认是utf-8,有时候运行不出来就是这个原因。然后将.txt后缀名改为.bat即可点击运行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@echo off  

echo 正在清除系统垃圾文件,请稍等...... 

del /f /s /q %systemdrive%\*.tmp  

del /f /s /q %systemdrive%\*._mp  

del /f /s /q %systemdrive%\*.log  

del /f /s /q %systemdrive%\*.gid  

del /f /s /q %systemdrive%\*.chk  

del /f /s /q %systemdrive%\*.old  

del /f /s /q %systemdrive%\recycled\*.*  

del /f /s /q %windir%\*.bak  

del /f /s /q %windir%\prefetch\*.*  

rd /s /q %windir%\temp & md %windir%\temp  

del /f /q %userprofile%\cookies\*.*  

del /f /q %userprofile%\recent\*.*  

del /f /s /q “%userprofile%\Local Settings\Temporary Internet Files\*.*”  

del /f /s /q “%userprofile%\Local Settings\Temp\*.*”  

del /f /s /q “%userprofile%\recent\*.*”  

echo 清除系统LJ完成!  

echo. & pause

清空回收站

将代码复制后另存为ANSL编码格式的文件,然后将.txt后缀名改为.bat即可。

1
2
@echo off
powershell -c "Clear-RecycleBin -Force" 2>nul

软件多开登录

写入以下代码即可同时启动多个应用软件,想登几个就码入几个,最后改成.bat文件即可。

1
2
3
start "" "D:\Program Files (x86)\Tencent\WeChat\WeChat.exe"
start "" "D:\Program Files (x86)\Tencent\WeChat\WeChat.exe"
start "" "D:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe"

应用分身

比如电脑微信想多开登录,也可以写入如下bat脚本开启登录:

1
2
PATH D:\Program Files (x86)\Tencent\WeChat
start WeChat.exe&WeChat.exe

滑动关机

这个比较秀(推荐),后缀名.bat文件。

1
slidetoshutdown

重启应用

可快速重启应用程序的bat脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
@echo off
tasklist | findstr /I "Code.exe" >nul
if errorlevel 1 (
echo ABC 客户端未运行,直接启动...
) else (
echo 正在关闭 ABC 客户端...
taskkill /F /IM Code.exe >nul 2>nul
)

echo 正在启动 ABC 客户端...
start "" /B "D:\Program Files\VSCode\Code.exe"
echo 操作完成。
exit

重启桌面

有时候win10系统的扬声器或者桌面图标无法启动,可以通过bat文件来一键重启操作。

1
2
3
4
5
6
7
8
9
10
11
@echo off

taskkill /f /im explorer.exe

CD /d %userprofile%\AppData\Local

DEL IconCache.db /a

start explorer.exe

cho 执行完成

重启电脑

通过执行bat脚本文件实现一键重启电脑的操作。

1
shutdown -r -t 0

电脑睡眠

通过执行bat脚本文件实现一键睡眠的操作。

1
rundll32.exe powrprof.dll,SetSuspendState 0,1,0

屏幕亮度切换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@echo off
setlocal enabledelayedexpansion

set "brightness=10"

for /f "tokens=2 delims==." %%a in ('wmic path Win32_VideoController get CurrentHorizontalResolution /value') do (
set "resolution=%%a"
)

if exist "%temp%\brightness.txt" (
set /p brightness=<"%temp%\brightness.txt"
if !brightness! equ 10 (
set "brightness=90"
) else (
set "brightness=10"
)
)

powershell -command "(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, !brightness!)"
echo !brightness!>"%temp%\brightness.txt"

exit /b

数字时钟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@echo off
setlocal enabledelayedexpansion
color 09
mode con COLS=67 LINES=8
title 数字时钟 code by felicity
set num0_0=■■■■
set num0_1=■□□■
set num0_2=■□□■
set num0_3=■□□■
set num0_4=■□□■
set num0_5=■□□■
set num0_6=■■■■

set num1_0=□□□■
set num1_1=□□□■
set num1_2=□□□■
set num1_3=□□□■
set num1_4=□□□■
set num1_5=□□□■
set num1_6=□□□■

set num2_0=■■■■
set num2_1=□□□■
set num2_2=□□□■
set num2_3=■■■■
set num2_4=■□□□
set num2_5=■□□□
set num2_6=■■■■

set num3_0=■■■■
set num3_1=□□□■
set num3_2=□□□■
set num3_3=■■■■
set num3_4=□□□■
set num3_5=□□□■
set num3_6=■■■■

set num4_0=■□□■
set num4_1=■□□■
set num4_2=■□□■
set num4_3=■■■■
set num4_4=□□□■
set num4_5=□□□■
set num4_6=□□□■

set num5_0=■■■■
set num5_1=■□□□
set num5_2=■□□□
set num5_3=■■■■
set num5_4=□□□■
set num5_5=□□□■
set num5_6=■■■■

set num6_0=■■■■
set num6_1=■□□□
set num6_2=■□□□
set num6_3=■■■■
set num6_4=■□□■
set num6_5=■□□■
set num6_6=■■■■

set num7_0=■■■■
set num7_1=□□□■
set num7_2=□□□■
set num7_3=□□□■
set num7_4=□□□■
set num7_5=□□□■
set num7_6=□□□■

set num8_0=■■■■
set num8_1=■□□■
set num8_2=■□□■
set num8_3=■■■■
set num8_4=■□□■
set num8_5=■□□■
set num8_6=■■■■

set num9_0=■■■■
set num9_1=■□□■
set num9_2=■□□■
set num9_3=■■■■
set num9_4=□□□■
set num9_5=□□□■
set num9_6=■■■■

:lable
::获取系统时间,并去除冒号得到一个数
set str=%time:~0,-3%
set str1=%str::=%

:: 判断时间的大小以区分10点之前或之后,分别处理,因为10点之前的时间少一位数。之后把时间数字的每位数分别提出来赋给n1-n6。
if %str1% lss 100000 (
set n1=0
set n2=%str1:~1,1%
set n3=%str1:~2,1%
set n4=%str1:~3,1%
set n5=%str1:~4,1%
set n6=%str1:~5,1%
) else (
set n1=%str1:~0,1%
set n2=%str1:~1,1%
set n3=%str1:~2,1%
set n4=%str1:~3,1%
set n5=%str1:~4,1%
set n6=%str1:~5,1%
)
ping /n 2 127.0.0.1>nul &cls

:: !num%n1%_0! ,数字n1的第一行
:: !num%n1%_1! ,数字n1的第二行
:: !num%n1%_2!
:: !num%n1%_3!
:: !num%n1%_4!
:: !num%n1%_5!
:: !num%n1%_6!
::以上对应之前所赋的值,n1-n6由截取的系统时间获得


set /p =!num%n1%_0!□!num%n2%_0!□□□!num%n3%_0!□!num%n4%_0!□□□!num%n5%_0!□!num%n6%_0!<nul & echo.
set /p =!num%n1%_1!□!num%n2%_1!□□□!num%n3%_1!□!num%n4%_1!□□□!num%n5%_1!□!num%n6%_1!<nul & echo.
set /p =!num%n1%_2!□!num%n2%_2!□■□!num%n3%_2!□!num%n4%_2!□■□!num%n5%_2!□!num%n6%_2!<nul & echo.
set /p =!num%n1%_3!□!num%n2%_3!□□□!num%n3%_3!□!num%n4%_3!□□□!num%n5%_3!□!num%n6%_3!<nul & echo.
set /p =!num%n1%_4!□!num%n2%_4!□■□!num%n3%_4!□!num%n4%_4!□■□!num%n5%_4!□!num%n6%_4!<nul & echo.
set /p =!num%n1%_5!□!num%n2%_5!□□□!num%n3%_5!□!num%n4%_5!□□□!num%n5%_5!□!num%n6%_5!<nul & echo.
set /p =!num%n1%_6!□!num%n2%_6!□□□!num%n3%_6!□!num%n4%_6!□□□!num%n5%_6!□!num%n6%_6!<nul & echo.

goto :lable

vbs脚本区域

电脑念诗(香水篇)

注意双引号是英文的,然后将.txt后缀名改为.vbs即可。

1
2
set objTTS = createobject("sapi.spvoice")
objTTS.speak "芦丹氏-柏林少女:玫瑰是我偷的,你爱的人是我杀的。不爱你是假的,想忘了你是真的。冷水:所谓冷水,如人饮水冷暖自知。芦丹氏-孤儿怨:你绝非善类,我也不做好人。YSL-反转巴黎:我想和你见面,地点你选,森林沙漠,夜晚依稀的湖畔,草原大海,情分薄雾的街口,只是不要在梦里。纪梵希-心无禁忌:从此,我爱的人都像你。蒂普迪克-影中之水:我爱你只是我的事,与你无关。"

恶搞电脑自爆

同样后缀名改为.vbs即可。

1
2
msgbox"电脑即将自爆"+chr(13)+"请在15秒内离开座位"+chr(13)+"否则你死定了",2,"系统自爆提醒"
CreateObject("SAPI.SpVoice").Speak"电脑即将自爆,请在15秒内离开座位,否则你死定了!"

电脑自爆恶搞

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Set objVoice = CreateObject("SAPI.SpVoice")

' 显示消息框
MsgBox "电脑即将自爆" & vbCrLf & "请在15秒内离开座位" & vbCrLf & "否则你死定了", 2, "系统自爆提醒"

' 增加一些搞怪的语音输出
objVoice.Speak "嘿,你听到了吗?电脑即将自爆啦!你还不快跑的话,可别怪我没提醒你!"

' 每3秒发出一次 "蹦蹦蹦" 的声音
For i = 1 To 3
WScript.Sleep 3000 ' 停顿3秒
objVoice.Speak "蹦蹦蹦"
Next

' 最后警告
objVoice.Speak "时间所剩无几,你还不快点离开?记住,离开座位,才能保住小命!"

中奖千万富翁

代码写好后另存为ANSL编码格式的txt文件,再把后缀名改为.vbs。

1
2
3
4
set objTTS = createobject("sapi.spvoice")
msgbox"恭喜您上一期购买的六合彩中奖啦!"+chr(13)+"奖金为一千万元"
objTTS.speak "恭喜你中了一千万的白日梦大奖!"
objTTS.Speak"支付宝到账,一千万元"

表白恶搞

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
msgbox "做我女朋友好吗",vbQuestion,"在吗"

msgbox ("房产写你名字")

msgbox ("保大")

msgbox ("我妈会游泳")

dim j

do while j<1

Select Case msgbox("做我女朋友好吗",68,"请郑重的回答我")

Case 6 j=1

Case 7 msgbox("再给你一次机会")

end Select

loop

msgbox("我就知道你会同意的,哈哈哈哈")

表白恶搞语音版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
' 创建语音对象
Set speech = CreateObject("SAPI.SpVoice")

' 表白
speech.Speak "做我女朋友好吗"
msgbox "做我女朋友好吗", vbQuestion, "在吗"

' 房产写你名字
speech.Speak "房产写你名字"
msgbox "房产写你名字"

' 保大
speech.Speak "保大"
msgbox "保大"

' 我妈会游泳
speech.Speak "我妈会游泳"
msgbox "我妈会游泳"

' 循环询问
Dim j
Do While j < 1
Select Case msgbox("做我女朋友好吗", 68, "请郑重的回答我")
Case 6 ' Yes 按钮
j = 1
Case 7 ' No 按钮
speech.Speak "再给你一次机会"
msgbox "再给你一次机会"
End Select
Loop

' 结束语
speech.Speak "我就知道你会同意的,哈哈哈哈"
msgbox "我就知道你会同意的,哈哈哈哈"

重启应用

示例1

创建一个vsb文件,另存编码为ANSI格式即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Set WshShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

' 检查 VSCode 是否已启动
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process where Name = 'Code.exe'")

' 如果 VSCode 已经在运行,关闭它
If colProcesses.Count > 0 Then
WshShell.Run "taskkill /F /IM Code.exe", 0, True
WScript.Sleep 1000 ' 等待 1 秒钟,以确保进程关闭
End If

' 启动 VSCode
Set objExec = WshShell.Exec("""D:\Program Files\VSCode\Code.exe""") ' 使用 Exec 方法

' 等待 3 秒钟以确保 VSCode 启动
WScript.Sleep 3000

示例2

如果遇到有些应用需要管理员权限运行,且应用打开时间比较长的,可以执行以下vsb脚本代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

' 临时文件路径,用于标记脚本是否正在执行
tempFile = "C:\temp\vsCodeRunning.txt"

' 确保路径存在,如果不存在则创建
If Not objFSO.FolderExists("C:\temp") Then
objFSO.CreateFolder("C:\temp")
End If

' 检查是否已经以管理员权限运行
If Not IsAdmin() Then
' 如果没有管理员权限,重新启动脚本并以管理员身份运行
RunAsAdmin()
WScript.Quit
End If

' 检查标记文件,防止重复执行
If FileExists(tempFile) Then
WScript.Echo "脚本已经在运行,请稍后..."
WScript.Quit
End If

' 创建标记文件,表示脚本正在运行
CreateFile tempFile

' 检查 VSCode 是否已启动
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process where Name = 'Code.exe'")

' 如果 VSCode 已经在运行,关闭它
If colProcesses.Count > 0 Then
WshShell.Run "taskkill /F /IM Code.exe", 0, True
WScript.Sleep 2000 ' 等待 2 秒钟,以确保进程完全关闭
' WScript.Echo "VSCode 已关闭。" ' 输出到控制台
End If

' 启动 VSCode
WshShell.Run """D:\Program Files\Microsoft VS Code\Code.exe""", 1, False ' 使用 Run 方法,不等待

' 等待直到 VSCode 启动完成或达到最大等待次数
max_wait_time = 120
wait_interval = 5
max_attempts = max_wait_time / wait_interval
attempt = 0
Do While attempt < max_attempts
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process where Name = 'Code.exe'")
If colProcesses.Count > 0 Then
Exit Do
Else
WScript.Echo "VSCode 尚未启动,继续等待... 已等待 " & attempt * wait_interval & " 秒"
WScript.Sleep wait_interval * 1000
attempt = attempt + 1
End If
Loop

If attempt >= max_attempts Then
WScript.Echo "达到最大等待时间,VSCode 可能无法启动。"
End If

' 删除标记文件,表示脚本执行完成
DeleteFile tempFile

' 函数:检查文件是否存在
Function FileExists(filePath)
On Error Resume Next
FileExists = (Len(Dir(filePath)) > 0)
On Error GoTo 0
End Function

' 函数:创建文件
Sub CreateFile(filePath)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(filePath, True)
objFile.WriteLine("VSCode脚本正在执行")
objFile.Close
End Sub

' 函数:删除文件
Sub DeleteFile(filePath)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile filePath, True
End Sub

' 函数:检查是否以管理员身份运行
Function IsAdmin()
On Error Resume Next
Set objShell = CreateObject("Shell.Application")
If objShell.IsUserAnAdmin() Then
IsAdmin = True
Else
IsAdmin = False
End If
On Error GoTo 0
End Function

' 函数:以管理员身份重新运行脚本
Sub RunAsAdmin()
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """", "", "runas", 1
End Sub

关闭电脑

这个是vbs文件的关机命令,还可以直接cmd命令窗口:shutdown -s -t 00来关机。

1
2
3
4
5
dim WSHshell

set WSHshell = wscript.createobject("wscript.shell")

WSHshell.run "shutdown -f -s -t 00",0 ,true

消息轰炸恶搞

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
On Error Resume Next

Dim wsh,ye

set wsh=createobject("wscript.shell")

for i=1 to 30

wscript.sleep 300

wsh.AppActivate("")

wsh.sendKeys "^v"

wsh.sendKeys

wsh.sendKeys "%s"

next

wscript.quit

使用方法

  1. 复制这段代码,保存为 *.vbs后缀的VBS脚本;
  2. 打开特定聊天窗口
  3. 把想要输入的内容复制在剪切板中;
  4. 双击该脚本即可批量发送,比如设置的是循环30次发送,可任意修改。

批量启动面板

该vbs启动脚本用于双击执行批量启动面板.ps1文件,解决无法直接双击启动、关闭面板不影响已启动程序等问题。(推荐)

保存为 ANSI 编码:

  1. 用记事本打开 VBS 文件
  2. 点击”文件” → “另存为”
  3. 在保存对话框底部,将”编码”改为 ANSI
  4. 保存文件
1
2
' 应用启动面板启动器 - 无黑框版本
CreateObject("WScript.Shell").Run "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File ""F:\好玩脚本程序\批量启动面板.ps1""", 0, False

ps1脚本区域

实现双击运行 .ps1 脚本

默认情况下,双击 .ps1 文件不会直接运行,因为 PowerShell 的执行策略限制了脚本的直接执行,而且 Windows 通常将 .ps1 文件与文本编辑器关联,而不是 PowerShell 执行环境。以下是实现双击运行的步骤:

快捷方式配置

  1. 创建一个快捷方式
  • 右键点击你的脚本文件(例如 AppLauncher.ps1),选择“创建快捷方式”。
  • 将快捷方式重命名(例如 启动面板.lnk)并移动到桌面或其他方便的位置。
  1. 修改快捷方式属性
  • 右键点击快捷方式,选择“属性”。

  • 在“目标”字段中输入以下命令(替换路径为你的脚本路径):
    text

    1
    powershell.exe -ExecutionPolicy Bypass -File "C:\Path\To\Your\AppLauncher.ps1"
  • -ExecutionPolicy Bypass 绕过执行策略限制,允许脚本运行。

  • 可选:点击“更改图标”按钮,选择一个更美观的图标(例如从 shell32.dll 选择)。

  1. 双击运行
  • 双击快捷方式即可运行脚本,启动 GUI 面板。
  • 这种方法不需要修改系统执行策略,适合单机使用。

批量启动面板.ps1

另存时用带有BOM的UTF-8的编码格式进行保存。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# ============================================
# 🌞 向阳的应用启动面板 v4.1
# 功能:自定义布局界面,快速批量启动应用程序。
# ============================================

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

# 软件清单 - 使用字体图标
$apps = @(
@{Name="谷歌浏览器"; Path="C:\Program Files\Google\Chrome\Application\chrome.exe"; Icon="➲"},
@{Name="Edge 浏览器"; Path="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; Icon="➲"},
@{Name="微信"; Path="D:\Program Files\Tencent\Weixin\Weixin.exe"; Icon="☏"},
@{Name="QQ"; Path="D:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe"; Icon="♫"},
@{Name="VSCode"; Path="D:\Program Files\VSCode\Code.exe"; Icon="📄"},
@{Name="有道云笔记"; Path="D:\Program Files\ynote-desktop\有道云笔记.exe"; Icon="⚙"},
@{Name="Notepad++"; Path="E:\常用软件包\npp.8.6.7.portable.x64\notepad++.exe"; Icon="✎"},
@{Name="Photoshop"; Path="C:\Program Files\Adobe\Photoshop\photoshop.exe"; Icon="🎨"},
@{Name="Excel"; Path="C:\Program Files\Microsoft Office\Office16\EXCEL.EXE"; Icon="★"},
@{Name="Word"; Path="C:\Program Files\Microsoft Office\Office16\WINWORD.EXE"; Icon="♦"},
@{Name="PowerPoint"; Path="C:\Program Files\Microsoft Office\Office16\POWERPNT.EXE"; Icon="♣"},
@{Name="Teams"; Path="C:\Program Files\Microsoft Teams\teams.exe"; Icon="嘻嘻"},
@{Name="Slack"; Path="C:\Program Files\Slack\slack.exe"; Icon="💼"},
@{Name="Discord"; Path="C:\Program Files\Discord\Discord.exe"; Icon="⚔"},
@{Name="Spotify"; Path="C:\Program Files\Spotify\Spotify.exe"; Icon="♫"},
@{Name="计算器"; Path="C:\Windows\System32\calc.exe"; Icon="℗"},
@{Name="画图"; Path="C:\Windows\System32\mspaint.exe"; Icon="❂"},
@{Name="记事本"; Path="C:\Windows\System32\notepad.exe"; Icon="📄"}
)

# 创建主窗体
$form = New-Object System.Windows.Forms.Form
$form.Text = "🌞 向阳的应用启动面板 v4.1"
$form.StartPosition = "CenterScreen"
$form.Size = New-Object System.Drawing.Size(850, 600)
$form.BackColor = [System.Drawing.Color]::FromArgb(245, 249, 255)
$form.TopMost = $false
$form.FormBorderStyle = "FixedDialog"
$form.MaximizeBox = $false
$form.MinimizeBox = $true

# 标题面板
$headerPanel = New-Object System.Windows.Forms.Panel
$headerPanel.Size = New-Object System.Drawing.Size(810, 90)
$headerPanel.Location = New-Object System.Drawing.Point(20, 15)
$headerPanel.BackColor = [System.Drawing.Color]::FromArgb(74, 107, 255)
$headerPanel.ForeColor = [System.Drawing.Color]::White
$form.Controls.Add($headerPanel)

# 渐变背景绘制
$headerPanel.Add_Paint({
param($sender, $e)
$brush = New-Object System.Drawing.Drawing2D.LinearGradientBrush(
$sender.ClientRectangle,
[System.Drawing.Color]::FromArgb(74, 107, 255),
[System.Drawing.Color]::FromArgb(119, 146, 255),
[System.Drawing.Drawing2D.LinearGradientMode]::Horizontal
)
$e.Graphics.FillRectangle($brush, $sender.ClientRectangle)
$brush.Dispose()
})

# 标题
$titleLabel = New-Object System.Windows.Forms.Label
$titleLabel.Text = "应用启动面板"
$titleLabel.Font = New-Object System.Drawing.Font("Microsoft YaHei", 16, [System.Drawing.FontStyle]::Bold)
$titleLabel.ForeColor = [System.Drawing.Color]::White
$titleLabel.Size = New-Object System.Drawing.Size(810, 40)
$titleLabel.Location = New-Object System.Drawing.Point(0, 15)
$titleLabel.TextAlign = "MiddleCenter"
$headerPanel.Controls.Add($titleLabel)

# 副标题
$subtitleLabel = New-Object System.Windows.Forms.Label
$subtitleLabel.Text = "选择您要启动的应用程序"
$subtitleLabel.Font = New-Object System.Drawing.Font("Microsoft YaHei", 10, [System.Drawing.FontStyle]::Regular)
$subtitleLabel.ForeColor = [System.Drawing.Color]::FromArgb(230, 230, 255)
$subtitleLabel.Size = New-Object System.Drawing.Size(810, 25)
$subtitleLabel.Location = New-Object System.Drawing.Point(0, 55)
$subtitleLabel.TextAlign = "MiddleCenter"
$headerPanel.Controls.Add($subtitleLabel)

# 创建滚动面板
$scrollPanel = New-Object System.Windows.Forms.Panel
$scrollPanel.Size = New-Object System.Drawing.Size(810, 350)
$scrollPanel.Location = New-Object System.Drawing.Point(20, 120)
$scrollPanel.BackColor = [System.Drawing.Color]::White
$scrollPanel.BorderStyle = "FixedSingle"
$scrollPanel.AutoScroll = $true
$form.Controls.Add($scrollPanel)

# 创建复选框(两列布局)
$checkboxes = @()
$columnCount = 3 # 列数
$itemWidth = 200 # 增加宽度以容纳图标
$itemHeight = 50 # 每项高度
$margin = 15 # 边距

for ($i = 0; $i -lt $apps.Count; $i++) {
$app = $apps[$i]
$row = [Math]::Floor($i / $columnCount)
$column = $i % $columnCount

$x = $margin + ($column * $itemWidth)
$y = $margin + ($row * $itemHeight)

# 创建应用项面板
$itemPanel = New-Object System.Windows.Forms.Panel
$itemPanel.Size = New-Object System.Drawing.Size(($itemWidth - 25), 40)
$itemPanel.Location = New-Object System.Drawing.Point($x, $y)
$itemPanel.BackColor = [System.Drawing.Color]::FromArgb(250, 252, 255)
$itemPanel.BorderStyle = "FixedSingle"
$itemPanel.Cursor = [System.Windows.Forms.Cursors]::Hand

# 添加悬停效果
$itemPanel.Add_MouseEnter({
$this.BackColor = [System.Drawing.Color]::FromArgb(240, 245, 255)
$this.BorderStyle = "FixedSingle"
})

$itemPanel.Add_MouseLeave({
if (-not $this.Controls[0].Checked) {
$this.BackColor = [System.Drawing.Color]::FromArgb(250, 252, 255)
}
})

# 复选框
$cb = New-Object System.Windows.Forms.CheckBox
$cb.Text = " $($app.Icon) $($app.Name)" # 增加图标与文字间距
$cb.Tag = $app.Path
$cb.Font = New-Object System.Drawing.Font("Microsoft YaHei", 9.5, [System.Drawing.FontStyle]::Regular)
$cb.Location = New-Object System.Drawing.Point(8, 10)
$cb.AutoSize = $true
$cb.BackColor = [System.Drawing.Color]::Transparent
$cb.Cursor = [System.Windows.Forms.Cursors]::Hand

# 复选框状态改变时更新面板样式
$cb.Add_CheckedChanged({
if ($this.Checked) {
$this.Parent.BackColor = [System.Drawing.Color]::FromArgb(230, 240, 255)
} else {
$this.Parent.BackColor = [System.Drawing.Color]::FromArgb(250, 252, 255)
}
})

$itemPanel.Controls.Add($cb)
$scrollPanel.Controls.Add($itemPanel)
$checkboxes += $cb
}

# 调整滚动面板高度
$totalRows = [Math]::Ceiling($apps.Count / $columnCount)
$scrollPanel.Height = [Math]::Min(350, ($totalRows * $itemHeight + 2 * $margin))

# 按钮面板
$buttonPanel = New-Object System.Windows.Forms.Panel
$buttonPanel.Size = New-Object System.Drawing.Size(810, 80)
$buttonPanel.Location = New-Object System.Drawing.Point(20, ($scrollPanel.Location.Y + $scrollPanel.Height + 20))
$buttonPanel.BackColor = [System.Drawing.Color]::Transparent
$form.Controls.Add($buttonPanel)

# 启动按钮
$launchButton = New-Object System.Windows.Forms.Button
$launchButton.Text = "🚀 启动选中程序"
$launchButton.Font = New-Object System.Drawing.Font("Microsoft YaHei", 11, [System.Drawing.FontStyle]::Bold)
$launchButton.Size = New-Object System.Drawing.Size(200, 45)
$launchButton.Location = New-Object System.Drawing.Point(150, 15)
$launchButton.BackColor = [System.Drawing.Color]::FromArgb(74, 107, 255)
$launchButton.ForeColor = [System.Drawing.Color]::White
$launchButton.FlatStyle = "Flat"
$launchButton.FlatAppearance.BorderSize = 0
$launchButton.Cursor = [System.Windows.Forms.Cursors]::Hand

# 按钮悬停效果
$launchButton.Add_MouseEnter({
$this.BackColor = [System.Drawing.Color]::FromArgb(30, 144, 255)
})

$launchButton.Add_MouseLeave({
$this.BackColor = [System.Drawing.Color]::FromArgb(74, 107, 255)
})

$launchButton.Add_Click({
$selected = $checkboxes | Where-Object { $_.Checked }
if ($selected.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show("请至少选择一个应用程序!", "提示",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information)
return
}

$notFound = @()
$successCount = 0

foreach ($item in $selected) {
$path = $item.Tag
if (Test-Path $path) {
try {
Start-Process -FilePath $path -ErrorAction Stop
$successCount++
} catch {
$notFound += "$($item.Text.Trim()) (启动失败)"
}
} else {
$notFound += "$($item.Text.Trim()) (文件不存在)"
}
Start-Sleep -Milliseconds 100 # 稍微延迟,避免同时启动太多程序
}

if ($notFound.Count -gt 0) {
[System.Windows.Forms.MessageBox]::Show("以下程序启动失败:`n`n" + ($notFound -join "`n"),
"⚠️ 启动失败",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning)
} else {
[System.Windows.Forms.MessageBox]::Show("✅ 已成功启动 $successCount 个应用!",
"完成",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information)
$form.WindowState = [System.Windows.Forms.FormWindowState]::Minimized
}
})
$buttonPanel.Controls.Add($launchButton)

# 调整窗体高度
$form.Height = $buttonPanel.Location.Y + $buttonPanel.Height + 50

# 启动窗口
[void]$form.ShowDialog()
文章作者: PanXiaoKang
文章链接: http://example.com/2024/05/12/%E8%B6%A3%E5%91%B3%E6%80%A7%E8%84%9A%E6%9C%AC/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 向阳榆木
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论