Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Run a batch file before Windows User logon  (Read 9147 times)

0 Members and 1 Guest are viewing this topic.

ionic

    Topic Starter


    Rookie

    Run a batch file before Windows User logon
    « on: January 07, 2008, 01:56:19 PM »
    I run a program called PerfectDisk.  essentially it is an alternative to Windows XP "Defrag". One option is to defragment metafile data on restart. My guess is that it performs this prior to loading windows services or as a service, but before the any User logon.  I say this because my attempt to run a batch file from another batch file when placed in the Startup folder is too late in the boot process.

    Test Code:
    Code: [Select]
    CALL HI.BAT
    ECHO Hi Out There!
    pause
    This seems never to run at either restart or Shutdown/Restart



    My final hope is to run a batch file(SDOS.BAT) that calls out an executable file(Sdelete.exe) and SDelete needs access to certain files before they are locked by Windows.

    It's not imperative that it is a batch file but I do need to select multiple files/folders to securely delete. prior to login.

    I suppose that doing this after windows logs off the user when shutting down is another option.

    Any thoughts?






    Sidewinder



      Guru

      Thanked: 121
    • Experience: Familiar
    • OS: Windows 7
    Re: Run a batch file before Windows User logon
    « Reply #1 on: January 07, 2008, 03:46:49 PM »
    This reference will explain how and when programs are run at startup.

    The Startup Control Panel will give you some limited access to the registry startup functions.

    As always, practice safe PC and backup your registry before proceeding.

    Normally I try not to have posters download anything, but in this case it's safer than hacking the registry and turning your PC into a brick.

     8)

    It has been my experience that folks who have no vices have very few virtues

    - Abraham Lincoln

    ionic

      Topic Starter


      Rookie

      Re: Run a batch file before Windows User logon
      « Reply #2 on: January 07, 2008, 04:06:14 PM »
      Normally I try not to have posters download anything, but in this case it's safer than hacking the registry and turning your PC into a brick.

      Been hackin' the registtry for years, so if it is necessary then we can go there.
      But for now I will take your lead and read....the information on the links provided.

      ionic

        Topic Starter


        Rookie

        Re: Run a batch file before Windows User logon
        « Reply #3 on: January 07, 2008, 09:31:41 PM »
        Well,
        According to the startup sequencing RunServicesOnce - This key is designed to start services when a computer boots up. These entries can also continue running even after you log on, but must be completed before the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce registry can start loading its programs.

        This seems to be where I need to run the bat file or executable.

        But since there are currently no entries I can not figure out safetly how to create one.

        Sidewinder



          Guru

          Thanked: 121
        • Experience: Familiar
        • OS: Windows 7
        Re: Run a batch file before Windows User logon
        « Reply #4 on: January 08, 2008, 05:26:18 AM »
        Sdelete may require services or functionality that has not been started when the RunServicesOnce key kicks in.

        If you use regedit, find the key in the left panel, highlight it to see all existing values, right click the right panel, add a new string value, pick a name for your key, and in the data field enter the fully qualified path to your program.

        If you use reg from the command line type reg add /? for details. Note: the regkey data type should be REG_SZ.

        Quote
        My final hope is to run a batch file(SDOS.BAT) that calls out an executable file(Sdelete.exe)

        You may have to run Sdelete.exe directly without the batch wrapper. The cmd processor (required for batch files) may be unable to start this early in the boot cycle.

        Quote
        SDelete needs access to certain files before they are locked by Windows.

        Just asking, but if Windows protects files it needs to operate, why are you deleting them?

        CYA: Backup your Registry before proceeding.

         8)
        It has been my experience that folks who have no vices have very few virtues

        - Abraham Lincoln

        ionic

          Topic Starter


          Rookie

          Re: Run a batch file before Windows User logon
          « Reply #5 on: January 08, 2008, 02:46:58 PM »
          Just asking, but if Windows protects files it needs to operate, why are you deleting them?

          Many files, such as internet explorer history, the temp directory, temporary internet files should be able to clear completely, but files such as the index.dat is hard to securely delete as it is locked by the time you logon. This is just an example of some files that I would like to clean up.

          Rilez



            Greenhorn

            • Experience: Beginner
            • OS: Unknown
            Re: Run a batch file before Windows User logon
            « Reply #6 on: January 13, 2011, 08:21:56 PM »
            I apologize for restarting a 2 year old topic, but I had just a quick question regarding the software earlier posted.
            Quote
            The Startup Control Panel will give you some limited access to the registry startup functions.

            If I were to download that and place a batch file in the RunServicesOnce or RunServices (the batch file being a custom
            login file) would is disrupt the startup process of the computer and harm it?

            Sidewinder



              Guru

              Thanked: 121
            • Experience: Familiar
            • OS: Windows 7
            Re: Run a batch file before Windows User logon
            « Reply #7 on: January 14, 2011, 10:10:38 AM »
            If I were to download that and place a batch file in the RunServicesOnce or RunServices (the batch file being a custom
            login file) would is disrupt the startup process of the computer and harm it?

            Don't know your OS but is there any reason that this login script cannot be attached to Group Policy? Otherwise this link may provide some additional information using some tools from the 2003 Resource Kit.

            Good luck.  8)
            It has been my experience that folks who have no vices have very few virtues

            - Abraham Lincoln

            Rilez



              Greenhorn

              • Experience: Beginner
              • OS: Unknown
              Re: Run a batch file before Windows User logon
              « Reply #8 on: January 14, 2011, 10:36:07 AM »
              My OS is Windo.ws 7 that link does help, but the question remains, if I were to put a simple batch file there to run before windows logon screen would it harm my computer. (Also, its an Acer 5532 if its important)

              Sidewinder



                Guru

                Thanked: 121
              • Experience: Familiar
              • OS: Windows 7
              Re: Run a batch file before Windows User logon
              « Reply #9 on: January 14, 2011, 11:33:22 AM »
              Don't honestly know if it would harm your computer.

              Call me crazy, but I thought login scripts were run after a user logged-in and it could be determined what script (if any) would run for this user.

              It might help everyone if you posted the batch file.

               8)
              It has been my experience that folks who have no vices have very few virtues

              - Abraham Lincoln

              Rilez



                Greenhorn

                • Experience: Beginner
                • OS: Unknown
                Re: Run a batch file before Windows User logon
                « Reply #10 on: January 14, 2011, 03:03:34 PM »
                This is the Login file. I copied from a script someone released on YouTube. (I did not create the file)
                It just has simple login capabilities along with remote options (like I stated earlier).

                [recovering disk space - old attachment deleted by admin]

                Sidewinder



                  Guru

                  Thanked: 121
                • Experience: Familiar
                • OS: Windows 7
                Re: Run a batch file before Windows User logon
                « Reply #11 on: January 15, 2011, 08:08:27 AM »
                The batch code you posted appears to be safe. There are a couple of del commands you may want to check out but nothing particularly malicious.  I suspect the code would run perfectly on the author's machine, but not anybody elses. There are also references to other batch files and executables that you may or may not have on your system.

                Most login scripts I have ever seen or written are used to setup a user environment (map network drives, attach printers, empty temp directories etc.) Generally they are "once and out" in that they run from top to bottom without any user intervention.

                There is no reason to even try to run this script before Windows User logon. Better to put this in the startup folder; even better start over and customize it for your machine/network.  You can try using this link as a template.

                Good luck.  8)

                [opinion]
                The batch code posted should be the poster child of what not to do when writing batch code. There are no indents, no whitespace, no comments, constructs which are difficult to follow and a menu 60 lines long. It was a mind numbing experience.
                [/opinion]

                « Last Edit: January 15, 2011, 08:26:11 AM by Sidewinder »
                It has been my experience that folks who have no vices have very few virtues

                - Abraham Lincoln

                Salmon Trout



                  Genius

                  Thanked: 757
                  • Yes
                • Computer: Specs
                • Experience: Experienced
                • OS: Windows 7
                Re: Run a batch file before Windows User logon
                « Reply #12 on: January 17, 2011, 11:24:12 AM »
                The batch code posted should be the poster child of what not to do when writing batch code.[/opinion]

                That code is about as bad as I have ever seen. Utterly without merit. It contains classics like this

                Code: [Select]
                set /p newname="Enter new username:"
                if "%newname%"=="%newname%" goto inputname
                :inputname

                and this

                Code: [Select]
                goto next
                :next

                It is what many people do when they first discover batch scripting. They write an 882 line batch script with menus to run Notepad.



                Stirb nicht vor mir - Rammstein