Link to home
Start Free TrialLog in
Avatar of T-cko
T-cko

asked on

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
Avatar of acl-puzz
acl-puzz
Flag of India image

Avatar of merowinger
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

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=




Avatar of T-cko
T-cko

ASKER

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
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

>>>> 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.
Avatar of T-cko

ASKER

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
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

Avatar of T-cko

ASKER

line 11 char 89 has syntax error as error message says, can you please check
Avatar of T-cko

ASKER

ups i forgot to rename yourscreensaver string.. but if i did it brings error on line 11 char 78
change to:
objFSO.CopyFile strFile, "\\" &strCurrentPC &strFolder &"\YourScreensaver.scr",true  
Avatar of T-cko

ASKER

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
Avatar of T-cko

ASKER

now i have permission denied on line 11 error..i didnt  modify anything just run vbs again
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

Avatar of T-cko

ASKER

Error copying file:Path not found

 i have source scr file in root of D\:
so you use the following?
strSource = "D:\"
or
strSource = "D:"
It's important that there is no backslash
Avatar of T-cko

ASKER

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
then the computer you try to copy is not available?!
Avatar of T-cko

ASKER

no no i have 3 test computers here beside me, they are running
also previous attempt (your script version 1) gave no error.
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

Avatar of T-cko

ASKER

and copy.log is empty
pic.JPG
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
Avatar of T-cko

ASKER

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)
you you tried my last suggestion?
Avatar of T-cko

ASKER

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
try a textfile for testing purpose
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

ASKER CERTIFIED SOLUTION
Avatar of Justin_W_Chandler
Justin_W_Chandler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial