Jump to content

Remove shortcut from all users start menu folder


Recommended Posts

$folder = StringLeft(@StartMenuDir,StringInStr(@StartMenuDir,"\",0,-1))
       $search = FileFindFirstFile($folder&"*")
       While 1
       $StartMenuSearch = FileFindNextFile($search)
       If @error Then ExitLoop
       If FileExists($folder&$StartMenuSearch&"\programs\pcsetup\Printer*.lnk") Then
       FileDelete($folder&$StartMenuSearch&"\programs\pcsetup\Printer*.lnk")
       EndIf
       WEnd
       FileClose($search)

Hi,

I need to search for a shortcut that would be under each user profile.Can someone tell me if this looks right ? It was based upon a solution to someone's else problem with my tweaks.

Thanks

Link to comment
Share on other sites

Just curious, do you actually need to see if it exists before trying to delete it? You could just run a DEL console command if you know the name of the file you're looking for and just delete every copy it finds.

Run(@ComSpec & " /c DEL c:\users\printer*.lnk /s", "", @SW_HIDE)

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

but when I look at the shortcut properties it points back to something like this:

C:\Users\bob\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Maintenance

If I search the users folder I see 7 of instances of the shortcut. So this is being copied as part of the roaming user profile

But deleting it off the start menu won't delete each instance, only for the 1 user logged in

 

 

Link to comment
Share on other sites

The  you need to read all users here: C:\Users\
Then delete each user shortcut, the problem you will probably face with this is that Windows 7 for example by default don't allow you to access other users directory inside C:\Users so you will need to find a solution to deal with that.

Kind Regards
Alien.

Link to comment
Share on other sites

25 minutes ago, alien4u said:

Hi again @Briandr

If you remove a shortcut from C:\ProgramData\Microsoft\Windows\Start Menu\Programs this shortcut will be removed for all users in the system.

Kind Regards
Alien.

Only if no user have the link in his own startmenu. It can also happen that linkname is different from user to user.

Link to comment
Share on other sites

I'm afraid that maybe this is not going to save you from that because even if you have admins right you can't access other users folders by default in Windows 7 you probably need to change permissions, do your tasks and then restore previous permissions again.

Anyways let us know if you make it work with #RequireAdmin because maybe this do everything that I'm thinking in a different way.

Kind Regards
Alien.

Link to comment
Share on other sites

Before I thought I just wanted the shortcut removed. Now I am thinking just delete the whole folder. If that is removed the shortcuts should be as well, right? Think back to my original post if that guy could remove a shortcut off the desktop why can't it be tweaked to what I want? And with our image admin can see other users profiles. I am mobile but I will include a link to what I found when I am out of a car

Link to comment
Share on other sites

Hi, 

In reply back to BrewManNH your command worked in two separates test. The lnk file I am looking to delete for whatever reason its name starts like 9. Click Me.lnk. Not sure who came up with the crazy name, but perhaps I need to do something like this:

Run(@ComSpec & " /c DEL c:\users\9.*.lnk /s", "", @SW_HIDE)

I updated the posting and the command works fine outside autoit, but I am just wondering the fact the shortcut begins with 9. Blah Blah if the period is throwing things off??

 

Edited by Briandr
Link to comment
Share on other sites

As long as you have local admin rights you should have no issues deleting things from other users directories, I do it all the time.

Most of my production code runs as system, but I run as local admin when testing.

 

Looks like so far you have not got a  way to loop through all the user accounts and will need to do that before you can get to the shortcut for each user.

 

I personally would use _FileListToArray() on the Users folder and then loop through each users desktop/startup folder as needed.

 

Link to comment
Share on other sites

Hi again @Briandr

Here you have a working solution:

 

#include <File.au3>
#include <Array.au3>
#include <String.au3>

$commonpath = "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"

; List All System Users this should Point to your user profile folder I mean maybe C:/Users/?
$users = _FileListToArray(@ScriptDir&"\Users\")

; If you are going to delete de entire folder something like this should do the job
For $i = 1 To UBound($users) -1
    DirRemove(@ScriptDir&"\Users\"&$users[$i]&$commonpath&"\Accessories",3)
Next

Hope this finally help you to finish your task.

Kind Regards
Alien.

Link to comment
Share on other sites

  • 1 month later...

Hi Alien,

This fell off the radar and I just looked at it again. For some reason the folder I wanted removed which is off Start->Programs, named PCSetup the code just does not seem to work. I removed my code and just included the code you graciously shared. While logged on as Administrator I ran the code and afterwards, Accessories was still present. Did you by chance test the code or a test device?

 

 

 

Link to comment
Share on other sites

Hello,

If you want to delete a folder's content, then robocopy.exe might be your friend:

  • create any new, empty folder
  • run robocopy using the command line switch " /b" (Backup Mode), which makes it possible to access *ANY* folder
  • (ab)use robocopy to delete the files by "mirror copying" the new, empty folder to that one, you need to get rid of its content (#requireadmin, otherwise "/b" won't be allowed) (see "robocopy /???|more" help, switch "/mir")

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Run(@ComSpec & " /c DEL c:\users\9.*.lnk /s", "", @SW_HIDE)

This works. It is amazing what a space can do a command. Plus it worked with Run as opposed to RunWait. The only thing is can I somehow manipulate this so it deletes a folder.

Run(@ComSpec & " /c RD /s /q c:\users\pcsetup* /s", "", @SW_HIDE)

Because of what I am looking to accomplish here I don't think DirRemove will work. Problem with the line directly above is pcsetup is not directly off c:\users. The first example that now works is targeting a specific file that could be spread out over sever directories under c:\users. Any ideas?

Thanks.

Link to comment
Share on other sites

1 hour ago, Briandr said:
Run(@ComSpec & " /c DEL c:\users\9.*.lnk /s", "", @SW_HIDE)

This works. It is amazing what a space can do a command. Plus it worked with Run as opposed to RunWait. The only thing is can I somehow manipulate this so it deletes a folder.

Run(@ComSpec & " /c RD /s /q c:\users\pcsetup* /s", "", @SW_HIDE)

Because of what I am looking to accomplish here I don't think DirRemove will work. Problem with the line directly above is pcsetup is not directly off c:\users. The first example that now works is targeting a specific file that could be spread out over sever directories under c:\users. Any ideas?

Thanks.

I don't know why solution is post number 15 does not work for you, is tested and it works...
Why do you think you cant use DirRemove?

Modify with your own path and use my solution on post #15 it will work. Add #requireadmin to your script.

Regards
Alien.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...