12 Replies Latest reply on Mar 24, 2009 9:44 AM by SteveH

    Removing Start Menu Items from User Accounts

    Apprentice

      We have a piece of software that we use called ScreenPop.  Its a home grown App, and it was originally distributed via multiple different MSI's with varying version numbers.   This home grown app, has been upgraded and changed and now we still have old versions of the software still roaming out there.  We are trying to remove the old versions off the machines, and it seams like a very simple process.  The following is what needs to be done:

       

      1.  Delete  \Userprofile\Start Menu\Programs\Avtex (and all shortcuts under it)

      2.  Delete C:\Program Files\Avtex  (and all files under it)

       

      We have found a vb Script to do the deletion of the shortcuts, but we are unable to get this to run with landesk No matter which way we run it, if a user without admin rights is logged in, the script runs but does not go threw the machine and delete the icons.   If we run the script manually as an admin, or via landesk while the user is not logged in, the script works. 

       

      I am running Landesk 8.8 SP2A.  I have tried distributing it using the windows script host package, and i tried using a batch file using the following syntax:

       

      cmd /C cscript ScreenPopRemoval.vbs

      Every method i have tried has returned the same results.

       

      After speaking with landesk they have told me that they think there is something wrong with the script.  Unfortunately im not very knowledgable in VB Scripting, One of the guys here found a script online and modified it for our needs so its very possible that there is a syntax error, or something .

       

      Also i was hoping to be able to figure this process out, so i can make some sort of scheduled cleanup task for my machines, something that would go threw and delete the temp folders, and run a defrag.  But this is rather unimportant compared to removing the other old software.

       

      Here is the VBS script we are trying to use(i am aware that the syntax for it to delete the C:\program files\avtex is not there, im currently concerned about the user profile start menu items):

      '==========================================================================
      '
      ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
      '
      ' NAME: ScreenPopRemoval.vbs
      '
      ' AUTHOR: Dave Hastings, IT Department , Mediacom Communications
      ' DATE  : 3/13/2009
      '
      ' COMMENT: This script searchs all local user profiles for the start menu item "Avtex" and deletes the folder. 
      '          Also deletes the C:\program files\avtex folder.
      '
      '==========================================================================

      ' Sample VB Script to remove the folder "Hmmm" (plus any contents) located in the profile folder for every user on the
      ' system.
      ' C:\Documents and Settings\dhastings\Start Menu\Programs\Avtex
      ' C:\Program Files\Avtex
      ' Alter the constant, FolderToDelete, to meet your own requirements
      '
      Const FolderToDelete = "\Start Menu\Programs\Avtex"
      Const AllUsers       = "\All Users"

      Dim strComputer
      Dim oWMI, oWSH, oFSO
      Dim sAllUsersProfile, oAllUsersFolder, sProfilesRoot, oFolder
      Dim colFSOSubFolders, colWMISubFolders, colSubFolders, colSubFolders2
      Dim intSize
      Dim objFolder, objFolder2, objSubFolder
      Dim strFolder, strFolderName

      ' Instantiate the various objects

      strComputer = "."
      Set oWMI    = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
      set oWSH    = CreateObject("WScript.Shell")
      Set oFSO    = CreateObject("Scripting.FileSystemObject")


      ' Get the Allusers profile folder path first and from this determine profiles parent folder
      '

      sAllUsersProfile    = oWSH.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
      Set oAllUsersFolder = oFSO.GetFolder(sAllUsersProfile)
      sProfilesRoot       = oAllUsersFOlder.ParentFolder

      ' Now enumerate all existing user profile folders

      Set oFolder            = oFSO.GetFolder(sProfilesRoot)
      Set colFSOSubfolders   = oFolder.Subfolders

      ' Now go through each existing user profile folder looking for the designated folder to delete

      For Each objSubfolder in colFSOSubfolders

      if oFSO.FolderExists(sProfilesRoot & "\" & objSubfolder.Name & FolderToDelete) then
        intSize = 0
        strFolderName = sProfilesRoot & "\" & objSubfolder.Name & FolderToDelete

        Set colSubfolders = oWMI.ExecQuery _
          ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
              & "Where AssocClass = Win32_Subdirectory " _
                  & "ResultRole = PartComponent")

        ReDim Preserve arrFolders(intSize)
        arrFolders(intSize) = strFolderName
        intSize             = intSize + 1

        For Each objFolder in colSubfolders
            GetSubFolders strFolderName
        Next
        For i = Ubound(arrFolders) to 0 Step -1
            strFolder = arrFolders(i)
            strFolder = Replace(strFolder, "\", "\\")
            Set colFolders = oWMI.ExecQuery _
              ("Select * from Win32_Directory where Name = '" & strFolder & "'")

            For Each objFolder in colFolders
                errResults = objFolder.Delete
            Next
        Next
      end if
      Next


      ' ***************************************************************************************************************
      Sub GetSubFolders(strFolderName)
          Set colSubfolders2 = oWMI.ExecQuery _
              ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
                  & "Where AssocClass = Win32_Subdirectory " _
                      & "ResultRole = PartComponent")

          For Each objFolder2 in colSubfolders2
              strFolderName = objFolder2.Name
              ReDim Preserve arrFolders(intSize)
              arrFolders(intSize) = strFolderName
              intSize = intSize + 1
              GetSubFolders strFolderName
          Next
      End Sub

      ' ****************************************************************************************************************

        • 1. Re: Removing Start Menu Items from User Accounts
          zman Master

          I'm not a big fan of VBscript, so I can't help with the script. My guess is that it does not like running in the local system account context. You may want to simplify the deletion of the shortcuts by using some batch commands:

           

          @ECHO OFF
          DEL /F /S /Q "C:\Documents and Settings\Shortcut.LNK"
          RD /S /Q "C:\Program Files\Avtex"
          

           

          Replace Shortcut.lnk with the name of your shortcut. A lot more efficient and easier to troubleshoot and test.

           

          I would prefer to use the orginal MSIs to uninstall the software.

          • 2. Re: Removing Start Menu Items from User Accounts
            Apprentice

            ya but how do i do that for each and every user profile?  theres no way im gonna hard code 4000 user accounts into a batch file.

            • 3. Re: Removing Start Menu Items from User Accounts
              Employee

              you use a scripting language. Even .BAT could do this, but AutoIT, VB, one of the higher-level languages, whatever.

               

              option 1: assume that most machines have a single user, then write a script which uses %USERNAME% or %USERPROFILE% to do the work, then call that script with LANDesk's startasuser.exe.

               

              option 2: assume multiple accounts per machine, write a script that uses the registry or WMI to iterate all possible profiles and do the uninstallation per profil

              • 4. Re: Removing Start Menu Items from User Accounts
                zman Master

                /s means all subdirectories, so no need to figure out profiles, it will do all profiles. I'm very simple minded so I always go for the simply stuff so I can understand.

                 

                "Try it you'll like it"

                • 5. Re: Removing Start Menu Items from User Accounts
                  Apprentice

                  im not much of a pro at writing this type of stuff.  i can read the code logicly enough.  but i dont know where to begin to write the code.

                   

                  Jack, Every machine has more then 1 user profile unfortunatly, so i would need to crawl threw all of them.  some could have over twenty since this is a call center app that we will be removing, and since users swap desks, and turnover is high in those departments, for completeness we would need to go through and delete it from every profile.

                   

                  zman, using the /s would work, but how do i get it do delete the avtex folder with everythign in it.  Since there are a few versions floating around, the short cut could be called screenpop 1.4, 1.4.1,1.1 and even the spellings cold be differetn some may have spaces some may not, its just poor development in the early stages of this product.

                  • 6. Re: Removing Start Menu Items from User Accounts
                    zman Master
                    DEL /F /S /Q "C:\Documents and Settings\screenpop*.LNK"

                    You can use wildcards (see above) same with the folder deletion. Wildcards can be a little nasty so test.  This will whack anything beginning with screenpop.

                    • 7. Re: Removing Start Menu Items from User Accounts
                      Apprentice

                      hmm... what about deleting the avtex folder is there a way to do that with this syntax as well?

                      • 8. Re: Removing Start Menu Items from User Accounts
                        zman Master
                        for /f "tokens=*" %i in ('dir "c:\program files\avtex*" /b') do rd "%i" /s
                        

                         

                        I left off the /Q from the RD command so you could test. Once tested:

                         

                        for /f "tokens=*" %i in ('dir "c:\program files\avtex*" /b') do rd "%i" /s /q
                        • 9. Re: Removing Start Menu Items from User Accounts
                          Apprentice

                          Well i ment for the C:\Documents and Settings\user\Start Menu\Programs\Avtex

                           

                          I want to delete that folder as well as the shortcuts, so its completely gone, im hoping it will cause less confusion that way.

                          • 10. Re: Removing Start Menu Items from User Accounts
                            zman Master

                            Cool so your happy now, if so close this thread out it is getting too long.

                            • 11. Re: Removing Start Menu Items from User Accounts
                              Apprentice

                              Ive been doing some looking, and this is not going to work.  I cant have it delete every instance of screen pop in the start menu.  we have a newer version in a different folder in the start menu.  so i am back to limiting it to specifically the  C:\Documents and Settings\USERACCOUNT\Start Menu\Programs\Avtex  Folder.

                               

                              Any help will be appreciated.

                              • 12. Re: Removing Start Menu Items from User Accounts
                                Apprentice

                                Ok So I did some searching online, and I came across a bat file, that someone had built to delete the temp files in all the users profiles.  After some tweaking i was able to get this to delete the Avtex folder I was looking for.  thanks for the feedback on this topic, Hope this script helps someone else out in the future.

                                 

                                 

                                Here is the original Script:  http://harrycoal.co.uk/2008/08/20/delete-temp-files-for-each-user-profile/

                                cd /D  C:\Documents and Settings
                                REM —-Clean Temp Folder—
                                for /D %%a in (*.*)  do DEL /F /Q "%%a\Local Settings\Temp\*.*"
                                for /D %%a in (*.*)  do FOR /D %%b IN ("%%a\Local Settings\Temp\*.*") DO RMDIR /S /Q "%%b"
                                REM —-Clean IE Cache—
                                for /D %%a in (*.*)  do DEL /F /Q "%%a\Local Settings\Temporary Internet Files\*.*"
                                for /D %%a in (*.*)  do FOR /D %%b IN ("%%a\Local Settings\Temporary Internet Files\*.*") DO RMDIR /S /Q "%%b"
                                pause

                                I modified it slightly to delete the folder I needed.  Initial tests show that it is working properly:

                                 

                                cd /D  C:\Documents and Settings
                                REM —-Clean Temp Folder—
                                for /D %%a in (*.*)  do DEL /F /Q "%%a\Start Menu\Programs\Avtex*.*"
                                for /D %%a in (*.*)  do FOR /D %%b IN ("%%a\Start Menu\Programs\Avtex*.*") DO RMDIR /S /Q "%%b"
                                RMDIR /S /Q "C:\Program Files\Avtex"