Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Deleting a .lnk via VBScript

Reply
 
Old 06-03-2009   #1 (permalink)
DTSIGuy


 
 

Deleting a .lnk via VBScript

I have a process by which I push icons to distant Vista based PCs on our
domain...it's all automated. One of these items is a shortcut (call it
MYLINK.LNK) which I put in the user's Start Menu. That shortcut calls a .WSF
script that, in turn, runs a JScript followed by a VBScript.

The JScript installs a commercial product and the VBScript is used to clean
up after itself. One of those 'clean up' jobs is to delete the icon that
kicked off this entire thing.

So I have :

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\temp\startload.wsf")
objFSO.DeleteFile("C:\temp\loadapp.jss")
objFSO.DeleteFile("C:\temp\cleanup.vbs")
objFSO.DeleteFile("C:\ProgramData\Microsoft\Windows\Start
Menu\Programs\QC\MYLINK.LNK")

Everything gets deleted except for the .LNK file which is now useless since
it points to the .WSF file which just got deleted. When I get to the .LNK
the script crashes w/ a "Permission Denied".

So I checked the permissions on the file. Administrators and System have
full access. The shortcut is owned by Administrators. The user running the
script is currently in the Administrator's group, I remove him later but for
the moment the user IS in that group.

So why will that file not vanish like a good little icon?

I have found suggestions here and there, none of which apply specifically to
this and I can't remove the folder (which would be easier I suppose, but
that's a non-starter).

CJ


My System SpecsSystem Spec
Old 06-03-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Deleting a .lnk via VBScript


"DTSIGuy" <DTSIGuy@xxxxxx> wrote in message
news:B6DD79AD-A73E-41EC-887A-11C32B6EF1C7@xxxxxx
Quote:

>I have a process by which I push icons to distant Vista based PCs on our
> domain...it's all automated. One of these items is a shortcut (call it
> MYLINK.LNK) which I put in the user's Start Menu. That shortcut calls a
> .WSF
> script that, in turn, runs a JScript followed by a VBScript.
>
> The JScript installs a commercial product and the VBScript is used to
> clean
> up after itself. One of those 'clean up' jobs is to delete the icon that
> kicked off this entire thing.
>
> So I have :
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.DeleteFile("C:\temp\startload.wsf")
> objFSO.DeleteFile("C:\temp\loadapp.jss")
> objFSO.DeleteFile("C:\temp\cleanup.vbs")
> objFSO.DeleteFile("C:\ProgramData\Microsoft\Windows\Start
> Menu\Programs\QC\MYLINK.LNK")
>
> Everything gets deleted except for the .LNK file which is now useless
> since
> it points to the .WSF file which just got deleted. When I get to the .LNK
> the script crashes w/ a "Permission Denied".
>
> So I checked the permissions on the file. Administrators and System have
> full access. The shortcut is owned by Administrators. The user running
> the
> script is currently in the Administrator's group, I remove him later but
> for
> the moment the user IS in that group.
>
> So why will that file not vanish like a good little icon?
>
> I have found suggestions here and there, none of which apply specifically
> to
> this and I can't remove the folder (which would be easier I suppose, but
> that's a non-starter).
>
> CJ
Perhaps the .lnk file is locked at that stage. Did you try deleting it
manually while logged on under the same account as the one used to run the
script?


My System SpecsSystem Spec
Old 06-03-2009   #3 (permalink)
Alex K. Angelopoulos


 
 

Re: Deleting a .lnk via VBScript

Ironic; this is a UAC problem. : )

On Vista, when UAC is enabled, an application run by a user who is not the
actual Administrator can't perform operations that require administrative
privileges unless it requests those privileges as it starts. If you were to
go to the machine in question and try to delete the shortcut as the user,
you would get a dialog box that has "access denied" in the title bar (but a
message that reads "you need to confirm this operation").

There are several ways to work around the problem, but here's a simple one
that should fix the issue, assuming that the user is actually in attendance.
If you can pass the deletion request through the Windows shell, it will
raise an elevation prompt for the user to confirm. This works well enough if
you're having the user do things interactively. Here's a code snippet that
handles the problem:

Dim sa
Set sa = CreateObject("Shell.Application")
Set ns = sa.NameSpace("C:\ProgramData\Microsoft\Windows\Start
Menu\Programs\QC")
set link = ns.Items().Item("MYLINK.LNK")
Set verbs = link.verbs
for each verb in link.verbs
'WScript.Echo verb.Name
if verb.Name = "&Delete" Then
verb.Doit()
exit for
end if
next




"DTSIGuy" <DTSIGuy@xxxxxx> wrote in message
news:B6DD79AD-A73E-41EC-887A-11C32B6EF1C7@xxxxxx
Quote:

> I have a process by which I push icons to distant Vista based PCs on our
> domain...it's all automated. One of these items is a shortcut (call it
> MYLINK.LNK) which I put in the user's Start Menu. That shortcut calls a
> .WSF
> script that, in turn, runs a JScript followed by a VBScript.
>
> The JScript installs a commercial product and the VBScript is used to
> clean
> up after itself. One of those 'clean up' jobs is to delete the icon that
> kicked off this entire thing.
>
> So I have :
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.DeleteFile("C:\temp\startload.wsf")
> objFSO.DeleteFile("C:\temp\loadapp.jss")
> objFSO.DeleteFile("C:\temp\cleanup.vbs")
> objFSO.DeleteFile("C:\ProgramData\Microsoft\Windows\Start
> Menu\Programs\QC\MYLINK.LNK")
>
> Everything gets deleted except for the .LNK file which is now useless
> since
> it points to the .WSF file which just got deleted. When I get to the .LNK
> the script crashes w/ a "Permission Denied".
>
> So I checked the permissions on the file. Administrators and System have
> full access. The shortcut is owned by Administrators. The user running
> the
> script is currently in the Administrator's group, I remove him later but
> for
> the moment the user IS in that group.
>
> So why will that file not vanish like a good little icon?
>
> I have found suggestions here and there, none of which apply specifically
> to
> this and I can't remove the folder (which would be easier I suppose, but
> that's a non-starter).
>
> CJ
>
My System SpecsSystem Spec
Old 06-04-2009   #4 (permalink)
DTSIGuy


 
 

Re: Deleting a .lnk via VBScript

Thanks guys...I'll check it out.

I wonder if UAC actually stands for UnAble to Comply? <argh>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
New to VBscript, Help please! VB Script
CSS and VBscript VB Script
VBscript Help VB Script
How to do No hang up VBScript (nohup for VBScript) VB Script
vbscript and HTA help VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46