#64096 - 2002-03-26 10:38 PM
Delete Icon from Desktop
|
Anonymous
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
|
|
|
|
#64098 - 2002-03-26 11:14 PM
Re: Delete Icon from Desktop
|
Kdyer
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
|
|
Top
|
|
|
|
#64099 - 2002-03-27 12:18 AM
Re: Delete Icon from Desktop
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: CA
|
I like this one... removes even if you have +R attribute on the file.
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
|
|
|
|
#64101 - 2002-03-27 06:57 AM
Re: Delete Icon from Desktop
|
MCA
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.
|
|
Top
|
|
|
|
#64103 - 2002-03-27 02:32 PM
Re: Delete Icon from Desktop
|
Kdyer
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
|
|
Top
|
|
|
|
#64104 - 2002-03-27 03:38 PM
Re: Delete Icon from Desktop
|
Anonymous
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
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 ]
|
|
Top
|
|
|
|
#64106 - 2002-03-27 05:12 PM
Re: Delete Icon from Desktop
|
Anonymous
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
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
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
   
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 583 anonymous users online.
|
|
|