Distribution of .scr file

Hello friends
I would like to ask you if you can help me with distribution of new .scr file to around 3000 win xp clients in domain.
I thought that logon script can do this via simple line of: copy [source] [ destination]
and job would be done but I'm not sure if logon script has enough rights to copy .scr file to sensitive location like /windows/system32/  and I don't want to run it each time a user logs domain..its enough to run it once.

So I would like to use simple DOS environment (if->do) and loopback, some .bat or .cmd to:
1.) copy example.scr file from shared folder \\server\share to each hostname's c:/windows /system32
2.) source of hostnames is hostnames.txt
3. perform this operation for each hostname from source hostnames.txt
4.) ideally to produce some log file which hostname was or was not successful

Can you please write short script or command that will perform it?
Thank you very much for your help
T-ckoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

merowingerCommented:
Here's a version for a vbscript (.vbs)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile("D:\Copy.log")
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")
strFolder = "\c$\windows\system32"
strFile = "D:\YourScreensaver.scr"

Do While Not objPCs.AtEndOfStream
	strCurrentPC = objPCs.ReadLine
	
	On Error Resume Next
	objFSO.CopyFile strFile, "\\" &strCurrentPC &strFolder
	On Error GoTo 0
	If Err.Number <> 0 Then
		objLog.WriteLine strCurrentPC &" - Error copying file"
	Else
		objLog.WriteLine strCurrentPC &" - Success copying file"
	End If
Loop

Open in new window

0
itsmeandnobodyelseCommented:
Here are 2 batch scripts which would do the job (not tested)


@echo off
REM install_to_hosts.cmd
for /f "delims=" %%i in (c:\temp\hostnames.txt) do call install_file xxx.scr %%i


@echo off
REM install_file filename hostname
if "%1"=="" goto ERR_NO_ARG
if "%2"=="" goto ERR_NO_ARG
goto COPY_FILE
:ERR_NO_ARG
echo "syntax %0 <file_to_copy> <host_name>"
echo.
goto END
:COPY_FILE
set copystmt="xcopy /Y /R "%1" \\"%2"\c$\windows\system32\"
echo %copystmt% >> err.log
xcopy /Y /R "%1" \\"%2"\c$\windows\system32\   >> err.log
if not errorlevel 1 goto END
:ERR_COPY
echo %copystmt%
echo.
echo "copy failed. See err.log for details "
echo.
:END
set copystmt=




0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

T-ckoAuthor Commented:
guys one more importatnt information;

I need to replace existing scr file with new that has the same name so I would need to automatically avoid message that says that such file alradey exist - and force it to copy new one
0
merowingerCommented:
vbscript without "already exists" messages
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objLog = objFSO.CreateTextFile("D:\Copy.log") 
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt") 
strFolder = "\c$\windows\system32" 
strFile = "D:\YourScreensaver.scr" 
 
Do While Not objPCs.AtEndOfStream 
        strCurrentPC = objPCs.ReadLine 
         
        On Error Resume Next 
        objFSO.CopyFile strFile, "\\" &strCurrentPC &strFolder,true 
        On Error GoTo 0 
        If Err.Number <> 0 Then 
                objLog.WriteLine strCurrentPC &" - Error copying file" 
        Else 
                objLog.WriteLine strCurrentPC &" - Success copying file" 
        End If 
Loop

Open in new window

0
itsmeandnobodyelseCommented:
>>>> avoid message that says that such file alradey exist - and force it to copy new one

xcopy /R /Y

copies without asking back if existing.
0
T-ckoAuthor Commented:
hello merowinger

this script does not work, it makes log that copying was successfull but it was not
i tried it via checking date created stamp in win explorer and it shows old date
i tried to delete current .scr file if new one (copied) will come but it didn't
0
merowingerCommented:
Ok once more.
I've removed the option  to hide errors and did some changes
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objLog = objFSO.CreateTextFile("D:\Copy.log") 
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt") 
strFolder = "\c$\windows\system32" 
strFile = "D:\YourScreensaver.scr" 
 
Do While Not objPCs.AtEndOfStream 
        strCurrentPC = objPCs.ReadLine 
         
        'On Error Resume Next 
        objFSO.CopyFile strFile, "\\" &strCurrentPC &strFolder &"\YourScreensaver.scr" &,true 
        On Error GoTo 0 
        If Err.Number <> 0 Then 
                objLog.WriteLine strCurrentPC &" - Error copying file" 
        Else 
                objLog.WriteLine strCurrentPC &" - Success copying file" 
        End If 
Loop

Open in new window

0
T-ckoAuthor Commented:
line 11 char 89 has syntax error as error message says, can you please check
0
T-ckoAuthor Commented:
ups i forgot to rename yourscreensaver string.. but if i did it brings error on line 11 char 78
0
merowingerCommented:
change to:
objFSO.CopyFile strFile, "\\" &strCurrentPC &strFolder &"\YourScreensaver.scr",true  
0
T-ckoAuthor Commented:
this change successfully copied .scr file to computer that has no .scr file in system32 folder
but for computers that already has .scr file it did not overwrite them - looks untouched even after refresh
0
T-ckoAuthor Commented:
now i have permission denied on line 11 error..i didnt  modify anything just run vbs again
0
merowingerCommented:
I've created a more cleaner version. Which should output the correct errors if the copy process fails
Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objLog = objFSO.CreateTextFile("D:\Copy.log")  
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")  
strTarget = "c$\windows\system32"
strName = "YourScreensaver.scr"
strSource = "D:\Folder"
  
