Page 1 of 2 12>
Topic Options
#26551 - 2002-08-06 01:11 PM Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
I am building a script that will delete a mapped network drive and the desktop shortcut which relates to this network drive. My pdc and bdc platforms are NT and my workstation platforms are XP, 2000, 98, NT. I have no problem with deleting the mapped network drive was just wondering how to delete the desktop shortcut.

Aany help much appreciated guys.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26552 - 2002-08-06 01:30 PM Re: Desktop Shortcuts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if it's named properly that would not be problem. if it's named whatever, you can't do anything about it without some nice cracks.

anyway, you will locate users desktop with:
$desktop=readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Desktop")

and to delete known named link:
$file="mydrive.lnk"
del $desktop+"\$file"

if you then have no idea of the name, you would need to dir the desktop and check all files if they are lnk and if yes, then check if they point to that location...
can write that for you too if you need it...

just say [Big Grin]
_________________________
!

download KiXnet

Top
#26553 - 2002-08-06 02:46 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
Sorry about this i just tested my script on an NT workstation and nothing happened. What scipt would you write which would delete a network connection t: "fileserver\net_share" and a desktop shortcut named - shortcut to net_share on 'fileserver' (t).
_________________________
Any problem encountered is a challenge to overcome.

Top
#26554 - 2002-08-06 03:16 PM Re: Desktop Shortcuts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I would add some file content scanning in there...
like:
code:
$desktop=readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Desktop")
$file=dir($desktop+"\*.lnk")
while @error=0
shell '%comspec% /c type $desktop'+'\$file |find "\\server\share" >nul'
if not @error
? "this file: $file" ? "points to the place where it shouldn't!"
del $desktop+"\$file"
endif
$file=dir()
loop

not tested as did it just from head...
_________________________
!

download KiXnet

Top
#26555 - 2002-08-06 03:20 PM Re: Desktop Shortcuts
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
It really depends on where the shortcut is stored, either in the 'All Users' profile, the 'Default User' profile, or the current user's profile.

If it's in 'All Users' or 'Default Users' then you'll need administrative permissions to delete that file.
_________________________
There are two types of vessels, submarines and targets.

Top
#26556 - 2002-08-06 03:44 PM Re: Desktop Shortcuts
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
try this

code:
Break on


deldrive("h")

function DelDrive($letter)
dim $d[6], $dp[6], $loop, $desktop

$desktop=readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Desktop")
$desktop=expandenvironmentvars($desktop)
$d=DriveProp("$letter")
if $d[1]="network"
use "$letter:" /d
$dp=split($d[2],"\")
$icon=dir("$desktop\shortcut to*.lnk")
while not @error
if instr($icon,$dp[2]) and instr($icon,$dp[3])
? "got it" $icon
del "$desktop\$icon"
endif
$icon=dir()
loop
endif

endfunction

function DriveProp($Drive)
dim $fso, $Drives, $list, $param, $property
$DriveType="unknown","removable","fixed","network","cd-rom","ram"
$DrivePara="driveletter","drivetype","sharename","isready","filesystem","volumename","serialnumber"
dim $temparray[6]
$fso = createobject("scripting.filesystemobject")
if $fso
$D=$fso.getdrive("$Drive")
for $param = 0 to ubound($DrivePara)
$property=$DrivePara[$param]
$ret=execute('$$temparray[$param]=$$d.$property')
if $param=1 $temparray[$param]=$DriveType[$temparray[$param]] endif
next
$DriveProp=$temparray
$fso=""
endif
exit @error
endfunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#26557 - 2002-08-06 04:05 PM Re: Desktop Shortcuts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
so rad you have spent time with this...

anyway the shortcut gets deleted if it has in it's name the drive...
_________________________
!

download KiXnet

Top
#26558 - 2002-08-06 04:06 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
Radimus you have really confused me. i am only new to this. Right. Every user has their t drive mapped to the same network path. I wish to remove this and the desktop shortcut which is named the same on every user's desktop.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26559 - 2002-08-06 04:14 PM Re: Desktop Shortcuts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
but is it on users desktop?
if it is in all users\desktop
you can't probably delete it in logonscript as most likely normal user has no rights to delete it.
_________________________
!

download KiXnet

Top
#26560 - 2002-08-06 04:15 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
you can because when i configure a new machine i manually mapp the network drive in the user profile. Therefore you dont need administrative rights to delete it.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26561 - 2002-08-06 04:19 PM Re: Desktop Shortcuts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, I can't see why my first sample didn't work for you.
_________________________
!

download KiXnet

Top
#26562 - 2002-08-06 04:24 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
im sorry i haven't tested your script yet, was just confused by radimus. Could you please explain what happens at each stage of the script, so it can understand the process.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26563 - 2002-08-06 04:28 PM Re: Desktop Shortcuts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, it scans all link files in desktop folder and if it links to the pointed place it deletes the link.
anyway, if you know the name of the link-file you just need to specify it and use my first sample.
it reads from registry the place of users desktop folder and deletes the file from there:
code:
;your filename here:
$file="mydrive.lnk"
;the place in reg for folder info:
$desktop=readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Desktop")
del $desktop+"\$file"

_________________________
!

download KiXnet

Top
#26564 - 2002-08-06 04:40 PM Re: Desktop Shortcuts
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
it only deletes the shortcut if the servername and sharename are in the 'shortcut to'

Driveprop() is a UDF described in the UDF forum, and it's purpose is to return and array of values of the types described in the $DrivePara array

The Deldrive() function only will operate if it is passed a drive letter that it a network drive type (not a CD drive letter) it will only function if you give it a network drive to delete.

beyond that, just read the code line by line... it is just little steps
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#26565 - 2002-08-06 05:21 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
Lets start from the beginning in simple terms to a beginner(me).

what would be the command to delete a mapped network drive. I have mapped T to \\fileserver\net_share.

deldrive t: "\\fileserver\net_share"

This does not work can someone please explain in simple terms explaining what each stage of the script does.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26566 - 2002-08-06 05:25 PM Re: Desktop Shortcuts
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
To for example delete a mapped drive T: you just need to do a
code:
use T: /delete /persistent

However, the question was more related to how to delete an shortcut on the user's desktop.
_________________________
There are two types of vessels, submarines and targets.

Top
#26567 - 2002-08-06 05:32 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
Thanks sealeopard.

Now could you show me how to delete the shortcut on the desktop which is called - shortcut to net_share on 'fileserver' (T).

I woiuld really appreciate it if you could explain what is happening at each stage.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26568 - 2002-08-06 05:38 PM Re: Desktop Shortcuts
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$desktop=readvalue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Desktop")
del "$desktop\shortcut to net_share on 'fileserver' (T).lnk"

Click here for more detail

[ 06. August 2002, 17:42: Message edited by: Radimus ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#26569 - 2002-08-06 05:53 PM Re: Desktop Shortcuts
2hotty Offline
Getting the hang of it

Registered: 2002-04-09
Posts: 76
Loc: London
It didnt work. sorry.
_________________________
Any problem encountered is a challenge to overcome.

Top
#26570 - 2002-08-06 06:05 PM Re: Desktop Shortcuts
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
more detail....
_________________________
How to ask questions the smart way <-----------> Before you ask

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 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.139 seconds in which 0.097 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