how to create an .inf file that will open a .bat file - batch-file

I'm trying to create an inf file containing a command which opens a .bat file, but it doesn't work.
I've used "run=", "open=", "shellexecute=" but nothing worked.
I've also tried to plug the removable disk, (which contains the inf file), into another computer, but still doesn't work.
Additionally, I've also tried other commands like "icon=" and which works. But when I use the command "run=", "open=", etc. I still can't open the .bat file that I created, and have placed in the same removable disk.

Related

Running SAVE AS using a batch file

I have a batch file that creates text files in multiple folders.
What I need it to do as well, is after creating that text file, save a copy of it as a .scr file
If I were to do with this without a batch file, I would open the text file, click SAVE AS and save the file with a .scr extension. I cannot figure out how to add this feature to my batch file however.
The original text file cannot be erased, so I can't just change the extension. I would have to copy it, then change the extension, or imitate the SAVE AS feature.
Help?
I just used the ren *<> *<> command. It is extremely redundant because I end up making two text files that are identical and just changing one, but it gets the job done

Batch Files - Closing Opened Text Files

I currently have a Windows batch file that runs an .exe file that uses a text file. I am trying to have the Windows batch file run the .exe file multiple times. This, however, requires the use of the same text files to read from. The command prompt gives me the error that the ".txt could not be opened" (I assume from this that it is already open.)
I am trying to see if there is a way in a .bat file to system call to kill that specific text file. The suggestions I see online are to use 'taskkill notepad.exe', but that returns "invalid argument" because the program doesn't open Notepad to use the text file.
Any suggestions would be appreciated.
It sounds like your existing script fails because the first instance of the exe is still open when the second instance starts.
One thing worth trying (and this depends on the nature of the application you are invoking) is to start the executable using the START /WAIT /B ... command. This makes the command interpreter wait for the program to exit before it moves onto the next command, so as long as nothing else is locking the text files you should be OK to move onto the next command.

How can you open a non-specific file using a program called through a batch file?

I can find plenty of answers on the internet about how to open a specific file, e.g. http://answers.yahoo.com/question/index?qid=20080102230630AAfu5dF
However, I need to provide a way of opening a non-specific file in a program called by a batch file.
To explain, here is an example. The user has a folder with 100 files in with the .xyz extension. He wants to be able to double click on ANY file and open it in his "XYZ Viewer," but to run his XYZ Viewer he needs to run a batch file that alters his registry and then runs the actual XYZ Viewer .exe.
If you select the batch file to be the default program via the "Always use the selected program to open this kind of file" tickbox, it will open the program, but without using the standard Windows function of opening the file that instigating the running of the program.
Is there a way to run the program through the batch file and for it to both run the program and open whichever file it was that instigated the running of the program?
I suspect this is impossible, but any suggestions would be very gratefully received!
Cheers.
Edit:
The program does eventually support opening a file placed as an argument to it.
My code is
reg import c:\regent\31.2.03.reg
start C:\Program\Program.exe
Does the program eventually support opening a file placed as an argument to it? In the example you linked, mspaint opens the first parameter given to it.
If your batch file isn't currently doing this, you will have to edit it to contain the batch parameter(s).
See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true for some fuller documentation on it.
Essentially you want to add %1 somewhere like:
reg import c:\regent\31.2.03.reg
start C:\Program\Program.exe %1

.BAT Copying file - same directory different drive

How would i go about writing a .bat file, so that i can drag and drop a file onto it in windows 7, that would copy the file to the same directory, but on a different drive?
So if my file was:
D:\Files\Newfiles\File01.jpg
It would copy it to a prespecified network location (COMPUTER_01):
\\COMPUTER_01\Files\Newfiles\File01.jpg
I've looked into using command line parameters %~p1 and %~nx1, but i'm not sure how these would be implemented.
I'm sure this is painfully easy to do but I have no idea!
Painfully easy it is:
copy %1 "\\COMPUTER_01%~p1"

How to create a batch file from .exe file?

I want to know simply how to create a batch file from .exe file?
If you mean you want to create a new batch file from an unrelated existing executable file (in other words, the batch file does something different), you do it the way you create any file. In C, you'd use fopen, fwrite and fclose to create your new file and write whatever batch file commands you want to it.
If you mean you want to create a batch file that "intercepts" your exe file, you can do that too. If your executable file is pax.exe, you can simply rename it to pax2.exe and create a batch file called pax.cmd thus:
#echo off
pax2.exe
This will allow you to do arbitrary actions before and after your executable runs but there are things to watch out for such as executables that return control before they're actually finsihed.
If, however, you're talking about converting an arbitrary executable into a batch file that performs the same task, that's much more difficult. Unless you have the source code or a very good specification on how the executable works, you're going to have a lot of trouble.
Automating the conversion for anything but the simplest executable will be insanely difficult.
And, if you want a link to a batch file that runs your executable, just create the batch file (say in c:\bin\pax.cmd) containing:
#echo off
c:\bin\pax.exe
and then create a shortcut to it from wherever you want (such as the desktop). You could even put the batch file itself in your desktop directory but I'm not a big fan of that. However, to each their own.

Resources