问题:
因为某些特殊原因,需要在AD域用户登陆Window 桌面时,任务栏会自动隐藏,但是AD域策略并不提供对应的策略,于是需要写个bat文件,让域控服务器在用户登陆时会自动执行这条bat。
代码:
这段代码是在网上找的。经测验,可以使用。但是在(域策略下发成功后)用户第一次登陆时并不能成功自动隐藏任务栏,而是在注销用户或者重启计算机后,第二次登陆才能开始自动隐藏任务栏。
/*&cls
@echo off
set "netpath=%systemroot%\Microsoft.NET\Framework"
for /f "delims=" %%a in ('dir /ad /b "%netpath%\v?.*"') do (
if exist "%netpath%\%%a\csc.exe" (
set "cscpath=%netpath%\%%a\csc.exe"
goto :0
)
)
echo;未安装.Net Framework 2.0及其上版本组件或相关程序丢失&pause&exit
:0
if not exist "%tmp%\$TaskBarHider.exe" (
"%cscpath%" /nologo /out:"%tmp%\$TaskBarHider.exe" "%~f0"
)
"%tmp%\$TaskBarHider.exe" h
pause&exit
*/
using System;
using System.Runtime.InteropServices;
class TaskBarHider
{
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public struct APPBARDATA
{
public int cbSize;
public int hwnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public int lParam;
}
public const int ABS_ALWAYSONTOP = 0x002;
public const int ABS_AUTOHIDE = 0x001;
public const int ABM_SETSTATE = 0x00A;
[DllImport("shell32.dll")]
public static extern int SHAppBarMessage(int dwmsg, ref APPBARDATA app);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
public static void SetAppBarAutoDisplay(bool IsAuto)
{
APPBARDATA abd = new APPBARDATA();
abd.hwnd = FindWindow("Shell_TrayWnd", "");
if (IsAuto)
{
abd.lParam = ABS_AUTOHIDE;
SHAppBarMessage(ABM_SETSTATE, ref abd);
}
else
{
abd.lParam = ABS_ALWAYSONTOP;
SHAppBarMessage(ABM_SETSTATE, ref abd);
}
}
static void Main(string[] args)
{
bool sta=false;
if(args.Length==0)
{
Console.WriteLine("$TaskBarHider.exe [s/h] 显示/隐藏任务栏");
}
else
{
if(args[0] == "h" || args[0] == "H"){sta=true;}
SetAppBarAutoDisplay(sta);
}
}
}