Batch files

Discussion in 'Software' started by Kippin, Mar 20, 2010.

  1. Kippin

    Kippin Private E-2

    Hello, I made a batch file and am trying to have it run on startup. For simplicity, let's say the batch commands IE to open. When I double click the batch file, it does just that, IE opens.

    However, when I create a shortcut of the batch file and put it in the startup folder, IE does not start when Windows starts. What do I do to make the batch file run its commands every time Windows starts without me having to manually double click the file?

    Thanks!
     
  2. Mada_Milty

    Mada_Milty MajorGeek

    I just tested putting a shortcut to a batch file in my startup folder on WinXP SP3, and it worked, so what version are you using? If it's the same or sooner, I would suspect a deeper issue. If it's a later version, there may be a security issue that I'm not considering. Have you tried putting your shortcut in both the %ALLUSERSPROFILE%\startup AND %USERPROFILE%\startup folder?

    A workaround might be to add a entry to the registry in either the:

    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (for your current user account)

    or the:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (for all user accounts)

    keys. In either registry case, you would need to add a string value, whatever name, and make the value "cmd.exe <pathtobatchfile>"
     
    Last edited: Mar 20, 2010
  3. Kippin

    Kippin Private E-2

    Thanks for the reply. Unfortunately, I'm not very informed on batch files so a lot of what you said went a bit over my head. Here's a bit of information I can give you though:

    I am running XP SP3. There is only one user account on my computer.

    I right clicked the batch file and selected create shortcut. I did edit/cut on the shortcut. I clicked start, all programs, right clicked the folder "Startup" and selected "open." I then did a edit/paste in there and saw the shortcut I created.
     
  4. Mada_Milty

    Mada_Milty MajorGeek

    I apologize, I knew I should have explained everything, but I was feeling lazy enough to hope you were in the know. :-D

    For the future:

    Words wrapped in percent signs, (ex. %USERPROFILE% and %ALLUSERSPROFILE%) are called environment variables. They are a convenient way for programmers to refer to commonly used, but often changing data.

    For WinXP, by default (ie. these values can be changed):

    %ALLUSERSPROFILE% expands to c:\documents and settings\all users

    and

    %USERPROFILE% expands to c:\documents and settings\username (where username will match the name of the account you are logged in as)

    The startup folder you see on your start menu is a composite of these two folders. It will list the contents of both, and should allow you to write ONLY to your own. (Short of taking administrative workarounds)

    You've answered my question, though. Using the method you've described, you've added a shortcut to the %USERPROFILE%\startup folder.

    It is odd to me that this method works on my system, and not yours. Hopefully, we can identify the difference between our systems.

    When you reboot, or log out and back in, does your shortcut still appear in this folder?

    What security applications do you run? Is it possible that one is offering startup program protection that is interfering with what you're trying to do?
     
    Last edited: Mar 20, 2010
  5. Kippin

    Kippin Private E-2

    After a reboot, the shortcut is still in the folder. My security is minimal.

    To be fair though, I should probably say that I did make the batch file on a different computer (using windows 7 ultimate x64). I tested the batch file on the Windows 7 PC and it worked by double clicking it. However, I never tested it on startup. I then transferred that file to the XP PC using a USB drive. From the XP PC I made the shortcut and put it in the startup. I never tested double clicking on the XP PC, but the startup is not working.

    Could that have something to do with it?

    (PS I don't have access to the XP PC at the moment)
     
  6. Mada_Milty

    Mada_Milty MajorGeek

    Okay, the shortcut is still there, that's good. Although, the "No access to XP PC" worries me. We are still talking about the XP machine, right? You didn't just test this on the Win7 machine when we're trying to diagnose the former, correct?

    And please do be specific about the security applications. When you say "security is minimal", I'm going to operate under the assumption that the XP PC is running no antivirus and no antispyware programs.

    Now, if both my assumptions above are correct, we have a shortcut that remains in the startup folder, even on reboot of a WinXP PC with no security applications. Are there any other shortcuts in the same folder that DO execute on startup of Windows?

    I don't expect that this has any effect on the situation. Your batch file is just plain text, correct? You haven't put any special character sets or encoding on the file, right? A simple text file should transfer from the first operating system to the next.
     
  7. Kippin

    Kippin Private E-2

    That is correct.

    There are no other shortcuts in the startup folder. And by no access to the XP computer, I mean that I won't have access to the computer we are troubleshooting for probably a few more hours. And yes, the batch is plain text. I opened up notepad, put the code in there and saved it with a .bat ending under "All files."
     
  8. Mada_Milty

    Mada_Milty MajorGeek

    I've overthought the problem here (I don't often get to use Vista/Win7 on a personal basis)... On win7, the location of the internet explorer executable is c:\programs\internet explorer\iexplore.exe, correct? On winXP, the location of the internet explorer executable is c:\program files\internet explorer\iexplore.exe...

    Can we verify that the batch file is using the correct path for your operating system?

    Hahaha... this is a case where environment variables would come in handy. I believe if you used %PROGRAMFILES%\internet explorer\iexplore.exe, %PROGRAMFILES% would expand to the correct path on BOTH operating systems.
     
    Last edited: Mar 20, 2010
  9. Kippin

    Kippin Private E-2

    Well, I just used the IE thing as an example. The batch file itself has nothing to do with file locations.
     
  10. Mada_Milty

    Mada_Milty MajorGeek

    Oh, drats. So, you're certain that the batch file does not execute at all, then? Is it possible that it executes so quickly you don't notice it? Are you comfortable posting your code for review?

    If not, back to the serious troubleshooting: When you have access again, can we test the same method you've used above on another shortcut for more regularly used program? (A shortcut from the desktop or start menu would do nicely). I'm trying to determine if only batch files, or all startup programs fail to launch at startup. If it's the former, I would go back to suspecting a security configuration problem. If it's the latter, I would begin looking for operating system/file system issues.
     
  11. Kippin

    Kippin Private E-2

    Yeah, I'll try to post the code when I have access to the computer again.
     
  12. Break_Da

    Break_Da Sergeant

    I am curious what the desired outcome is? What is the purpose after getting the .bat file to run upon log in during start up? tia
     
  13. Kippin

    Kippin Private E-2

    Well, it's hard to say without sounding shady. The purpose is to shut down the computer every time it starts up. It's for educational purposes. I'm trying to see different things that can be done with batch files and although I have been able to make a shut down batch, I'm not satisfied that it won't work on startup.
     
  14. Kippin

    Kippin Private E-2

    Okay so here is the batch file code:

    @ echo off
    SHUTDOWN -s -t 01

    I put a shortcut of it in the Startup folder. I double clicked the shortcut and the computer shut down. However, it won't shut down on startup.
     
  15. Mada_Milty

    Mada_Milty MajorGeek

    Have you had a chance to test another startup file? I think I remember trying something similar, and having difficulties myself. I wonder if there is a security setting inbuilt into windows that prevents this specific command. If we can test another startup (or even, another, more innocuous batch file that say, ran ipconfig >> c:\ipconfiguration.txt) and it succeeds, we could probably say that this is the case.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds