Page 1 of 1 1
Topic Options
#64096 - 2002-03-26 10:38 PM Delete Icon from Desktop
Anonymous
Unregistered


I am having trouble deleting an icon from the desktop. We use roaming user profiles and I can't seem to find a variable that works for the username. Here is the code I am currently using:

If EXIST ("C:\Documents and Settings\%username%\Desktop\Syteline.lnk") = 0
DEL "C:\Documents and Settings\%username%\Desktop\Syteline.lnk"
Endif

I have tried %username% and @userid. Neither have worked. What variable can should I be using? Any help would be greatly appreciated. Thanks.

Gordon

Top
#64097 - 2002-03-26 10:47 PM Re: Delete Icon from Desktop
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gordon,

Try %userprofile%\desktop\syteline.lnk

-Shawn

Top
#64098 - 2002-03-26 11:14 PM Re: Delete Icon from Desktop
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
You are close....

Break on cls
IF EXIST ("%userprofile%\Desktop\Syteline.lnk") = 1
DEL "%userprofile%\Desktop\Syteline.lnk"
Endif

HTH,

- Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#64099 - 2002-03-27 12:18 AM Re: Delete Icon from Desktop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
I like this one... removes even if you have +R attribute on the file. [Eek!]

code:
Break on cls
IF EXIST ("%userprofile%\Desktop\Syteline.lnk")<>0
shell '%comspec% /c DELTREE "%userprofile%\Desktop\Syteline.lnk /y"'
Endif

What a cool language KiX is. See how you can do the same thing in so many ways.

Top
#64100 - 2002-03-27 12:28 AM Re: Delete Icon from Desktop
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Gotta love that DelTree... doesn't care about attributes.

I had a user once copy an entire CD to his HomeShare. After reading him the riot act, I gave him until the next day to delete it. You see, if you copy read-only files, they're not so easy to delete. He toiled at it for hours before asking if there was a better way or for an extension on the deadline. That's when he learned about DelTree.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#64101 - 2002-03-27 06:57 AM Re: Delete Icon from Desktop
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

When the location is different from "%userprofile%" setting we advise to use the actual
location of your desktop by reading desktop setting.
code:
  $ikey="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
IF (Exist($ikey) = 0)
$ivalue=ReadValue($ikey, "Desktop")
$ivalue=ExpandEnvironmentVars($ivalue)
IF (Substr($ivalue,len($ivalue),1) <> "\")
$ivalue=$ivalue+"\"
ENDIF
;
IF Exist($ivalue+"Syteline.lnk") = 1
DEL $ivalue+"Syteline.lnk"
IF (@error <> 0)
? "KIX-DEL: error @error (@serror)"
ENDIF
ENDIF
ENDIF

greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#64102 - 2002-03-27 10:16 AM Re: Delete Icon from Desktop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
I completely agree with MCA, but I was being too lazy to write the full code for this. If it were for my own use, I would read the registry to locate the folder in question.

Then also check and log who has the link and if I have tried to remove it or not, then take appropriate actions if the removal appears to fail.

Top
#64103 - 2002-03-27 02:32 PM Re: Delete Icon from Desktop
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
If you have Kix 4.x, you could do the following...
code:
Break on cls

$WSHShell = WScript.CreateObject("WScript.Shell")

; Read desktop path using WshSpecialFolders object
$DesktopPath = $WSHShell.SpecialFolders("Desktop")

IF EXIST ($DesktopPath + "\Syteline.lnk") <> 0
DEL $DesktopPath + "\Syteline.lnk"
ENDIF

- Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#64104 - 2002-03-27 03:38 PM Re: Delete Icon from Desktop
Anonymous
Unregistered


Thanks all for the replies. I used:

Break on cls
IF EXIST ("%userprofile%\Desktop\Syteline.lnk") = 1
DEL "%userprofile%\Desktop\Syteline.lnk"
Endif

It worked! One other question, I am also trying to delete a folder using the code:

If EXIST ("%USERPROFILE%\Desktop\Syteline") = 1
DEL "%USERPROFILE%\Desktop\Syteline"
Endif

This does not work. I figured it would work the same as for an icon. Any ideas? Thanks.

Gordon

Top
#64105 - 2002-03-27 03:47 PM Re: Delete Icon from Desktop
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Gordon,

If it is a folder...

If EXIST ("%USERPROFILE%\Desktop\Syteline") = 1
RD "%USERPROFILE%\Desktop\Syteline"
Endif

Another way to do this...

IF GetFileAttr( "%USERPROFILE%\Desktop\Syteline" ) = 16
RD "%USERPROFILE%\Desktop\Syteline"
ENDIF

HTH,

- Kent

[ 27 March 2002, 15:51: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#64106 - 2002-03-27 05:12 PM Re: Delete Icon from Desktop
Anonymous
Unregistered


This doesn't seem to be working. The folder I want to delete is located in C:\Documents and Settings\gjaquay\DESKTOP. The folder name is Syteline. The folder contains 5 icons (if that matters). I used what you suggested:

If EXIST ("%USERPROFILE%\Desktop\Syteline\") = 1
RD "%USERPROFILE%\Desktop\Syteline"
Endif

What am I doing wrong? Thanks.

Gordon

Top
#64107 - 2002-03-27 05:29 PM Re: Delete Icon from Desktop
Dean R Offline
Starting to like KiXtart

Registered: 2002-03-15
Posts: 115
Loc: Ireland, but Im an Aussie
If EXIST ("%USERPROFILE%\Desktop\Syteline\") = 1
RD "%USERPROFILE%\Desktop\Syteline"
Endif

Is not going to work due to the following
-------------------------------------------------
RD

Action: Removes the directory specified.

Syntax: RD "directory"

Remarks: The directory must be empty for this command to succeed.

Check the value of @ERROR to see if RD was successful.
-------------------------------------------------

Try this
If EXIST ("%USERPROFILE%\Desktop\Syteline\") = 1
DEL "%USERPROFILE%\Desktop\Syteline\*.*"
RD "%USERPROFILE%\Desktop\Syteline"
Endif
_________________________
-------------------------------- When you can take this stone from my hand Gwasshoppa you are read... *yoink* Gwasshoppa? Gwasshoppa? Where did you go? ---------------------------------

Top
#64108 - 2002-03-27 05:32 PM Re: Delete Icon from Desktop
Dean R Offline
Starting to like KiXtart

Registered: 2002-03-15
Posts: 115
Loc: Ireland, but Im an Aussie
Alternatively try rewriting what Shawn posted above
code:

IF EXIST ("%userprofile%\Desktop\Syteline.lnk")<>0
shell '%comspec% /c DELTREE "%userprofile%\Desktop\Syteline /y"'
Endif
_________________________
-------------------------------- When you can take this stone from my hand Gwasshoppa you are read... *yoink* Gwasshoppa? Gwasshoppa? Where did you go? ---------------------------------

Top
#64109 - 2002-03-27 06:25 PM Re: Delete Icon from Desktop
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Gordon and Dean,

You can use RD, but the processors not the one from KiXtart.

This code will work even if the user has deleted or moved the DELTREE program.

code:
Break on cls
IF EXIST ("%userprofile%\Desktop\Syteline\nul")<>0
shell '%comspec% /c RD /S /Q "%userprofile%\Desktop\Syteline"'
Endif

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.

/Q Quiet mode, do not ask if ok to remove a directory tree with /S


Again, this is being lazy. Better code would read where the path really is from the Registry, then verify and log success, failure.

[ 27 March 2002, 18:26: Message edited by: NTDOC ]

Top
Page 1 of 1 1


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

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

Generated in 0.061 seconds in which 0.023 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