Computer Hope
Software => Computer programming => Topic started by: KCuHCeht on April 01, 2011, 12:47:27 PM
-
Hi, I'm fairly new with batch files and the syntax, but understand the logic of programming for the most part. I have 2 programs at work that both use pervasive databases, but they use different versions, Primavera P3 and Timberline Accounting. If one of the programs are running, i must close it and the database before i can open the other, and I would like to create a batch file that will do this for me instead of doing it manually. So here is effectively what i need it to do:
\\This would be the batch file to open Primavera P3
If (tasklist contains "w3dbsmgr.exe") then
Start "C:\Program Files\Pervasive Software\PSQL\bin\pvkillwg.exe"
End If
Start "C:\P3WIN\P3PROGS\P3.exe" /user:chuck
Exit
If someone could help me figure out the correct syntax to make this work, I believe I could figure out the other one.
Thanks,
Chuck
-
Something along these lines shoud do it...
tasklist | find "w3dbsmgr.exe" && Start "C:\Program Files\Pervasive Software\PSQL\bin\pvkillwg.exe"
Start "C:\P3WIN\P3PROGS\P3.exe" /user:chuck
-
it's not running the pvkillwg.exe file, the command window opens up with "C:\Program Files\Pervasive Software\PSQL\bin\pvkillwg.exe" in the title bar, and it doesn't appear that it is getting to the point to run P3.
-
Try using the start "" "program.exe" syntax
tasklist | find "w3dbsmgr.exe" && Start "" "C:\Program Files\Pervasive Software\PSQL\bin\pvkillwg.exe"
Start "" "C:\P3WIN\P3PROGS\P3.exe" /user:chuck
-
Awesome. Thanks. That works like a charm. Now not that it is important, but is there any way to hide the command windows from showing up at all?
-
is there any way to hide the command windows from showing up at all?
try adding the /MIN switch after Start and before the ""
Start /MIN "" "program"
By the way, the && thing can be given a multiline structure if you prefer
tasklist | find "w3dbsmgr.exe" && (
Start "" "C:\Program Files\Pervasive Software\PSQL\bin\pvkillwg.exe"
)
Start "" "C:\P3WIN\P3PROGS\P3.exe" /user:chuck
The way it works is this: these two symbol pairs && and || have a specific meaning in post-Windows 2000 batch scripts:
&& tests for zero errorlevel so
command1 && command2 means "carry out command1 and if the errorlevel returned is zero, carry out command2"
and this...
command1 && (
command2
command3
command4
)
...means "carry out command1 and if the errorlevel returned is zero, carry out command2, command3 and command4"
Using the || symbol pair reverses the test so that a nonzero errorlevel is the trigger.
-
This would be the other program, i dont think the taskkill is working
tasklist | find "w32mkde.exe" && taskkill /f /im "w32mkde.exe"
start "" "C:\Program Files\Pervasive Software\PSQL\bin\w3dbsmgr.exe"
start "" "C:\Program Files\Timberline Office\Accounting\IA.exe"
-
Thanks for explaining that. I like knowing how/why things work. Any help on the taskkill would be greatly appreciated as well :)
-
OK, I've got everything working (almost), thanks to your help. Here are my final batch files for anyone looking for something similar.
tasklist | find "W32MKDE.EXE" && (
start /MIN "" "C:\Windows\System32\taskkill.exe" /f /im "W32MKDE.EXE"
)
tasklist | find "W32MKDE.EXE" || (
start /MIN "" "C:\Program Files\Pervasive Software\PSQL\bin\w3dbsmgr.exe"
)
start "" "C:\Program Files\Timberline Office\Accounting\IA.exe"
and...
tasklist | find "w3dbsmgr.exe" && (
Start /MIN "" "C:\Program Files\Pervasive Software\PSQL\bin\pvkillwg.exe"
)
tasklist | find "w3dbsmgr.exe" || (
start "" "C:\P3WIN\P3PROGS\P3.exe" /user:chuck
)
Now, one final tweak and it will be "perfect" I want to add a "Start in:" directory similar to what you can do in shortcut properties (see attached). The directory would be on a server so it would be in the format of "\\server\etc\etc\etc"
Thanks again.
[recovering disk space - old attachment deleted by admin]
-
Add /D server_path to the Start command
-
Where in the start command?
I've tried this:
start "" "C:\Program Files\Timberline Office\Accounting\IA.exe" /D "\\server2\system\tsgold\lantz\"
and this:
start "" "C:\Program Files\Timberline Office\Accounting\IA.exe" /D \\server2\system\tsgold\lantz\
Thanks.
-
start "" /D \\server2\system\tsgold\lantz\ "C:\Program Files\Timberline Office\Accounting\IA.exe"
-
Wonderful. Thanks a lot for everyone's help. It is working like a charm.
-
btw the syntax for if is
if a==b command
just that
-
btw the syntax for if is
if a==b command
just that
This isn't what was being asked.
-
i know i just wanted to point that out
-
i know i just wanted to point that out
You could also mention that the sky is blue and that the sun goes away at night.