2016-12-03 17 views
-3

我們最近開始在我的工作場所推出2016盒子,現在我正在經歷的部分流程是儘可能使用戶配置文件爲「用戶友好」。文件夾刪除批處理文件導致的意外結果服務器2016

正如你可能知道的Server 2016有Windows 10的開始菜單配置,不幸的是,我的特殊情況,使管理工具,PowerShell等非常容易得到爲我們的客戶誰將無法運行它們,但我想避免可能的負面印象/誤解的服務器有問題,他們可能會有,如果他們嘗試運行任何這些快捷方式,所以... ...

我想獲得一個批處理文件一起,我可以運行或者作爲每個用戶登錄或從我自己的域管理員配置文件登錄,並從包含這些快捷方式的appdata漫遊和appdata本地刪除文件夾....我不想刪除我的同胞域管理員快捷方式只有客戶端的。

這是我到目前爲止沒有完美工作..我已經從我遇到的各種腳本拼湊在一起,因爲我對這些編碼相對缺乏經驗....在我的測試環境中,它正在影響多個配置文件,雖然我沒有意識到它會去,它真的只爲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 
+3

你的代碼亂七八糟。請[編輯]正確格式化。如果你不確定如何,點擊?在文本區域的右上角之上並閱讀所提供的信息。另外,FWIW,你的方法是完全錯誤的。您應該使用組策略來代替;它會爲非管理員用戶刪除菜單項,而不會手動刪除任何內容。它也會使這些菜單項可供管理員再次自動使用。 –

+0

使用組策略方法闡明問題:已經制定了防止用戶能夠運行這些快捷方式的策略。它不會做的是將它們從可見性中刪除/從開始解除它們。我必須從開始手動取消固定並手動進入,並更改包含快捷方式的文件夾上的NTFS權限,或刪除它們以便能夠提供我正在爭取給客戶端的環境。正如您可以想象的,每臺服務器上有30多個用戶需要花費大量時間。 – therealslimbrady

+0

你們是否都只是對我的問題投反對票,因爲你沒有答案或者是什麼問題? – therealslimbrady

回答

0

我能找到的工作時間使用ICA是一個解決方案CLS。從快捷文件夾中刪除權限使它們消失。我確信一些不需要輸入的東西可能會在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分鐘時間後,發現....儘管該快捷方式控制面板寫明快捷方式的名稱屬性一切都是「控制Panel.lnk」實際快捷方式的名稱是「4 - Control Panel.lnk」不知道命名方案的普遍性如何,但這正是我工作的服務器上的內容,似乎是我運行我的批處理的後續服務器的名稱文件。

相關問題