Do While Not objPCs.AtEndOfStream  
        strCurrentPC = objPCs.ReadLine  
          
        On Error Resume Next  
        objFSO.CopyFile strSource &"\" &strName, "\\" &strCurrentPC &"\" &strTarget &"\" &strName,true  
        If Err.Number <> 0 Then  
                objLog.WriteLine strCurrentPC &" - Error copying file:" &Err.Description
        Else  
                objLog.WriteLine strCurrentPC &" - Success copying file"  
        End If  
Loop

Open in new window

0
T-ckoAuthor Commented:
Error copying file:Path not found

 i have source scr file in root of D\:
0
merowingerCommented:
so you use the following?
strSource = "D:\"
or
strSource = "D:"
It's important that there is no backslash
0
T-ckoAuthor Commented:
I use only script that is written by you..I only modify the name of scr file nothing else

I have source scr file (the one i want to distribute) on my root of D drive on my computer
0
merowingerCommented:
then the computer you try to copy is not available?!
0
T-ckoAuthor Commented:
no no i have 3 test computers here beside me, they are running
also previous attempt (your script version 1) gave no error.
0
merowingerCommented:
ok what result do you get? Please post all messages
Set objFSO = CreateObject("Scripting.FileSystemObject")   
Set objLog = objFSO.CreateTextFile("D:\Copy.log")   
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")   
strTarget = "c$\windows\system32" 
strName = "YourScreensaver.scr" 
strSource = "D:" 
   
Do While Not objPCs.AtEndOfStream   
        strCurrentPC = objPCs.ReadLine   
           
        'On Error Resume Next
	Wscript.echo strSource &"\" &strName, "\\" &strCurrentPC &"\" &strTarget &"\" &strName 
        objFSO.CopyFile strSource &"\" &strName, "\\" &strCurrentPC &"\" &strTarget &"\" &strName,true   
        If Err.Number <> 0 Then   
                objLog.WriteLine strCurrentPC &" - Error copying file:" &Err.Description 
        Else   
                objLog.WriteLine strCurrentPC &" - Success copying file"   
        End If   
Loop

Open in new window

0
T-ckoAuthor Commented:
and copy.log is empty
pic.JPG
0
merowingerCommented:
ok try replacing the line 13 with this line:
objFSO.CopyFile strSource &"\" &strName, "\\" &strCurrentPC &"\" &strTarget

If you still get the same messages, then you have no permissons to write to the server's system32 directory
0
T-ckoAuthor Commented:
i tried it once again and it showed no error, also copy.log says about success
but "date created" flag in win expolere on one of tested machines shows old date (date of distrib, of old scr)
0
merowingerCommented:
you you tried my last suggestion?
0
T-ckoAuthor Commented:
yes i did, but still access denied - but im sure that i have access becouse i can delete scr file on test machines manually via unc path (comming from my admin account)

but even if it helped im not sure if it could overwrite scr file also for computers that are running with screensaver turned on
0
merowingerCommented:
try a textfile for testing purpose
0
itsmeandnobodyelseCommented:
If the screensaver currently is active (or loaded in memory) you can't overwrite it.

But mostly you can rename the old screensaver.scr and then the copy of the new one would work.
(see in batch in code box).

Or - alternatively - add an entry PendingFileRenameOperations to

     HKLM\System\CurrentControlSet\Control\SessionManager

key in registry which would replace the files next boot-time.

See http://support.microsoft.com/kb/181345/en-us for details.



@echo off 
REM install_to_hosts.cmd
for /f "delims=" %%i in (c:\temp\hostnames.txt) do call install_file xxx.scr %%i v10


@echo off
REM install_file filename hostname oldversion
if "%1"=="" goto ERR_NO_ARG
if "%2"=="" goto ERR_NO_ARG
goto COPY_FILE
:ERR_NO_ARG
echo "syntax %0 <file_to_copy> <host_name> <old_version_number>"
echo.
goto END
:COPY_FILE
set target_file=\\"%2"\c$\windows\system32\%~n1%~x1
set renamestmt="rename %target_file% %~n1%~x1.%3"
if exist %target_file% rename %target_file% %~n1%~x1.%3 >> err.log
if errorlevel 1 goto ERR_RENAME
set copystmt="xcopy /Y /R "%1" \\"%2"\c$\windows\system32\
echo %copystmt% >> err.log
xcopy /Y /R "%1" \\"%2"\c$\windows\system32\   >> err.log
if not errorlevel 1 goto END
:ERR_COPY 
echo %copystmt%
echo.
echo "copy failed. See err.log for details "
echo.
goto END
:ERR_RENAME 
echo %renamestmt%
echo.
echo "rename failed. See err.log for details "
echo.
goto END
:END
set renamestmt=
set copystmt=

Open in new window

0
Justin_W_ChandlerCommented:
This is incredibly easy... and it seems we're getting too complicated here. Assuming you have proper permissions to the computer all you have to do is open a command prompt, change directory to the one with hostnames.txt and example.scr, and then type the following command:

for /f "tokens=*" %A in ('type hostnames.txt') do copy /y example.scr \\%A\c$\windows\system32 > output.log

Access denied errors should only occur if it's active, so it could be assumed you're simply overwriting a screensaver that's already in use. To overcome this issue simply type this command before the copy command above:

for /f "tokens=*" %A in ('type hostnames.txt') do taskkill /s %A /im example.scr /f

This should kill the screensaver's executable (SCR is actually an executable file), thus allowing you to overwrite it. Please try this solution. It shouldn't take more than 1 minute to do so. OUTPUT.LOG is the log file you can review to make sure it copied correctly.

Justin Chandler
for /f "tokens=*" %A in ('type hostnames.txt') do taskkill /s %A /im example.scr /f
for /f "tokens=*" %A in ('type hostnames.txt') do copy /y example.scr \\%A\c$\windows\system32 > output.log

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.