Page 1 of 2 12>
Topic Options
#168952 - 2006-10-05 07:31 PM Check file exists then copy
rparsons Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 6
I need to copy a screen saver to the system32 dir of XP & 2000 systems and am trying o figure out how to check for it's existence first so it isn't copied over and over again.
Something like IF NOT EXIST (%sysemdir%\screen.scr) COPY "\\server\file" "%sytemdir%\file) END IF.

Can someone give me the right syntax for this? Thanks

Top
#168953 - 2006-10-05 08:07 PM Re: Check file exists then copy
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Check for extra information in the kix2010.doc
Code:

If NOT Exist("FileOrFolder")
Copy "Source" "Destination" /c /h
EndIf


Top
#168954 - 2006-10-05 09:33 PM Re: Check file exists then copy
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Would not recommend that code for Folder checking.

Also, unless the user has Admin rights they should not be able to copy that file into the system32 folder.

For a folder I'd use something like this. Though he did ask about a file.


If GetFileAttr('foldername') & 16
 

Top
#168955 - 2006-10-05 10:36 PM Re: Check file exists then copy
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, why do you offer folder then?
Top
#168956 - 2006-10-05 11:02 PM Re: Check file exists then copy
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Becasue Witto so suggested and I'm just pointing out what I think would be a better method.

Quote:

("FileOrFolder")



Top
#168957 - 2006-10-05 11:17 PM Re: Check file exists then copy
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
witto showed that you can use exist against both file and folder.
but didn't see such suggestion you are referring to.

Top
#168958 - 2006-10-05 11:46 PM Re: Check file exists then copy
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
True, I (almost) copied the syntax from the kix2010.doc
I tried to show that quotes are missing, that brackets are misplaced and that EndIf is one word.
Just what was asked
Quote:


Can someone give me the right syntax for this?




Top
#168959 - 2006-10-06 01:24 AM Re: Check file exists then copy
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
No problem Jooel or Witto. Was simply wanting to point out that it is possible to have a file with the name of a folder or the name of a folder with the name of a file and if that does exist the script will fail.

Witto's solution and explanation of why is valid. Just hoping to educate on a possible issue either now or in the future for new scripters.

Top
#168960 - 2006-10-06 02:16 AM Re: Check file exists then copy
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
DOC, your logic is flawed. regardless of whether it is a file or folder that exists, if either exists the file should not be copied. In fact if there is a folder by the ssame name as the file, the copy would fail!
Top
#168961 - 2006-10-06 02:22 AM Re: Check file exists then copy
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Not sure how the logic could be flawed since I didn't provide any SILVER PLATTER code.

I only provided what I think would be a better TYPE of solution.

I could / would write some Silver Platter code if the original poster requests it though.

Top
#168962 - 2006-10-06 02:33 AM Re: Check file exists then copy
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well my vote goes to Witto's code and I rise to his defense.
Top
#168963 - 2006-10-06 02:41 AM Re: Check file exists then copy
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
That's cool. No problem, many ways to do the same task.

Most of us have the freedom to choose as well, which is good. Not trying to solicit some type of challenge.

Top
#168964 - 2006-10-06 03:36 PM Re: Check file exists then copy
rparsons Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 6
Thanks. My syntax was based on m ow logic not true kixtart code but it's good to see I was close. Since I am using kixtart for our logon script (active directory), wouldn't the file copy to system32? I would think the script runs under admin context.
Top
#168965 - 2006-10-06 03:44 PM Re: Check file exists then copy
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
The file will be copied to the path specified. Yes and no, the script runs under the user-context, if the user is a admin (why would an admin run a loginscript?...) then yes, runs as admin, if it's just a domain user, runs as a domain user etc.
Top
#168966 - 2006-10-06 04:09 PM Re: Check file exists then copy
rparsons Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 6
Hmm. Good to know. I have the logic working now and the file is copying. Unfortunately I can see people putting on their on screen saver if its not in system32 or other denied folder (renaming their own). I could use SMS to do this and still may but is there a way to run it as admin?
Top
#168967 - 2006-10-06 04:11 PM Re: Check file exists then copy
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Then you should schedule it as a scheduled task. This can even be done remotely.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#168968 - 2006-10-06 04:17 PM Re: Check file exists then copy
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
You can limit screensaver and background with a gpo if you wish.
What have I missed, why would you wanna schedule a filecopy?


Edited by Björn (2006-10-06 04:20 PM)

Top
#168969 - 2006-10-06 04:24 PM Re: Check file exists then copy
rparsons Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 6
Yea, I can limit the screen saver via GPO which I do but a person who knew enough could copy their own and rename it. The best I can think of is just make it read only and hidden in a common location like Program Files.
Top
#168970 - 2006-10-06 04:25 PM Re: Check file exists then copy
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
or just change the permissions on the specified file not to include your users for change.

Edited by Björn (2006-10-06 04:31 PM)

Top
#168971 - 2006-10-06 04:36 PM Re: Check file exists then copy
rparsons Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 6
I thought about that but wouldn't the permission then get inherited by the receiving computer thereby replacing the permissions?
Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1808 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.083 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org