Change registry DisableTaskManager not working in Windows 7 - windows-7

I want to disable a standard user from accessing the task manager. With gpedit.msc this works without problems, but I need to do this from the Windows registry. I already tried assigning 1 to the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DiableTaskMgr, but it is not working.
I use a bat file:
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableTaskMgr /t REG_DWORD /d 1 /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableChangePassword /t REG_DWORD /d 1 /f
taskkill /IM explorer.exe /F

Related

Why are changes to the Winlogon registry being ignored by MDT TaskSequence?

I'm setting up a Task Sequence(TS) in MDT for deploying Win10 IoT Enterprise. As one of the final steps in the TS I'm trying to add AutoLogon of the user account to the registry. But when the TS finishes and I check, the changes have either not been made or they have been reset by some clean-up script.
I create a new "Run Command Line" step in the TS, right after the Install Applications step that MDT generates automatically. This step runs a script I've added to the Deploy/Scripts folder. I get no errors here, but no result either.
I've tried to export the correct registry-settings to a .reg file and use the "Run Command Line" step to import these. Again, no errors and no result.
I've moved both of these steps down in the list, so that they are the last thing the TS does. Again, no errors and no result.
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d <username>/f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d <Domain> /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d <password> /f
cmd /c reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 500000 /f
I want the AutoLogon to be set automatically. If not, there has to be a procedure for how to set it up and that not only feels unnecessary, but is also a source of errors if its forgotten.
After more googling I finally found:
https://ccmcache.wordpress.com/2018/02/07/workaround-for-windows-10-1709-autoadminlogon-at-the-end-of-configmgr-osd-task-sequence/
Where there is a solution. An ugly one, but the only way I've found that works. So thank you to the author of this.

Windows Cmd Delete Item from HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

I added an item to startup using the command
REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
And after I tryed to delete it with the command :
REG DELETE "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OMG" /f
But with no succes. I searched for this type of question but with no result. I will realy apreciate any help!
rem ↓↓ missing " double quote
REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
rem ↑↑ missing " double quote
Missing " double quote causes misinterpreting keys as follows:
==> REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
The operation completed successfully.
==> reg query "HKCU\Software\Microsoft\Windows\CurrentVersion" /S | findstr /C:"CurrentVersion\Run " 2>NUL
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:\WGET
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:\WGET\wget.exe
==>
Add missing " double quote as follows:
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
Yup, You missed the 'Double Quotes' After REG ADD. But, in this method you are choosing, You need to run the script as an 'Admin'. While, Giving a Batch file Admin Access Can never be a good idea.
So, You can try the alternative of, Copying the Shortcut (the file to Execute at startup) to the path -> "%Userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" - No Admin Needed. :)

Windows Registry doesn't save changes after reboot

I'm using a batch script to activate Auto logon on a computer that's a member of doamin.
#echo off
REM Set variables
set /p username= What is the username?
set /p domain= What is the domain name?
set /p password= What is the password?
REM Enable Auto Logon
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1
REM Set Username for logon
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d %username%
REM Set Domain
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d %domain%
REM Set Password
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d %password%
REM Set number of times to auto logon (0 for infinite)
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /t REG_DWORD /d 0
Everything works fine after I execute the script, but once I reboot the computer I noticed that the DefaultPassword and AutoAdminLogon values are not saving. I changed the permission but still no luck.
Can you please tell me what am I doing wrong.
If I am reading the documentation correctly, AutoLogonCount decrements each time the system is automatically logged on, and when it reaches 0 then the auto logon is disabled. It sounds like you are configuring it to immediately end logging in automatically. Try not using the AutoLogonCount value at all (or remove it if it exists). I've never used it before and auto logon works forever without it.

Windows batch command to make changes effective immediately

