Announcement

Collapse
No announcement yet.

Trying to delete a specific file at logon

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to delete a specific file at logon

    Hi everyone,
    We are in the process of going through an email migration, and one of the problems we are having is that Outlook keeps trying to use the cache'd email information from the Outlook Nickname file (NK2). I am looking for a script that will delete the NK2 file that is located at:
    c:\documents and settings\%username%\application data\microsoft\outlook\

    If the file doesn't exist, or the profile folder is named something different, the script should just exit. I would like to put this in my logon script, which is currently a kix script.

    Thanks much

    app

  • #2
    Re: Trying to delete a specific file at logon

    http://www.robvanderwoude.com/if.html
    Shows the if command in a batch if you fancy a go yourself
    cheers
    Andy

    Please read this before you post:


    Quis custodiet ipsos custodes?

    Comment


    • #3
      Re: Trying to delete a specific file at logon

      If Exist ("c:\documents and settings\%username%\application data\microsoft\outlook\%username%.NK2")
      Del "c:\documents and settings\%username%\application data\microsoft\outlook\%username%.NK2"
      EndIf
      GoTo End

      ; ----- End Of Script ----------------------------------------------------------
      :End
      Exit

      I would use something like this.

      Comment


      • #4
        Re: Trying to delete a specific file at logon

        I am not familiar w/ KiXtart, but when it is not possible to adapt the code below in a KIX script, then add this batch as an extra logonscript via GPO or, maybe you can call the batch from within KIX.
        Code:
        :: http://forums.petri.com/showthread.php?t=23602
        ::
        :: With this Batch you can
        :: delete a common file (or filetype) from a folder
        
        @echo off
        
        SetLocal
        
        Set "$Folder=%userprofile%\Application Data\Microsoft\Outlook"
        Set "$File=*.NK2"
        
        Set "projTag=200805"  =will be added to the old file, to be left as 'done already'-flag for this logonscript
        
        If defined $Folder (
          PushD "%$Folder%" &&(
            For /f "Tokens=*" %%* in ('dir/B "%$File%" /A-D 2^>nul') Do (
              If exist "%%*.bak" (Del /F "%%*.bak")
              Ren "%%*" "%%*.bak%projTag%" 2>Nul
            )
            PopD
          )
        )
        
        EndLocal
        It is optional to use the variable 'projTag' here.
        When you define 'projTag' w/ an unique string (e.g. a date mark), the script can determine the NK2 file is already processed once. Otherwise the logon script will rename (or delete) the user's NK2 files again and again at every logon.

        \Rems
        Last edited by Rems; 2nd May 2008, 15:26. Reason: added "If defined" statement for safety

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Trying to delete a specific file at logon

          Why so difficult if the code i supplied wich is from Kixtart is much easier?
          So it checks everytime you login if the file excist, but still the loginscript will finish in a few seconds.
          I am not flaming in any kind, just wondering why you should do it in a hard way if it can be done the easy way.

          Originally posted by Rems View Post
          I am not familiar w/ KiXtart, but when it is not possible to adapt the code below in a KIX script, then add this batch as an extra logonscript via GPO or, maybe you can call the batch from within KIX.
          Code:
          :: http://forums.petri.com/showthread.php?t=23602
          ::
          :: With this Batch you can
          :: delete a common file (or filetype) from a folder
          
          @echo off
          
          SetLocal
          
          Set "$Folder=%userprofile%\Application Data\Microsoft\Outlook"
          Set "$File=*.NK2"
          
          Set "projTag=200805"  =will be added to the old file, to be left as 'done already'-flag for this logonscript
          
          If defined $Folder (
            PushD "%$Folder%" &&(
              For /f "Tokens=*" %%* in ('dir/B "%$File%" /A-D 2^>nul') Do (
                If exist "%%*.bak" (Del /F "%%*.bak")
                Ren "%%*" "%%*.bak%projTag%" 2>Nul
              )
              PopD
            )
          )
          
          EndLocal
          It is optional to use the variable 'projTag' here.
          When you define 'projTag' w/ an unique string (e.g. a date mark), the script can determine the NK2 file is already processed once. Otherwise the logon script will rename (or delete) the user's NK2 files again and again at every logon.

          \Rems

          Comment


          • #6
            Re: Trying to delete a specific file at logon

            Hey guys,
            both work great. I ended up making a slight change to Iznogoud's script (instead of %username%.NK2, i replaced it with *.NK2) and it works great. I was playing with the one from Rems, and that was great as well, i especially like the fact that he was able to incorporate %userprofile% since sometimes the profile name is not exactly the user's name, but this will work for 99% of my users, so this will make me very happy (My boss too!!!)

            Thanks for the help

            app

            Comment


            • #7
              Re: Trying to delete a specific file at logon

              Originally posted by apperrault View Post
              Hey guys,
              both work great. I ended up making a slight change to Iznogoud's script (instead of %username%.NK2, i replaced it with *.NK2) and it works great. I was playing with the one from Rems, and that was great as well, i especially like the fact that he was able to incorporate %userprofile% since sometimes the profile name is not exactly the user's name, but this will work for 99% of my users, so this will make me very happy (My boss too!!!)

              Thanks for the help

              app
              As for further notice Kixtart does also knows the %userprofile%. A complete list of the commands can you find at this site:
              http://www.kixtart.org/?p=commandRef

              ps. Don't be shy to give us or him some reputation points

              Comment


              • #8
                Re: Trying to delete a specific file at logon

                Nice to hear apperrault!


                Originally posted by Iznogoud View Post
                Why so difficult if the code i supplied wich is from Kixtart is much easier?
                So it checks everytime you login if the file excist, but still the loginscript will finish in a few seconds.
                I am not flaming in any kind, just wondering why you should do it in a hard way if it can be done the easy way.
                Hi Iznogoud,

                We both showed a possible solution, the OP now had choices.

                I don't want to compare both scripts as one is the hard way and the other the easy way (btw implementing KiX just for this would be the hardway option for me ), it are just two solutions with different results!

                I can explain the few extra lines of code in my scripted solution, this would still be ontopic and possibly helping others.
                I am not familiar with KiXtart, I didn't even know your code was KIX code. I would have written my soluten in KIX if I could.
                What my point was and is, is that your script not just checks everytime you login, because it will delete the 'nickname and the automatic completion cache' too everytime it was created during a previous logon - by doing so your solution will persistantly interfere with this feature of outlook. We do not know if the users in apperrault's network actualy have asked for that?

                My example was written as batch because that is the easiest way, I'am positive something similar can be accomplish with KiX, but it can be runned as separate batch also I don't think that would be to difficult.


                \Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: Trying to delete a specific file at logon

                  The funny thing of Kix is it can do all the same things DOS can, but than more.
                  What you could do with kix is write to a registry key a value wich he checks the next time if excist then skip. Or it could the same as you did with your code.

                  If i can understand Kix than you can. If needed i could show an example of a kix script wich i use at one of my clients. But that would be a bit offtopic.

                  But the best thing is that apperrault has a solution

                  Originally posted by Rems View Post
                  Nice to hear apperrault!



                  Hi Iznogoud,

                  We both showed a possible solution, the OP now had choices.

                  I don't want to compare both scripts as one is the hard way and the other the easy way (btw implementing KiX just for this would be the hardway option for me ), it are just two solutions with different results!

                  I can explain the few extra lines of code in my scripted solution, this would still be ontopic and possibly helping others.
                  I am not familiar with KiXtart, I didn't even know your code was KIX code. I would have written my soluten in KIX if I could.
                  What my point was and is, is that your script not just checks everytime you login, because it will delete the 'nickname and the automatic completion cache' too everytime it was created during a previous logon - by doing so your solution will persistantly interfere with this feature of outlook. We do not know if the users in apperrault's network actualy have asked for that?

                  My example was written as batch because that is the easiest way, I'am positive something similar can be accomplish with KiX, but it can be runned as separate batch also I don't think that would be to difficult.


                  \Rems

                  Comment

                  Working...
                  X