mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 23:28:34 +01:00
put_file writes bytes to a path in the guest (a folder that has a space in its name is made), wallpaper and set_wallpaper read and set the wallpaper of a display through IDesktopWallpaper, with the COM calls in C# compiled by Add-Type (wallpaper.ps1).
47 lines
1.5 KiB
PowerShell
47 lines
1.5 KiB
PowerShell
# usage: powershell -File wallpaper.ps1 get DISPLAY
|
|
# powershell -File wallpaper.ps1 set DISPLAY PATH
|
|
# Prints or sets the wallpaper of the monitor DISPLAY (0 is the first), through
|
|
# the IDesktopWallpaper interface of the shell.
|
|
param([string]$Command = "get", [int]$Display = 0, [string]$Path = "")
|
|
|
|
Add-Type @"
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
[ComImport, Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B"),
|
|
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
|
interface IDesktopWallpaper {
|
|
void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID,
|
|
[MarshalAs(UnmanagedType.LPWStr)] string wallpaper);
|
|
[return: MarshalAs(UnmanagedType.LPWStr)]
|
|
string GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID);
|
|
[return: MarshalAs(UnmanagedType.LPWStr)]
|
|
string GetMonitorDevicePathAt(uint monitorIndex);
|
|
uint GetMonitorDevicePathCount();
|
|
}
|
|
|
|
[ComImport, Guid("C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD")]
|
|
class DesktopWallpaperClass {}
|
|
|
|
public static class Wallpaper {
|
|
static IDesktopWallpaper Open() {
|
|
return (IDesktopWallpaper)new DesktopWallpaperClass();
|
|
}
|
|
public static string Get(int display) {
|
|
var w = Open();
|
|
return w.GetWallpaper(w.GetMonitorDevicePathAt((uint)display));
|
|
}
|
|
public static void Set(int display, string path) {
|
|
var w = Open();
|
|
w.SetWallpaper(w.GetMonitorDevicePathAt((uint)display), path);
|
|
}
|
|
}
|
|
"@
|
|
|
|
if ($Command -eq "get") {
|
|
[Wallpaper]::Get($Display)
|
|
} elseif ($Command -eq "set") {
|
|
[Wallpaper]::Set($Display, $Path)
|
|
"set"
|
|
}
|