|
|
|||||||
I'm looking for some script which will do the following... Check if screensaver.scr exists in a directory, check the date stamp. If it does not match the latest version, then overwrite it with the new version. If the file doesn't exist at all, then copy the latest version to the directory.. Is there a function to check the date and timestamp on a file? Cheers.. |
||||||||
|
|
|||||||
Originally Posted By: psykix Is there a function to check the date and timestamp on a file? Yup - look up GetFileTime() in the manual. Here is a very simple way of doing what you want: Code: $sSourceDir="\\server\share" $sTargetDir="%WINDIR%" $sFile="ScreenSaver.scr" If GetFileTime($sSourceDir+"\"+$sFile) > GetFileTime($sTargetDir+"\"+$sFile) Copy $sSourceDir+"\"+$sFile $sTargetDir+"\"+$sFile EndIf |
||||||||
|
|
|||||||
Ah.. Have been doing some reading and I was gonna use the following.. Code: $result = CompareFileTimes ("\\fileserver1\ICT Software\Software\ScreenSaver\nwdass.scr", "C:\WINDOWS\System32\nwdass.scr") IF $Result=1 OR $Result = -3 COPY "\\fileserver1\ICT Software\Software\Screensaver\nwdass.scr" "C:\WINDOWS\USER.INI" /h /s ENDIF How can I test code without deploying it in my live script? |
||||||||
|
|
|||||||
You can test it by running it manually. You need to use the correct path to kix32 and your script. Quote: kix32 yourscript.kix |
||||||||
|
|
|||||||
I use the following code (dunno where the USER.INI came from above!!) Code: $Result = CompareFileTimes ("\\fileserver1\ICT Software\Software\ScreenSaver\nwdass.scr", "C:\WINDOWS\System32\nwdass.scr") IF $Result = 1 OR $Result = -3 COPY "\\fileserver1\ICT Software\Software\Screensaver\nwdass.scr" "C:\WINDOWS\System32\nwdass.scr" /h /s ENDIF However, it is not overwriting the file - do I need a switch to overwrite it? Not sure how to troubleshoot it, as the script operates silently... Thanks for the help! |
||||||||
|
|
|||||||
I changed to this :- Code: $Result = CompareFileTimes ("\\fileserver1\ICT Software\Software\ScreenSaver\nwdass.scr", "C:\WINDOWS\System32\nwdass.scr") IF $Result = 1 OR $Result = -3 DEL "C:\WINDOWS\System32\nwdass.scr" COPY "\\fileserver1\ICT Software\Software\Screensaver\nwdass.scr" "C:\WINDOWS\System32\nwdass.scr" /h /s ENDIF It deletes the file, but doesn't copy the newer file... I'm wondering if it is a permissions issue? |
||||||||
|
|
|||||||
Originally Posted By: psykix ...I'm wondering if it is a permissions issue? ... Regular users cannot copy anything to the destination folder you are using. |
||||||||
|
|
|||||||
Originally Posted By: Mart Originally Posted By: psykix ...I'm wondering if it is a permissions issue? ... Regular users cannot copy anything to the destination folder you are using. Well I have local admin rights, and it's not working.. I have changed the code to the following so that they get the file from a local server :- Code: $Result = CompareFileTimes (@LDRIVE+"\Screensaver\nwdass.scr", "C:\WINDOWS\System32\nwdass.scr") IF $Result = 1 OR $Result = -3 COPY @LDRIVE+"\Screensaver\nwdass.scr" "C:\WINDOWS\System32\nwdass.scr" /h /s ENDIF I basically want to change the screensaver on a regular basis, without having to change the GPO - hence using a script to just overwrite the screensaver file. Any suggestions? |
||||||||
|
|
|||||||
Maybe because it is a scr file (could be seen as some kind of script) it is blocked by your virus scanner. Placing the code below directly after the copy command will provide you some extra info. Code: ?@error ?@serror sleep 5 |
||||||||
|
|
|||||||
Thanks, I get :- 87 The parameter is incorrect. |
||||||||
|
|
|||||||
Ok, I took a closer look at your code and two things come to mind. 1 You can drop the /s parameter. You are copying a file. The /s parameter is for copying folders including empty folders. 2 The @ldrive macro already has a trailing \ so you should remove the first \ after @ldrive. Please give the code below a go and let us know the results. Code: $Result = CompareFileTimes (@LDRIVE + " Screensaver\nwdass.scr", "C:\WINDOWS\System32\nwdass.scr") If $Result = 1 Or $Result = -3 Copy @LDRIVE + "Screensaver\nwdass.scr" "C:\WINDOWS\System32\nwdass.scr" /h EndIf |
||||||||
|
|
|||||||
Thanks, that seems to work ok now - it was the extra trailing \ Cheers for that! |
||||||||
|
|
|||||||
Hmm.. I have a problem as the script won't write that file into the C:\WINDOWS\System32 folder. It works on my machine because I am an admin. Is there any way to tell the script to use elevated privileges to copy the file? Cheers.. Edit : from reading this forum it seems that if I run the script as a logon script it will run with elevated privileges.. can someone confirm this? (I have only tested it running locally so far) |
||||||||
|
|
|||||||
It's ok, have proved the above by using a test script on one user. Works fine! |