Forum Discussion
Show/Hide Desktop Icons with a single click
Pyro2k6 here's what it says:
source : Die Benennung "source" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines
ausführbaren Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern
enthalten), und wiederholen Sie den Vorgang.
In C:\Curseforge\scripts\ToggleShowDesktopIcons.ps1:1 Zeichen:1
+ source = @'
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (source:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Add-Type : Das Argument kann nicht an den Parameter "TypeDefinition" gebunden werden, da es NULL ist.
In C:\Curseforge\scripts\ToggleShowDesktopIcons.ps1:46 Zeichen:26
+ Add-Type -TypeDefinition $source
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddTypeComm
and
Der Typ [DesktopUtility.Desktop] wurde nicht gefunden.
In C:\Curseforge\scripts\ToggleShowDesktopIcons.ps1:48 Zeichen:1
+ [DesktopUtility.Desktop]::ToggleDesktopIcons()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (DesktopUtility.Desktop:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
thanks to CHATGPT i made a fixed version of the code:
$source = @"
using System;
using System.Runtime.InteropServices;
namespace DesktopUtility
{
class Win32Functions
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
}
public class Desktop
{
public static IntPtr GetHandle()
{
IntPtr hDesktopWin = Win32Functions.GetDesktopWindow();
IntPtr hProgman = Win32Functions.FindWindow("Progman", "Program Manager");
IntPtr hWorkerW = IntPtr.Zero;
IntPtr hShellViewWin = Win32Functions.FindWindowEx(hProgman, IntPtr.Zero, "SHELLDLL_DefView", "");
if (hShellViewWin == IntPtr.Zero)
{
do
{
hWorkerW = Win32Functions.FindWindowEx(hDesktopWin, hWorkerW, "WorkerW", "");
hShellViewWin = Win32Functions.FindWindowEx(hWorkerW, IntPtr.Zero, "SHELLDLL_DefView", "");
} while (hShellViewWin == IntPtr.Zero && hWorkerW != null);
}
return hShellViewWin;
}
public static void ToggleDesktopIcons()
{
Win32Functions.SendMessage(Desktop.GetHandle(), 0x0111, (IntPtr)0x7402, (IntPtr)0);
}
}
}
"@
Add-Type -TypeDefinition $source
[DesktopUtility.Desktop]::ToggleDesktopIcons()