1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Make a scheduled batch file, from a batch

Discussion in 'Windows XP' started by Ph4te, 2006/04/17.

  1. 2006/04/17
    Ph4te

    Ph4te Inactive Thread Starter

    Joined:
    2006/04/17
    Messages:
    9
    Likes Received:
    0
    OK, so lets say i have batch file "one" (one.bat), and i want to make a batch file to execute some commands to make one.bat run on startup, how can i do this??
    I just need to know how to make that second batch file, I know how to create an autorun file...
    I bet there is a simpler way to do what i want... :confused:
     
  2. 2006/04/17
    Zander

    Zander Geek Member Alumni

    Joined:
    2002/01/07
    Messages:
    4,084
    Likes Received:
    5
    If you want it to run every time you start the computer, put a shortcut to one.bat in the startup folder in your start menu.
     

  3. to hide this advert.

  4. 2006/04/18
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    Use the registry

    If you want that specific bat to run automatically when windows boots, you have a few options, the startup folder is one good and really easy option. However, you can also create a registry (start-run-regedit) key in hklm-software-microsoft-windows-current version-run that points to your batch file. This method is really easier than it seems and will ensure that the batch fille will run automatically no matter who logs in.
     
  5. 2006/04/18
    Ph4te

    Ph4te Inactive Thread Starter

    Joined:
    2006/04/17
    Messages:
    9
    Likes Received:
    0
    ok thanks for the tips, but I would like a way fr me to make it ALL automatic,
    i pop in CD and then it executes everything i want to do(my one.bat, and some other type of file that creates possibly a startup process)
     
  6. 2006/04/18
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    OK, i see what you are attempting to do now. Easiest way in my mind is to create a batch file that copies the one.bat to the startup folder in your profile, and have the autorun execute that batch. I would assume using xcopy will work best in the batch file.
     
  7. 2006/04/18
    Ph4te

    Ph4te Inactive Thread Starter

    Joined:
    2006/04/17
    Messages:
    9
    Likes Received:
    0
    Yeah, this is what i had in mind, now as for making that batch that copies one.bat to the startup folder, i have no clue
     
  8. 2006/04/18
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    try this: xcopy one.bat "C:\Documents and Settings\Default User\Start Menu\Programs\Startup "
    Copy everything starting at xcopy and ending at the " into a text file and save it as a anything.bat. Put this bat in the same directory as the one.bat and create the autorun.inf to launch this batch file. Hope it works, if not we can probably get it fixed with some tweaking.
     
  9. 2006/04/19
    Ph4te

    Ph4te Inactive Thread Starter

    Joined:
    2006/04/17
    Messages:
    9
    Likes Received:
    0
    in that string "C:\Documents and Settings\Default User\Start Menu\Programs\Startup "...... where it says Default User, would it be better if I used "All Users" ?
    Or does Default User work just as well?
    Concern is that lets say i run these batches on a computer that has multiple usernames, and it only adds the batch to the startup for only one user and not all of them.
    Why I thought xcopy was a program, I do not know :confused:
    Also, does anyone know a way to make a batch file pause but only for a certain amount of time,
    (i.e. A period appears once a second [Please Wait...............----->])
     
    Last edited: 2006/04/19
  10. 2006/04/19
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    The all users will work also. I like using the default users folder because it is hidden and adding something in the start up there will add it for everyone and people will not see it. I hope im making sense. Try it and see how it works.
     
  11. 2006/04/19
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    Better to not code the paths using drive letters because not all comps will have the os that's in use on drive c, so use:

    "%UserProfile%\Start Menu\Programs\Startup "

    This way it wiill always work for the currently logged in user.

    xcopy IS a program (command line program), comes w/ windows.

    here's all the commands that work in xp:
    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true

    A Timer?
    create a loop.
    example:
    Code:
    :START
    REM Execute the MS-DOS dir command ever 20 seconds.
    dir
    SLEEP 20
    GOTO END
    OR
    can use ping to create a timed delay.
     
    Last edited: 2006/04/19
  12. 2006/04/19
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0

    Good point! Thanks, How would you show the path of the default user instead of %UserProfile%, so that it will run for everyone who logs in and not just the currently logged in user?
     
  13. 2006/04/20
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    http://www.microsoft.com/resources/.../all/proddocs/en-us/ntcmds_shelloverview.mspx

    Code:
    %ALLUSERSPROFILE%
     Local
     Returns the location of the All Users Profile.
     
    %APPDATA%
     Local
     Returns the location where applications store data by default.
     
    %CD%
     Local
     Returns the current directory string.
     
    %CMDCMDLINE%
     Local
     Returns the exact command line used to start the current Cmd.exe.
     
    %CMDEXTVERSION%
     System
     Returns the version number of the current Command Processor Extensions.
     
    %COMPUTERNAME% 
     System
     Returns the name of the computer.
     
    %COMSPEC% 
     System
     Returns the exact path to the command shell executable.
     
    %DATE% 
     System
     Returns the current date. Uses the same format as the date /t command. Generated by Cmd.exe. For more information about the date command, see Date
     
    %ERRORLEVEL% 
     System
     Returns the error code of the most recently used command. A non zero value usually indicates an error.
     
    %HOMEDRIVE% 
     System
     Returns which local workstation drive letter is connected to the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
     
    %HOMEPATH% 
     System
     Returns the full path of the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
     
    %HOMESHARE% 
     System
     Returns the network path to the user's shared home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
     
    %LOGONSEVER% 
     Local
     Returns the name of the domain controller that validated the current logon session.
     
    %NUMBER_OF_PROCESSORS% 
     System
     Specifies the number of processors installed on the computer.
     
    %OS% 
     System
     Returns the operating system name. Windows 2000 displays the operating system as Windows_NT.
     
    %PATH%
     System
     Specifies the search path for executable files.
     
    %PATHEXT%
     System
     Returns a list of the file extensions that the operating system considers to be executable.
     
    %PROCESSOR_ARCHITECTURE% 
     System
     Returns the chip architecture of the processor. Values: x86, IA64.
     
    %PROCESSOR_IDENTIFIER%
     System
     Returns a description of the processor.
     
    %PROCESSOR_LEVEL% 
     System
     Returns the model number of the processor installed on the computer.
     
    %PROCESSOR_REVISION%
     System
     Returns the revision number of the processor. 
     
    %PROMPT%
     Local
     Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
     
    %RANDOM%
     System
     Returns a random decimal number between 0 and 32767. Generated by Cmd.exe.
     
    %SYSTEMDRIVE%
     System
     Returns the drive containing the Windows XP root directory (that is, the system root).
     
    %SYSTEMROOT% 
     System
     Returns the location of the Windows XP root directory.
     
    %TEMP% and %TMP%
     System and User
     Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP.
     
    %TIME%
     System
     Returns the current time. Uses the same format as the time /t command. Generated by Cmd.exe. For more information about the time command, see Time
     
    %USERDOMAIN%
     Local
     Returns the name of the domain that contains the user's account.
     
    %USERNAME%
     Local
     Returns the name of the user who is currently logged on.
     
    %USERPROFILE%
     Local
     Returns the location of the profile for the current user.
     
    %WINDIR%
     System
     Returns the location of the operating system directory.
     
    
     
  14. 2006/04/20
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    This is great! I've always seen these paths but never new how to map them!. Thanks alot, this will def. be useful in the future.
     
  15. 2006/04/20
    rsinfo

    rsinfo SuperGeek Alumni

    Joined:
    2005/12/25
    Messages:
    4,076
    Likes Received:
    178
    Expanding on the thread, is there a way to execute the bat file (or even a program) even if no one logs in?
     
  16. 2006/04/20
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    The easiest way in my opinion is to create a scheduled task (the wizard is in the control panel). Choose the batch file you created as the program to run and choose "When my computer starts" as the time to execute.
     
  17. 2006/04/20
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    Well...there are 53 different locations/areas that a program can be started from when a xp comp is turned on. AKAIK, they all occur after a logon. Even if no pword has been set and the system boots right to the desktop (skipping logon) the execution occurs after "where login would be" in the sequence. The exception would be possibly a Run Once key where an app runs before explorer loads, such as an av scanner or anti-spy scanner.
     
  18. 2006/04/20
    rsinfo

    rsinfo SuperGeek Alumni

    Joined:
    2005/12/25
    Messages:
    4,076
    Likes Received:
    178
    TonyT, I don't want the program to run after logon. I want it to be executed even if no one logs in (ie. you get the Welcome login screen).
     
  19. 2006/04/21
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    Understood. Well, there must be a way to do this because one can use a script that auto-logs-in a user, so therefore the script gets executed prior to logon. Probably run as a service, see this table that shows entire windows boot process from start to finish:
    http://dotnetjunkies.com/WebLog/unknownreference/articles/12284.aspx
     
    Last edited: 2006/04/21
  20. 2006/04/21
    tonman23

    tonman23 Inactive

    Joined:
    2006/04/18
    Messages:
    38
    Likes Received:
    0
    You can use the windows scheduled task wizard to create a startup service and it's actually pretty easy. It can also be down with a group policy but here is how i did it in windows scheduled task:
    These particular procedures are for Windows XP Professional - others should be similar.
    1. Click Start, Settings, Control Panel, Scheduled Tasks, Add Scheduled Task
    2. Click Next to begin the Wizard
    3. Instead of choosing a program from the list, click Browse
    4. Browse to C:\batch files (or wherever you put it) and choose mybatch.bat
    5. The next window asks you to type a name for the task. Enter anything you like, such as 'startup task'. Below the box for the name are some choices for when to perform the task. Choose
    "When my computer starts ".
    6. The next window prompts for the user name and password to run as. For the user name, enter "NT
    AUTHORITY\SYSTEM" (without the quotes). Leave the password boxes blank.
    7. The next window tells you you've successfully created the task and gives you a checkbox option to
    "Open advanced properties for this task when I click Finish ". Check that box and click Finish.
    8. In the advanced properties, go to the Settings tab and uncheck the "Stop this task if it runs for xx
    hours" box.
    9. Click OK to close the window.
    To activate the new scheduled task you can Reboot, or do the following:
    1. Click Start, Settings, Control Panel, and then double-click the Scheduled Tasks item. If you do this
    correctly, a separate window of your scheduled tasks, and details about them, will open.
    2. Find your 'startup' task you created.
    3. Right-click the task and choose "Run ". If everything is correct, the "Status" of the task will change to
    "Running" but you won't see a batch window open (because it is running in the background).

    Try this out and let me know how it goes.
     
  21. 2006/04/23
    TonyT

    TonyT SuperGeek Staff

    Joined:
    2002/01/18
    Messages:
    9,072
    Likes Received:
    400
    %SystemDrive%\ can be used as well for scripts to run on any system where the os install drive is unknown.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.