0

This is my first question I'm asking on here. I've searched high and low for an answer/help but cant find anything that works.

Been tasked with creating a batch script that runs when our users log into their PC's that sets there Screensaver to the company one. I know some people are going to say to use Active Directory to enforce this but we don't use it.

The script itself is this:

    IF EXIST "C:\Windows\System32\MDXScreenSaver.scr" goto :found 
    IF NOT EXIST "C:\Windows\System32\MDXScreenSaver.scr" goto :notfound

    :notfound 
    copy "\\VSMG\VOL1\APPS\Screensaver\New\MDXScreenSaver.scr" "%UserProfile%\Desktop" 
    copy "%UserProfile%\Desktop\MDXScreenSaver.scr" "C:\Windows\System32\"

    REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 1 /f
    REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 30 /f
    REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure /t REG_SZ /d 0 /f
    REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t REG_SZ /d C:\Windows\System32\MDXScreenSaver.scr /f

    :found
    exit

When testing, I broke it down into separate stages so i know what worked and doesn't. It will move the file from the server to the desktop, and apply the REG keys.

When doing the copy/move to System32 (using the pause command) it states in CMD that it has copied/moved it but on inspection the file isn't there.

Please can someone help me to get this file into System32.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
OliV555
  • 1
  • 2
  • Are you running this file under administrative privileges? system32 will probably be a restricted area for your normal users. If not try `runas /user:Administrator`. – Compo Oct 24 '16 at 13:13
  • You mention the file isn't there, which means it's not in the System32 directory, but what about the Desktop directory? Is it there? – Dominique Oct 24 '16 at 13:26
  • In regards to Compo, thats what im trying to get it to do, but will that runas command just work for the one line i need to work on (System32) or will i need to declare from the start? and in regards to Dominique, the file is succesfully copying from server to desktop, but when moving from desktop to system 32 it isnt appearing there, but when you pasue the code it states it is there? if that makes sense – OliV555 Oct 24 '16 at 13:34
  • I have done testing with `runas /user:administrator` and this is not liking the syntax and not running that line of code – OliV555 Oct 24 '16 at 14:25

2 Answers2

0

You don't need to run each line as administrator, run the batch file.

RunAs /User:administrator C:\Folder\mybatchfile.bat
Compo
  • 36,585
  • 5
  • 27
  • 39
0

I managed to solve this in the end,

IF EXIST "C:\ScreenSaver\MdxAero_SS.scr" goto :found
IF NOT EXIST "C:\ScreenSaver\MdxAero_SS.scr" goto :notfound

:notfound 
mkdir "C:\Screensaver"
copy "\\VSMG\VOL1\APPS\Screensaver\MdxAero_SS.scr""%UserProfile\Desktop" 
move "%UserProfile%\Desktop\MdxAero_SS.scr" "C:\Screensaver"

REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 1 /f
REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 600 /f
REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure /t REG_SZ /d 1 /f
REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t REG_SZ /d C:\ScreenSaver\MdxAero_SS.scr /f

goto :end

:found

REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d 1 /f
REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d 600 /f
REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure /t REG_SZ /d 1 /f
REG add "HKEY_CURRENT_USER\Control Panel\Desktop" /v SCRNSAVE.EXE /t REG_SZ /d C:\ScreenSaver\MdxAero_SS.scr /f

goto :end

:end
exit   
OliV555
  • 1
  • 2