本帖最后由 jiavip 于 2026-7-15 10:58 编辑
如题:桌面显示文字.纯代码.BAT
----------------------扔代码----------------------
- @Echo off
- Set t=变量:T是显示的内容,C是字体颜色,D是字体大小,X是宽,Y是高
- Set c=red
- Set d=36
- Set x=50
- Set y=50
- Powershell -NoProfile -C "Add-Type -AssemblyName System.Windows.Forms;Add-Type -AssemblyName System.Drawing;Add-Type -MemberDefinition '[DllImport(\"user32.dll\")] public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImport(\"user32.dll\")] public static extern bool ReleaseCapture();' -Name User32 -Namespace WinAPI -PassThru | Out-Null;$form=New-Object System.Windows.Forms.Form;$form.FormBorderStyle='None';$form.ControlBox=$false;$form.ShowInTaskbar=$false;$form.TopMost=$true;$form.BackColor='White';$form.TransparencyKey='White';$form.StartPosition='Manual';$label=New-Object System.Windows.Forms.Label;$label.Text='%t%';$label.Font=New-Object System.Drawing.Font('SimSun',%d%,[System.Drawing.FontStyle]::Regular);$label.AutoSize=$true;$label.BackColor='White';$label.ForeColor='%c%';$label.Cursor=[System.Windows.Forms.Cursors]::SizeAll;$form.Controls.Add($label);$form.ClientSize=$label.Size;$form.Location=New-Object System.Drawing.Point(%x%,%y%);$label.Add_MouseDown({param($s,$e)if($e.Button -eq 'Left'){[WinAPI.User32]::ReleaseCapture();[WinAPI.User32]::SendMessage($form.Handle,0xA1,2,0);}});$form.Add_Shown({$form.Activate()});$form.Add_FormClosing({$form.Dispose()});[System.Windows.Forms.Application]::Run($form)"
复制代码
---------代码存 ANSI 编码, XXXX.BAT ------------------
桌面显示文字.纯 Powershell 代码,非第三方工具,
配合 VBS 隐藏启动运行脚本,可以实现开机桌面提示.也可以封装成 EXE 进程,
-----------------------------终极改进版---------------------------------
- @Echo off
- Rem;;;桌面显示文字
- Rem;;;下句是隐藏脚本运行窗口,去掉下句或加上参数 h 则 显示脚本运行窗口.
- If /i not "%1"=="h" Mshta vbscript:CreateObject("WScript.Shell").Run("""%~f0"" h",0)(Window.close)&&exit
- Set t=变量:T是显示的内容,C是字体颜色,D是字体大小,L是显示时间(毫秒),X是宽,Y是高
- Set c=red
- Set d=36
- Rem;;;下句L变量留空则长时间显示,写上数字,则显示时间(毫秒)
- Set l=5000
- Set x=50
- Set y=50
- If not "%l%"=="" Set z=$timer=New-Object System.Windows.Forms.Timer;$timer.Interval=%l%;$timer.Add_Tick({$form.Close()});$timer.Start()
- Powershell -NoProfile -C "Add-Type -AssemblyName System.Windows.Forms;Add-Type -AssemblyName System.Drawing;Add-Type -MemberDefinition '[DllImport(\"user32.dll\")] public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImport(\"user32.dll\")] public static extern bool ReleaseCapture();' -Name User32 -Namespace WinAPI -PassThru | Out-Null;$form=New-Object System.Windows.Forms.Form;$form.FormBorderStyle='None';$form.ControlBox=$false;$form.ShowInTaskbar=$false;$form.TopMost=$true;$form.BackColor='White';$form.TransparencyKey='White';$form.StartPosition='Manual';$label=New-Object System.Windows.Forms.Label;$label.Text='%t%';$label.Font=New-Object System.Drawing.Font('SimSun',%d%,[System.Drawing.FontStyle]::Regular);$label.AutoSize=$true;$label.BackColor='White';$label.ForeColor='%c%';$label.Cursor=[System.Windows.Forms.Cursors]::SizeAll;$form.Controls.Add($label);$form.ClientSize=$label.Size;$form.Location=New-Object System.Drawing.Point(%x%,%y%);$label.Add_MouseDown({param($s,$e)if($e.Button -eq 'Left'){[WinAPI.User32]::ReleaseCapture();[WinAPI.User32]::SendMessage($form.Handle,0xA1,2,0);}});$form.Add_Shown({$form.Activate();%z%});$form.Add_FormClosing({$form.Dispose()});[System.Windows.Forms.Application]::Run($form)"
- Exit
复制代码
-------------------
改了几个参数和判断思路,,,
脚本默认隐藏启动运行,加上参数 h 则正常显示脚本运行窗口,,,
L变量留空则长时间显示,写上数字,则显示时间(毫秒)
|