HELP with batch file.

Forum for anything else which doesn't fit in the above forums. Site feedback, random talk, whatever, are welcome.
Post Reply
User avatar
pg.manq
Posts: 48
Joined: Thu Jul 19, 2007 1:55 pm

HELP with batch file.

Post by pg.manq » Mon Nov 10, 2008 6:54 pm

Hi, i need help with a batch file thats to run from the CD, initiated by WPI. Im a nOOb at making batch files. Thought I'd be able to figure it out.. but... no success.

Requirements
1. Copy Folder APPDIR with contents from CD to %ProgramFiles% <----- Main Files
2. Copy Folder System with contents (that includes a folder APPNAME) from CD to %ALLUSERSPROFILE%\Start Menu\Programs <----- Shortcuts
3. Run the app thats now in %ProgramFiles%\APPNAME Application.exe <----- The app is self contained ie. a single file. It only needs to be run from its final location, and itll register to Add/Remove.
4. terminate the app <----- can use taskkill

And thats it.


This is what I have till now

Code: Select all

@ECHO

REM ----- Copying Folders
[color=red]REM ----- No Problems with Copying Anymore[/color]
XCOPY AppDir %ProgramFiles%\[color=yellow]AppDir[/color] /i
XCOPY System\* %ALLUSERSPROFILE%\Start Menu\Programs\[color=yellow]System[/color] /s /i
[color=red]REM ----- No Problems with Copying Anymore[/color]


REM ----- Installing the App

CD %ProgramFiles%\AppDir
App.exe
taskkill /f /IM App.exe

EXIT
Figured out the problem with the XCOPY... need the final folder name at the end too it seems.

Cant seem to spawn an app and then taskkill it as well, from the same script. Same result with notepad too... anybody know why this happens???

Appreciate all the help.

EDIT: Solved with using Start without the /wait

Code: Select all

start notepad.exe 
taskkill /f /im notepad.exe
Thanks to Yumeyao, ENU n Kel. :)
Last edited by pg.manq on Tue Nov 11, 2008 1:14 pm, edited 2 times in total.

yumeyao
Moderator
Posts: 1718
Joined: Sun Aug 27, 2006 9:24 pm
Location: Taiyuan, Shanxi, PR China

Post by yumeyao » Mon Nov 10, 2008 7:25 pm

1. xcopy - /s is needed always when you want to copy a whole directory.
2. simply modify it to start /parameter "%programfiles%\appdir\app.exe", quotation is needed if spaces exist in the path.
the parameter is something like nowait, i just can't remember what exactly it is. type start/? to find it out.
if you don't want the 4th step to be executed before the app in 3rd step finishes, you don't need that parameter.

btw, it's much easier to do the job with a self-extracter.
Image
My work list(Hosted by dumpydooby)

User avatar
pg.manq
Posts: 48
Joined: Thu Jul 19, 2007 1:55 pm

Post by pg.manq » Mon Nov 10, 2008 7:36 pm

yumeyao wrote:1. xcopy - /s is needed always when you want to copy a whole directory.
2. simply modify it to start /parameter "%programfiles%\appdir\app.exe", quotation is needed if spaces exist in the path.
the parameter is something like nowait, i just can't remember what exactly it is. type start/? to find it out.
if you don't want the 4th step to be executed before the app in 3rd step finishes, you don't need that parameter.

btw, it's much easier to do the job with a self-extracter.
Thanks yumeyao. Start /wait is what u were refering to I presume.
And the xcopy - /s isnt required if its just ONE directory with FILES ONLY. Its required if the folder contains SUBFOLDERS that u want to copy.

Its copying fine now... the problem Now is that once the app starts its not possible to taskkill it. Even with the use of Start /wait.

Try

Code: Select all

REM Starts and then Kills Notepad ... Hopefully 

start /wait Notepad.exe
taskkill /f /IM Notepad.exe

Pause
Thanks again.

[Edit] I havent figured out how to make a True addon yet. guess using .inf is easier. But then im in the last leg. Need to open and close an app. :rolleyes:
Last edited by pg.manq on Mon Nov 10, 2008 8:00 pm, edited 1 time in total.

