Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open program and close batch file window? 4

Status
Not open for further replies.

psemianonymous

Programmer
Dec 2, 2002
1,877
0
0
US
I am trying to open an instance of MSACCESS via a batch file, and it works acceptably. However, there is one part I want to tweak: after opening the database, I want the batch window to close/hide itself. Here is a similar thread I found on Google Groups--this is exactly what I'm trying to do:



Let me clarify:
1. I can't use a shortcut, because I need to run some commands in the batch file (i.e. IF EXIST FILENAME). The programming checks can be moved to another Access database, eliminating the batch file altogether, but this will be overkill, especially on my low-end user machines. So I would really like to use a batch file.
2. I just want to get rid of the batch window. I don't care if the batch file itself remains open but hidden; I just want it gone from sight (and mind).
3. I have set a shortcut to the batch file, and set it to run "Minimized", but this hasn't worked.
4. What happened to PIF files? Is that a Windows 95/98/Me only thing?
5. I will be using this with users in Windows NT 4.0 and 2000. So please no 2000-only workarounds.
 
Addendum: full points for the window to disappear entirely. Half credit if the window minimizes, but remains on the taskbar.
 
foolio12,

here's a thought:

in notepad or edit, try editing your .cmd file as follows:

cmd /c
"C:\Program Files\Microsoft Office\Office\msaccess.exe"
/wrkgrp \\pedscdcnt\databases\common\system.mdw
"c:\program files\arhms\ARHMS_client.mdb"

Does that change the behavior any?

-thefourthwall
 
No dice. CMD /C still waits until the program closes to "move on".


For all interested, here is my batch file in full:

Code:
if not exist "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" SET ACCESSEXE="C:\Program Files\MSOffice\Office\MSACCESS.EXE"
if exist "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" set ACCESSEXE="C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"

if not exist "C:\Program Files\Requests DB\requests_version1.00.txt" goto installer



%ACCESSEXE% "C:\Program Files\Requests DB\requests_standard_fe.mdb" /wrkgrp "u:\requests.mdw"
goto end


:installer
%ACCESSEXE% "u:\requests_update.mdb" /X update

:end
 
foolio12,

Try this as a quick fix. Create a SC to your batch file. Then go to Properties / Layout and change Screen & Window Size to 1 and Position to -1. Untick "let system .."

Your DOS window will go to the TaskBar only.

The MSOffice apps (for one) don't follow the "old" rules, since you should be able to write:-

if ....
do this
app name
exit

which launches app and closes the window

Ian

P.S. Pif's are still around. Copy _default.pif from
%winnt%
P.P.S
I've always found putting an exit statement as a last line is a good idea


 
foolio12,

Taking this one step further, you may want to try this also.

Given that mdb is associated to Access, you should be able to launch it using :-

start "path to file only.mdb" etc.
exit

I just tried it using a test db, with the window closing behind itself. That would save mucking with a SC

Ian
 
The 'documented' trick for doing that is to put a CLS command in the last line of the batch-file.

HTH
TonHu
 
You could use a VBScript to do the updating ... Ben O'Hara has a little something-something on here that I'm sure, with a little modification, would suit you perfectly. Only thing you have to watch for is virus software - it'll stop this script in it's tracks until you authorize it.

I found another thread for you also: thread707-550968 - it should give you a good idea where to go from there.

HTH

Greg

Boss quote from an office meeting: We're going to continue to have these meetings until we figure out why no work is getting done ...
 
After months of moving on, I randomly found the answer that was already in use by my sysadmin! The application is published as a Citrix application and must be started by a batch file--what he has done is create a shortcut that opens the database with all the command-line parameters, then calls the shortcut with the "start" command from the batch file. Since the batch file uses the "start" command to open my database, it closes right after executing the command. Full points to myself!


Summary: use "start myshortcut.lnk" instead of opening Access directly and thus avoid any "dangling batch file window" problems. Excellent.
 
foolio12,

Now, that's worth a star on the "walk of fame" !!

Ian

Everyday the Computer Gods pick one person to be "it". Maybe, today is your day !!
 
Little late but!
This is what I use and works fine!

@CLS
@Start MSACCESS "Path to the file"
@EXIT

Works great
ScorpioX

 
Hi,

I have two DB's in which I use a batch file to open it. I had similar problems to foolio12 and the START command worked great for the first DB, but it will not work for the second. Here is is:

Code:
@ECHO OFF

C:
CD 
MKDIR Inventory_Tracking_DB
CD Inventory_Tracking_DB


IF EXIST C:\Inventory_Tracking_DB\Inventory_Tracking_DB_v2.3.mde	GOTO WORKGROUP


IF NOT EXIST C:\Inventory_Tracking_DB\Inventory_Tracking_DB_v2.3.mde DEL C:\Inventory_Tracking_DB\*.mde
COPY "G:\Adcomm\SMS\Hub Info\Inventory Tracking Database\Administrator\Inventory_Tracking_DB_v2.3.mde" /y


:WORKGROUP
IF NOT EXIST C:\Inventory_Tracking_DB\INVTRK_SEC.mdw COPY "G:\Adcomm\SMS\Hub Info\Inventory Tracking Database\Administrator\INVTRK_SEC.mdw" /y


:OPEN
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\Inventory_Tracking_DB\Inventory_Tracking_DB_v2.3.mde" /wrkgrp "C:\Inventory_Tracking_DB\INVTRK_SEC.mdw"

EXIT

It loads access but without the workgroup file so it says that I dont have permissions to open the databse. Is there a way to open access with a workgroup file and still have the batch window disappear?? Any ideas or suggestions will be greatly appreciated. (^_^)

- Jedi420

A man who has risked his life knows that careers are worthless, and a man who will not risk his career has a worthless life.
 
Well, upon further examination, I decided to not try to open the DB directly from the batch file but rather START a shortcut to the DB, just like foolio12 mentioned, and it worked awesome! Amazing all the "small" stuff you learn along the way!

-Jedi420

A man who has risked his life knows that careers are worthless, and a man who will not risk his career has a worthless life.
 
Start you're batch file with these lines:

@echo off
echo Please wait: Database is loading...


Allow the window to pop up as normal, but then use a function that runs automatically when MS Access starts up to minimize or hide the window until it closes on it's own. This is still not the prettiest way to do it, but at least there's something aesthetically pleasing to it.
Use these two functions. For lpClassName, use 0. That way the window can be of any class. For nCmdShow, use 0 for hide, or two for minimize. Don't know what the name of you're particular window is.

'This function returns the hwnd of the found window
'(That's basically just an identifier number for the window)
Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" (ByVal lpClassName As Any, _
ByVal lpWindowName As Any) As Long


'This function uses the hwnd found from the other function
'to minimize, hide, or do other things to the window. It
'all depends on the value of nCmdShow when you call it.
'Returns a 0 if it failed, a 1 if it succeeded (<--spelling)
Declare Function ShowWindow Lib &quot;user32.dll&quot; _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top