Page 1 of 1 1
Topic Options
#176056 - 2007-05-07 05:55 PM Delete something from All Users profile
DrUltima Offline
Fresh Scripter

Registered: 2002-08-16
Posts: 21
Loc: Nashville, TN, USA
I would like to be able to delete a file in the all users\desktop. To find it:

 Code:
CASE EXIST("%USERPROFILE%\desktop\EMR.RDP")=1 OR EXIST("%ALLUSERSPROFILE%\desktop\EMR.RDP")=1


I want to delete it if it is in either location. I know permission is not an issue under %userprofile%, but it is under %allusersprofile%. Figured there is a way to set the a variable to be the actual file location, should it exist, and then delete that from another line, but I also don't know how to do that. I know I can break that into two different cases, if that is easier. Any guidance would be appreciated.

Top
#176059 - 2007-05-07 06:51 PM Re: Delete something from All Users profile [Re: DrUltima]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Something like this?

 Code:
SELECT
     CASE EXIST("%USERPROFILE%\desktop\EMR.RDP")
     	DEL "%USERPROFILE%\desktop\EMR.RDP"
     CASE EXIST("%ALLUSERSPROFILE%\desktop\EMR.RDP")
	DEL "%ALLUSERSPROFILE%\desktop\EMR.RDP
     CASE 1
	; No Action Taken
ENDSELECT


That doesn't take permissions into account, but it's a way of checking for the file and deleting it. As written, if the file happens to exist in both places, it'll only get deleted from %USERPROFILE% due to the nature of SELECT/CASE statements. An alternate method would be just having an IF/ENDIF statement for each possible location.

Top
#176070 - 2007-05-07 07:29 PM Re: Delete something from All Users profile [Re: eriqjaffe]
DrUltima Offline
Fresh Scripter

Registered: 2002-08-16
Posts: 21
Loc: Nashville, TN, USA
I apprecaite the post. I was really wanting to know about the permissions to be able to delete the all users\desktop file...

Here is the logic I was going to use...
 Code:
$CompName = @HOSTNAME

SELECT
	CASE InStr($CompName,"TNHQ")
		; Do nothing, but tell them why.
		? "    EMR Icon is not installed on Corporate computers."
	CASE EXIST("%USERPROFILE%\desktop\EMR2.RDP")=1 OR EXIST("%ALLUSERSPROFILE%\desktop\EMR2.RDP")=1
		; Do nothing, but tell them why...
		? "    EMR Icon already exists on your desktop."
	CASE EXIST("%USERPROFILE%\desktop\EMR.RDP")=1 OR EXIST("%ALLUSERSPROFILE%\desktop\EMR.RDP")=1
		? "    I am deleting link to EMR1 from your desktop."
		IF EXIST("%USERPROFILE%\desktop\EMR.RDP")=1
			DEL "%USERPROFILE%\desktop\EMR.RDP"
			CALL "errortrap.kix"
		ENDIF
		IF EXIST("%ALLUSERSPROFILE%\desktop\EMR.RDP")=1
			DEL "%ALLUSERSPROFILE%\desktop\EMR.RDP"
			CALL "errortrap.kix"
		ENDIF
		? "    I am copying the EMR2 Icon to your desktop."
		COPY "\\$dc-dc1\netlogon\EMR2.RDP" "%USERPROFILE%\desktop\EMR2.RDP"
		CALL "errortrap.kix"
	CASE 1
		; Copy the .rdp file from the local DC to the local user's desktop.
		? "    I am copying the EMR2 Icon to your desktop."
		COPY "\\$dc-dc1\netlogon\EMR2.RDP" "%USERPROFILE%\desktop\EMR2.RDP"
		CALL "errortrap.kix"
ENDSELECT

I just know for a fact that the DEL "%ALLUSERSPROFILE%\desktop\EMR.RDP" will fail because of permissions. I just wanted to know how to get around that, perhaps by calling the script with administrative access.


Edited by DrUltima (2007-05-07 10:44 PM)
Edit Reason: Added code

Top
#176089 - 2007-05-08 04:48 AM Re: Delete something from All Users profile [Re: DrUltima]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: DrUltima
I just wanted to know how to get around that, perhaps by calling the script with administrative access.
Sure, just run it as a GPO startup script.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#176120 - 2007-05-08 07:18 PM Re: Delete something from All Users profile [Re: Les]
noobness Offline
Fresh Scripter

Registered: 2006-01-05
Posts: 32
My thoughts exactly.... we use login / start up scripts... the startup scripts are used for anything that would require administrative permissions since local admin is removed from users.

You can use GPO's to specify the startup script.

Computer Configuration > Windows Settings > Scripts

JD

Top
Page 1 of 1 1


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

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

Generated in 0.058 seconds in which 0.029 seconds were spent on a total of 13 queries. Zlib compression enabled.

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