How to run .bat file in Windows 7?

Page 1 of 2 12 LastLast

  1. Posts : 3
    se7en
       #1

    How to run .bat file in Windows 7?


    I was hoping someone could assist me with running a .bat file on Windows 7.

    Previously, in WinXP I would run a .bat file from launchy to add a task to my remember the milk account. The .bat file was stored under C:\Program Files\Launchy\Utilities\Launchy Batch Plug-ins.

    The problem is that the cmd window will pop up and disappear but nothing gets added to the rtm account.

    Here is what I have tried:
    1) Since ProgramFiles is a 'protected directory' I have moved the .bat file to the D drive. same problem
    2) Tried to set the .bat file or the launchy.exe file to Run As Admin. .bat file is greyed out and launchy still gets the same problem
    3) turned off windows defender service, same problem

    Does anyone have any other ideas? Thanks for the help.
      My Computer


  2. Posts : 11,990
    Windows 7 Ultimate 32 bit
       #2

    You may get an answer for an easier way to to this; but the following should work:

    Open an elevated command prompt (run as administrator) the prompt will show C:\windows\system32> by default.

    Change the directory to the directory where you have your batch file. You might find it easier if you move the batch file and the program file back to the C drive.

    At the prompt, type the name of your .bat file and press Enter. It should run.
      My Computer


  3. Posts : 1,241
    Windows 7 Profesional x86, Mac OS X 10.6 Snow Leopard
       #3

    If the .bat file has to do ANYTHING that would require administrative privaliges it will not run correctly at start up or when double clicked.

    The only way to make it able to do administrative things is to right click on the Command Prompt icon in the start menu and click run as Administrator or to follow a tutorial like the one at Always Run a Batch File as an Administrator : Windows Vista and Windows 7 Help.

    The other option is of course to make it so there are no administrative commands in the batch file.

    Oli
      My Computer


  4. Posts : 3
    se7en
    Thread Starter
       #4

    Hi guys, thanks for your quick reply but I may have not communicated correctly.

    The bat file has to run when it is called from Launchy. An example scenario is as follows:


    1. I think of a new task while I am working on something else
    2. I hit alt space to bring up Launchy
    3. I type rtm> new task and hit return
    4. The batch file pops up runs and adds that new task to my Remember the Milk account.
    I am not sure if the bat file contains administrator privilege commands but I am assuming yes because it calls a cmd prompt. Here is the code:

    Code:
    @echo off
    cd c:\
    cmd /c curl --basic --user myname:password --data status="d rtm %*" http://twitter.com/statuses/update.xml
    Echo Exiting...
    The batch file essentially sends a direct message via Twitter to the Remember the Milk friend on Twitter, and this adds it to the task list. I know that part is working because I tested it. It is the running of the .bat that is not working. It worked in XP but know something is stopping it from running.

    Any ideas?

    I turned off UAC (well put it down to never notify) and I tried the shortcut technique that oshalt mentioned but same response.
      My Computer


  5. Posts : 1,170
    XP Pro SP3 X86 / Win7 Pro X86
       #5

    theredmoose said:
    Hi guys, thanks for your quick reply but I may have not communicated correctly.

    The bat file has to run when it is called from Launchy. An example scenario is as follows:


    1. I think of a new task while I am working on something else
    2. I hit alt space to bring up Launchy
    3. I type rtm> new task and hit return
    4. The batch file pops up runs and adds that new task to my Remember the Milk account.
    I am not sure if the bat file contains administrator privilege commands but I am assuming yes because it calls a cmd prompt. Here is the code:

    Code:
    @echo off
    cd c:\
    cmd /c curl --basic --user myname:password --data status="d rtm %*" http://twitter.com/statuses/update.xml
    Echo Exiting...
    The batch file essentially sends a direct message via Twitter to the Remember the Milk friend on Twitter, and this adds it to the task list. I know that part is working because I tested it. It is the running of the .bat that is not working. It worked in XP but know something is stopping it from running.

    Any ideas?

    I turned off UAC (well put it down to never notify) and I tried the shortcut technique that oshalt mentioned but same response.

    Is curl.exe in c:\ ? 'cause that's where your asking it to run from with the cd C:\ command at the beginning of the file. You should take that line out completely and put the batch file in the same folder as your curl.exe file.

    Lets assume your Curl.exe is in c:\program files\launchie
    Take out that first line... and put your RTM.BAT batch file in with it.
    Next you can set launchie to find it there...
    OR
    You can create a shortcut... Right click in the folder where you want the shortcut and select NEW -> Shortcut When asked for the location of the item enter CMD.exe and click next... It will ask for a name for the shortcut... call it say RTM...

    Now go to the shortcut and right click it selecting properties... You will find this...

    How to run .bat file in Windows 7?-capture.jpg

    In the START IN bar type the name of the folder where you have your batch file...
    As you can see in the example I've set it to C:\Program Files\MPClassic... If you're working from c:\program files\launchie... that's what you would put in yours.

    The result of this is that it will open a command prompt in the folder you specify...

    How to run .bat file in Windows 7?-capture2.jpg

    Now since this is the same folder as your batch file which is in the same folder as CURL.EXE your RTM Get Milk command is going to work. All you have to do is click the shortcut.
      My Computer


  6. Posts : 3
    se7en
    Thread Starter
       #6

    Thanks for all the help. In the end it was the location of the curl file not the permissions of running it. I ended up moving it all in the same folder as you suggested. Thanks.
      My Computer


  7. Posts : 11,990
    Windows 7 Ultimate 32 bit
       #7

    Glad you have it working. Thanks for letting us know.
      My Computer


  8. Posts : 1
    Windows 7 Ultimate x64, Windows 7 Ultimate x86, Windows XP Pro x86
       #8

    CommonTater,

    Sry for the necrobump but you were the first person I found that actually gave the right reason for this problem and the correct fix. After over an hour of googling, I had to create an account and tell you thanks. Hopefully others will find their way here as well.
      My Computer


  9. Posts : 1
    7 32
       #9

    The real solution for this (if you run it from a removable device) is just edit the batch file and add (at the top or where must it be) the following line:

    chdir /D %~dp0

    as ralfii stand in Running batch files as administrator change working directory - Vista Help

    it works! tested on Windows XP and Windows Vista
      My Computer


  10. Posts : 5
    Windows 7
       #10

    Sorry for the necrobump after 532 days. (I'm stealing the term used by fwdixon and will use it evermore!). I searched, just as Mr/Ms Dixon did, for a few hours trying to find the solution for this. Common Taters previous post #5 helped a lot. I'm probably less skilled and knowledgeable newbie than the original poster, theredmoose. I wanted to post more detailed how-to instructions for others like me.

    I think this is a problem related to Launchy's operation on 64-bit Windows; I could get Launchy to do what I wanted on an older PC with 32-bit Windows 7.

    My goal was to have Launchy run a batch file to append text to a text file. Why? So that while working on "Project A" I could quickly record thoughts unrelated to "Project A" in a way that didn't disrupt my workflow, such as opening another application or using pen and paper.

    Here's what I did and it worked.

    1. Create the batch file in a location outside of the programs folders: the desktop, documents, etc. I'll use "MyDocs" in this explanation.
    2. Copy the batch file and paste a shortcut in the same MyDocs folder.
    3. Right-click on the shortcut and select properties.
    4. Change the target to C:\Windows\System32\cmd.exe
    5. Change the "start in" location to the launch utilities folder. I used the default installation location: C:\Program Files (x86)\Launchy\Utilities
    6. Click the Advanced button
    7. Check the box "Run as Administrator"
    8. Okay your way out of the properties dialog.
    9. Copy the batch file and the shortcut to the Launchy Utilities folder. (I copied from MyDocs instead of moving. If I needed to change the .bat file, editing the .bat file in the Utitilies folder (a sub-sub of Program Fiels) didn't work well for me.)
    10. Open the Launchy options, click the catalog tab.
    11. Check "include executables"
    12. Add .bat and .lnk to the file types.
    13. Rescan the Launchy catalog.
    Attached Thumbnails Attached Thumbnails How to run .bat file in Windows 7?-shortcut-properties.png   How to run .bat file in Windows 7?-utilities-folder.png   How to run .bat file in Windows 7?-catalog-launchy4win7.png  
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:56.
Find Us