I have a batch script that lets users change their background from black to white or vice versa. The problem I'm having is that the script only makes immediate change sometimes, and other times the user has to log off and log back on for the background to change. Here is what I have so far:
#echo off
call :quiet
exit /b
:quiet
:: For comparison, using the black wallpaper registry value
set "black=C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\MDCBackground_black.bmp"
:: Set reg query result to current
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKCU\Control Panel\Desktop" /v Wallpaper') DO SET current=%%B
:: For debugging purpose.
ECHO current=%current%
pause
if "%current%"=="%black%" (
call :MakeDayWallpaper>nul 2>&1
:: Make changes without requiring logoff
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
) else (
call :MakeNightWallpaper>nul 2>&1
:: Make changes without requiring logoff
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
)
EXIT /b
:MakeDayWallpaper
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\MDCBackground_white.bmp" /f
REG DELETE "hkcu\Software\Microsoft\Internet Explorer\Desktop\General" /v Wallpaper /f
REG ADD "hkcu\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
EXIT /b
:MakeNightWallpaper
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f
REG ADD "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Themes\MDCBackground_black.bmp" /f
REG DELETE "hkcu\Software\Microsoft\Internet Explorer\Desktop\General" /v Wallpaper /f
REG ADD "hkcu\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
EXIT /b
The line RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters is the command that allows the immediate change. When I look at shell I can see that the registry value is changing every time the script is executed, but despite this fact, sometimes the background does not change until the user logs off and logs on.
It might be that the registry changes aren't taking effect until the log off/log on is done (I'm not sure why it would sometimes work immediately though). Try restarting explorer afterwards and see if that helps.
taskkill /im explorer.exe /f
explorer.exe

Windows batch script to switch desktop background

Is there a way to check what a user currently has as their background and then changing it depending on what it is? For example: I want a white background during day time and a black background for night time. Running the script would check the current background, if it is white it will switch to the black background, and if it is black it will switch to the white.
I'm a little unfamiliar with Windows batch script and I'm seeking some tips and advice on how I can accomplish the task above. Here is what I've been able to find so far:
#echo off
call :quiet>nul 2>&1
goto :EOF
:quiet
:: Configure Wallpaper
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "%SystemRoot%\energybliss.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 2
:: Configure the screen saver.
:: REG ADD "HKCU\Control Panel\Desktop" /V SCRNSAVE.EXE /T REG_SZ /F /D "%SystemRoot%\System32\scrnsave.scr"
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
:: Set the time out to 900 seconds (15 minutes).
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaveTimeOut /T REG_SZ /F /D 900
:: Set the On resume, password protect box
:: REG ADD "HKCU\Control Panel\Desktop" /V ScreenSaverIsSecure /T REG_SZ /F /D 1
:: Remove the user's ability to see the Screen Saver, background, and appearance tabs of Display Properties.
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispScrSavPage /T REG_DWORD /F /D 1
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispBackgroundPage /T REG_DWORD /F /D 1
::REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /V NoDispAppearancePage /T REG_DWORD /F /D 1
:: Make the changes effective immediately
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
You can use code like that:
#echo off
:: '>nul 2>&1' was moved to other place
call :quiet
exit /b
:quiet
:: Put there wallpaper name (with extension, bigger that 8 symbols)
set "Wallpaper.Night.BadWrited=Wallpaper1.bmp"
:: It is a dirty hack and example of bad code
for /F "tokens=*" %%a in ('reg query "HKCU\Control Panel\Desktop" /v Wallpaper') do set "Wallpaper.Current.BadWrited=%%a"
:: Take last 8 symbols of wallpaper name. Change number of symbols to your own minimal
set "Wallpaper.Current.BadWrited=%Wallpaper.Current.BadWrited:~-8%"
set "Wallpaper.Night.BadWrited=%Wallpaper.Night.BadWrited:~-8%"
if "%Wallpaper.Current.BadWrited%"=="%Wallpaper.Night.BadWrited%" (
call :MakeDayWallpaper>nul 2>&1
) else (
call :MakeNightWallpaper>nul 2>&1
)
exit /b
:MakeDayWallpaper
echo Day wallpaper setted
:: Put your code here
exit /b
:MakeNightWallpaper
echo Night wallpaper setted
:: Put your code here
exit /b
But i recommend to use the system scheduler. You can acces it from control panel, 'Scheduled Tasks' or something. You can make 2 files named 'makeday.bat' and 'makenight.bat'. Scheduler will run them every day at needed time

Resources