#198157 - 2010-03-24 09:37 AM
Find and replace file based on date stamp?
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
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..
|
Top
|
|
|
|
#198159 - 2010-03-24 09:56 AM
Re: Find and replace file based on date stamp?
[Re: Richard H.]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
Ah.. Have been doing some reading and I was gonna use the following..
$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?
Edited by psykix (2010-03-24 09:58 AM)
|
Top
|
|
|
|
#198161 - 2010-03-24 10:10 AM
Re: Find and replace file based on date stamp?
[Re: Mart]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
I use the following code (dunno where the USER.INI came from above!!)
$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!
|
Top
|
|
|
|
#198162 - 2010-03-24 10:26 AM
Re: Find and replace file based on date stamp?
[Re: psykix]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
I changed to this :-
$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?
Edited by psykix (2010-03-24 10:27 AM)
|
Top
|
|
|
|
#198164 - 2010-03-24 10:42 AM
Re: Find and replace file based on date stamp?
[Re: Mart]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
...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 :-
$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?
|
Top
|
|
|
|
#198166 - 2010-03-24 11:03 AM
Re: Find and replace file based on date stamp?
[Re: Mart]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
Thanks,
I get :-
87 The parameter is incorrect.
|
Top
|
|
|
|
#198168 - 2010-03-24 11:30 AM
Re: Find and replace file based on date stamp?
[Re: Mart]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
Thanks, that seems to work ok now - it was the extra trailing \
Cheers for that!
|
Top
|
|
|
|
#198170 - 2010-03-24 12:04 PM
Re: Find and replace file based on date stamp?
[Re: psykix]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
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)
Edited by psykix (2010-03-24 12:08 PM)
|
Top
|
|
|
|
#198171 - 2010-03-24 12:25 PM
Re: Find and replace file based on date stamp?
[Re: psykix]
|
psykix
Fresh Scripter
Registered: 2008-07-09
Posts: 12
|
It's ok, have proved the above by using a test script on one user.
Works fine!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 271 anonymous users online.
|
|
|