yumeyao
Moderator
Posts: 1718
Joined: Sun Aug 27, 2006 9:24 pm
Location: Taiyuan, Shanxi, PR China

Post by yumeyao » Mon Nov 10, 2008 7:52 pm

so.. do you want to start and close the same app?
and it seems /wait is not needed, i referred to /nowait...
could you give me an detailed instruction?

if the app can close itself after it finishes, you do not need to use taskkill.
if it cannot close itself, how do you ensure you taskkill it after it works functionally?
Image
My work list(Hosted by dumpydooby)

User avatar
pg.manq
Posts: 48
Joined: Thu Jul 19, 2007 1:55 pm

Post by pg.manq » Mon Nov 10, 2008 8:12 pm

yumeyao wrote:so.. do you want to start and close the same app?
and it seems /wait is not needed, i referred to /nowait...
could you give me an detailed instruction?

if the app can close itself after it finishes, you do not need to use taskkill.
if it cannot close itself, how do you ensure you taskkill it after it works functionally?
What the App does is that it Registers itself the first time it runs.
It does that automatically. No user interference required.
Doesnt do anything else. And it doesnt have a automatic feature to close itself. I intend to Install it along with the rest of my WPI addons on First Run.
And in this case install means OPENing the app and Closing it so that i can proceed with the rest of the installations.

I can get it to start up. But cant shut it down. (Oh, it does shutdown with taskkill but not from a command from the same bat file)
REF the notepad example. How can one overcome that problem?

If i were to do it manually this is wat happens
1. Double click on app icon
2. App GUI pops up - Registering itself in the background. Though i have no way of visually knowing that except checking Add/Remove at this point.
3. Win+R [Run] taskkill /f /IM app.exe <----- And it shuts down neatly.

Alternatively i could just wait for the user to use the app to register it when they run it first time.
Or regshot wat it adds to the registry and add it myself.

Hoping for a solution to the Bat file problem itself. Unless its a limitation.
Thanks again

User avatar
pg.manq
Posts: 48
Joined: Thu Jul 19, 2007 1:55 pm

Post by pg.manq » Mon Nov 10, 2008 8:40 pm

Ok i did it the registry way. So the apps installed. :D

Now the persuit would be purely academic to figure out how to Open and close an app, Notepad, from the same bat File.

Thanks so much Yume Yao.

User avatar
ENU_user
Posts: 1253
Joined: Wed Jan 25, 2006 1:42 pm

Post by ENU_user » Mon Nov 10, 2008 9:25 pm

Simply add start before app.exe

make sure to remove the "taskkil" line before you go on ;)
Last edited by ENU_user on Mon Nov 10, 2008 11:17 pm, edited 1 time in total.

User avatar
Kelsenellenelvian
Moderator
Posts: 4383
Joined: Tue Nov 30, 2004 8:32 pm
Location: Pocatello, ID
Contact:

Post by Kelsenellenelvian » Mon Nov 10, 2008 10:05 pm

and then depending on which you are using (Home or Pro)

You use = tskill notepad
Or use = taskkill /I /M notepad.exe

to close it out

yumeyao
Moderator
Posts: 1718
Joined: Sun Aug 27, 2006 9:24 pm
Location: Taiyuan, Shanxi, PR China

Post by yumeyao » Tue Nov 11, 2008 1:43 am

WFM..

Code: Select all

start notepad.exe
taskkill /f /im notepad.exe
Image
My work list(Hosted by dumpydooby)

User avatar
Kelsenellenelvian
Moderator
Posts: 4383
Joined: Tue Nov 30, 2004 8:32 pm
Location: Pocatello, ID
Contact:

Post by Kelsenellenelvian » Tue Nov 11, 2008 2:01 am

Damn I had my syntax wrong.

Sorry :(

User avatar
pg.manq
Posts: 48
Joined: Thu Jul 19, 2007 1:55 pm

Post by pg.manq » Tue Nov 11, 2008 1:06 pm

Excellent. :D Thank u very much guys.
Just using start worked great ENU.

Post Reply