-
Notifications
You must be signed in to change notification settings - Fork 0
/
wall-it.ps1
64 lines (52 loc) · 2.3 KB
/
wall-it.ps1
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
<#
Everytime you change the wallpaper), type in ".get" in the 'Write message?' prompt to create a new copy of the wallpaper.
This copy will be used everytime you then want to write a message.
Once the new wallpaper has been saved ("wallpaper.bmp" in the local folder), it will be set automatically.
Font: Arial, 20
Position of the text is based on the mouse coordinates.
#>
# had to put these 2 lines else the script wouldn't work in console
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
# something like...https://learn.microsoft.com/en-us/sysinternals/downloads/bginfo
$thispath = $PSScriptRoot + "\"
$backupExist = Test-Path -Path ($thispath + "TranscodedWallpaper") -PathType Leaf
# edit message
$text = Read-Host "Write message?"
if($text -eq ".get" -or $backupExist -eq 0){
# save the wallpaper to script folder
Copy-Item ("C:\Users\"+[System.Windows.Forms.SystemInformation]::UserName+"\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper") -Destination ($thispath + "TranscodedWallpaper")
}
if($text -eq ".get"){
# gives the possibility to write without having to relaunch
$text = Read-Host "Write message?"
}
# get the current wallpaper as BMP -- ok but if we set as wallpaper, it won't be "blank" anymore
$bmp = [System.Drawing.Bitmap]::FromFile($thispath + "TranscodedWallpaper")
# edit BMP
$g = [System.Drawing.Graphics]::FromImage($bmp)
$font = [System.Drawing.Font]::new("Arial",20)
$brush = [System.Drawing.Brushes]::White
$bw = $bmp.Width
$bh = $bmp.Height
$pX = [Math]::abs([System.Windows.Forms.Cursor]::Position.X)
$pY = [Math]::abs([System.Windows.Forms.Cursor]::Position.Y)
$g.DrawString($text, $font, $brush, $pX, $pY);
# save BMP
$wpath = $thispath + "wallpaper.bmp"
$bmp.Save($wpath)
# set as wallpaper
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Params
{
[DllImport("User32.dll",CharSet=CharSet.Unicode)]
public static extern int SystemParametersInfo (Int32 uAction,Int32 uParam,String lpvParam,Int32 fuWinIni);
}
"@
$SPI_SETDESKWALLPAPER = 0x0014
$UpdateIniFile = 0x01
$SendChangeEvent = 0x02
$fWinIni = $UpdateIniFile -bor $SendChangeEvent
$ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER,0,$wpath,$fWinIni)