Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: How to run .bat file in Windows 7?

06 Apr 2010   #1

se7en
 
 
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 System SpecsSystem Spec
.

06 Apr 2010   #2

Windows 7 Ultimate 32 bit
 
 

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 System SpecsSystem Spec
06 Apr 2010   #3

Windows 7 Profesional x86, Mac OS X 10.6 Snow Leopard
 
 

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 System SpecsSystem Spec
.


06 Apr 2010   #4

se7en
 
 

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 System SpecsSystem Spec
06 Apr 2010   #5

XP Pro SP3 X86 / Win7 Pro X86
 
 

Quote   Quote: Originally Posted by theredmoose View Post
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...

Name:  Capture.JPG
Views: 461
Size:  45.4 KB

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...

Name:  Capture2.JPG
Views: 428
Size:  29.4 KB

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 System SpecsSystem Spec
06 Apr 2010   #6

se7en
 
 

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 System SpecsSystem Spec
07 Apr 2010   #7

Windows 7 Ultimate 32 bit
 
 

Glad you have it working. Thanks for letting us know.
My System SpecsSystem Spec
08 Jan 2012   #8

Windows 7 Ultimate x64, Windows 7 Ultimate x86, Windows XP Pro x86
 
 

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 System SpecsSystem Spec
22 Mar 2012   #9

7 32
 
 

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 System SpecsSystem Spec
05 Sep 2013   #10

Windows 7
 
 

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 Images
   
My System SpecsSystem Spec
Reply

 How to run .bat file in Windows 7?




Thread Tools




Our Sites

Site Links

About Us

Find 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 03:58 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33