-3

我们最近开始在我的工作地点推出 2016 年的盒子,我现在正在经历的部分过程是使用户配置文件尽可能“用户友好”。

正如您可能知道的那样,Server 2016 具有 Windows 10 开始菜单配置,不幸的是,对于我的特殊情况,管理工具、PowerShell 等对于我们无法运行它们但我想避免的客户来说非常容易获得如果他们确实尝试运行这些快捷方式中的任何一个,他们可能会遇到服务器出现问题的可能负面印象/误解......

我正在尝试将一个批处理文件放在一起,我可以以每个用户身份登录或从我自己的域管理员配置文件中运行,并从包含这些快捷方式的 appdata roaming 和 appdata local 中删除文件夹....我不想要仅删除客户的域管理员快捷方式。

到目前为止,这是我所拥有的并不能完美运行的内容..我从遇到的各种脚本中拼凑出来,因为我对这些脚本的编码相对缺乏经验....在我的测试环境中,虽然我影响了多个配置文件没有意识到它会发生,它实际上只适用于 WinX 快捷方式文件夹......它正在删除它,但其他文件夹仍然存在......

任何有助于破译我在这里的无能的帮助将不胜感激。

@ECHO OFF

:START
cls
cd %USERPROFILE%
cd..
set profiles=%cd%

for /f "tokens=* delims= " %%u in ('dir /b/ad') do (

cls
title Removing %%u Unnecessary shortcuts from roaming. . .
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System" echo Deleting....
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System" cd "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System"
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System" rmdir /s /q "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System"

cls
title Removing %%u More unnecessary shortcuts from roaming. . .
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows Administrative Tools" echo Deleting....
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows Administrative Tools" cd "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows Administrative Tools"
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows Administrative Tools" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows Administrative Tools" rmdir /s /q "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows Administrative Tools"

cls
title Removing %%u Even more unnecessary shortcuts from roaming. . .
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" echo Deleting....
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" cd "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell"
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" rmdir /s /q "%profiles%\%%u\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell"

cls
title Removing %%u Unnecessary shortcuts from WinX Menu. . .
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\WinX\Group3" echo Deleting....
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\WinX\Group3" cd "%profiles%\%%u\AppData\Local\Microsoft\Windows\WinX\Group3"
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\WinX\Group3" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\WinX\Group3" rmdir /s /q "%profiles%\%%u\AppData\Local\Microsoft\Windows\WinX\Group3"

)

cls
goto END

:END
exit
4

1 回答 1

0

我能够找到一个暂时使用icacls的解决方案。从快捷方式文件夹中删除权限会使它们消失。我确信可以在 PowerShell 中生成不需要输入的内容,但我既没有经验也没有时间写出更精彩的内容。这适用于我的情况,我希望它也可以帮助其他人。

@echo off

echo Press the Enter Key To Begin
pause > NUL


::first I had to use takeown for just this folder as it was denying any modification of permissions I was attempting with icacls

takeown /f "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /R /A

::Next I go in and set the permissions for the shortcuts in ProgramData which are not profile specific and have "Everyone" and "Users" included by default. 
::I have used asterisks for security reasons but they are not part of the live code.

icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /inheritance:r /remove:g Everyone 
icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /remove:g Users 
icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /grant "Administrators:(CI)(OI)(F)" 
icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /grant "*****\Domain Admins:(CI)(OI)(F)" 
icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /grant "*****\Domain Admins:(CI)(OI)(F)" 
icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /grant "*****\*** Support:(CI)(OI)(M)" 

cls

goto Second

:Second

set /p USER=What is the name of the Userprofile being modified? 
del "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Server Manager.lnk"
icacls "C:\Users\%USER%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /inheritance:r /remove:g %USER%
icacls "C:\Users\%USER%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools" /inheritance:r /remove:g %USER%
icacls "C:\Users\%USER%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" /inheritance:r /remove:g %USER%
icacls "C:\Users\%USER%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools" /inheritance:r /remove:g %USER%
icacls "C:\Users\%USER%\AppData\Local\Microsoft\Windows\WinX\Group3" /inheritance:r /remove:g %USER%
del "C:\Users\%USER%\AppData\Local\Microsoft\Windows\WinX\Group2\4 - Control Panel.lnk"


echo.
echo.
echo Operation completed.

goto Second

End

经过令人沮丧的 10 分钟混乱后,我发现了一个有趣的花絮……尽管控制面板快捷方式的属性中的所有内容都清楚地说明了快捷方式的名称是“Control Panel.lnk”,但快捷方式的实际名称是“4 - Control Panel.lnk”不确定该命名方案的通用性,但这就是我正在处理的服务器上的内容,并且似乎是我运行批处理文件的后续服务器的名称。

于 2016-12-09T00:28:28.237 回答