batch file nerds... need help. I'm a little rusty

ok, I havent done this since I was like 15 but need this done for work.

what I’m trying to do is create a batch file that’ll take a file, rename it to something else, then run an EXE, then once the EXE is closed, rename said file back to what it was originally.

what I have so far is

@echo on
ren m:\batch est1.txt test2.txt
start C:\Program files\UGS\NX 3.0\UGII\ugraf.exe
ren m:\batch est2.txt test1.txt

it renames said files ok without any problems, but it doesnt want to run ugraf.exe. I remember back when I used to do this, windows at the time didn’t support long file names, so I’d have to use below instead for Program Files

@echo on
ren m:\batch est1.txt test2.txt
start C:\Progra~1\UGS\NX 3.0\UGII\ugraf.exe
ren m:\batch est2.txt test1.txt

this didn’t seem to work either… keeps telling me that

“windows cannot find *. Make sure you typed the name correctly, and then try again. To search for a file, click the start button, and then click search”

I’m 100% sure that this is where the exe is located. Am I missing something? Is it because of the 3.0 in the folder names?

also, This is going to have to change a file that’s in the c:\windows folder which none of our users have access to modify. I assume, under my admin account, I can just set the permissions for users to access this folder? or even better, can I just set the file to let users modify it?

you dont need to use “start”
your machine is trying to run a program named “start”

are you copying exactly what the tab completion gives you?

[quote=“Zer0DazE,post:2,topic:27718"”]

you dont need to use “start”
your machine is trying to run a program named “start”

[/quote]

you sure?

@echo off
start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe

just an example… I’m not good with batch at all… but it seems like its missing something

http://www.ss64.com/nt/start.html

maybe thats helpfull…

An A-Z Index of Windows CMD commands - SS64.com

[quote=“Zer0DazE,post:2,topic:27718"”]

you dont need to use “start”
your machine is trying to run a program named “start”

[/quote]

that’s how I first had it, then upon a google search it was reccomended adding “start” (it just tells the computer that you want to start a windows executible). Either way, it gives me the same error

are you copying exactly what the tab completion gives you?

no that was from the actual batch file I saved

here is what the actual screen reads

its because there is a space in the command line without a quote

and you are right, use start

yea its stopping at
x the space is the problem it seems

try start “path”

or just running it right in the directory :slight_smile:

should I just use a “*” or “?” for this instance? or some other kind of wildcard

thanks for the help too guys, much appreciated :beer:

what would you need a wildcard for? are you trying to run everything?

“filepath” should be fine… in my inexperienced batch syntax opinion…

things like this … make me love perl soo much more

I forgot how I used to do it, but I remember back when I used to have to setup the ol autoexec.bat there was a command to set filepaths into memory so you didn’t need to psysically NEED to be in that directory to launch the command.

I figure I could do that to the c:\progra~1\UGS folder and then just go “START Ugraf.exe”

anyone know what I’m talking about? lol

Wrap C:\Program files\UGS\NX 3.0\UGII\ugraf.exe in quotes.

IE…

ren m:\batch est1.txt test2.txt
start “C:\Program files\UGS\NX 3.0\UGII\ugraf.exe”
ren m:\batch est2.txt test1.txt

It will work. I do this all the time to syncshell the winzip command line program to make encrypted data backups. The only thing I’m not sure about is if your batch file will wait for ugraf.exe to complete execution before moving to the next line. You may have to add a pause in there.

we’ve told him to do this… and no response if it works or not

oh, sorry bout that… didn’t even see it.

ok, tried that and it stopped giving me the error, but instead of launching the app, it’s just launching another instance of CMD.EXE

:\

Remove the word start.

[quote=“JayS,post:15,topic:27718"”]

Remove the word start.

[/quote]

perfect :tup: thanks again guys

edit: now to remember how to use wildcards and variables :stuck_out_tongue: need this to be able to rename 2 different files based upon a users keystroke

wish me luck lol

Heh… I just tried this, copying notepad.exe to c:\program files
ote pad
otep.exe:

ren c:\batch est1.txt test2.txt
“c:\program files
ote pad
otep.exe”
ren c:\batch est2.txt test1.txt

And sure enough, the batch file does pause until I close notepad. While notepad is open, the txt file is “test2.txt”. As soon as I close it the batch file renames it “test1.txt”.

thats good to know… maybe I should have it launch an independant batch file opposed to just the one in case the batch is closed before the program is (so to prevent something goofy happening as the file I’m renaming is an INI in the windows folder depending on which version of said software the user is launching)

lol I’m having flashbacks to christmas of 95 when I got my first q-basic book :smiley:

lol i remember being one of those assholes making batch files to fuck with others…

lol same… used to fuck with the librarians computers in school :stuck_out_tongue:

REM CADRA SELECT MENU
@echo off

cls

ECHO CADRA v10.4.0/CADRA 2006 PLUS SELECT MENU
ECHO *
ECHO *
ECHO VERY IMPORTANT, PLEASE DO NOT CLOSE THIS WINDOW AT ANY TIME
ECHO *
ECHO *
ECHO *

PAUSE
cls
echo Please Choose An Option
echo;
echo (1) Run CADRA v.10.0.4
echo (2) Run CADRA v2006 PLUS
echo;
set /p userinp=choose a number(1-2):
set userinp=%userinp:~0,1%
if “%userinp%”==“2” goto 20
if “%userinp%”==“1” goto 10
:10
ren m:\batch est1.txt test2.txt

“C:\Program files\UGS\NX 3.0\UGII\ugraf.exe”

ren m:\batch est2.txt test1.txt

goto end
:20
ren m:\batch\alt1.txt alt2.txt

“C:\Program files\UGS\NX 3.0\UGII\ugraf.exe”

ren m:\batch\alt2.txt alt1.txt
goto end
:end

exit

coming along nicely… supprised that the “choice” command no longer exists though

now that I have the template, just need to apply it to the real world and tweak it