Re: Problem when executing application from batch file
- From: "Ralph" <nt_consulting64@xxxxxxxxx>
- Date: Wed, 5 Oct 2005 06:23:46 -0500
"Someone" <nobody@xxxxxxx> wrote in message
news:jMK0f.349$MN6.128@xxxxxxxxxxxxx
> Some people have mentioned that if the user started multiple copies of the
> App almost simoultenously, PrevInstance will not return the correct
> information. Maybe you are witnessing that. The solution is to use a
Mutex,
> however, you could have problems with terminal servers because a Mutex is
> usually system wide, while PrevInstance is session wide. If you use a
fixed
> global Mutex string, only 1 copy of your App will run per computer.
Usually
> you could use "Local\" prefix to avoid this problem, but it seems that
it's
> not supported in NT 4.0 according to CreateMutex() function.
>
> To support NT4, you could create a global mutex, like "MyApp-1", which
> includes your App's EXE name and the session ID returned by
> ProcessIdToSessionId() API function. You will need to check the OS version
> since this function requires NT4+SP4 and above.
>
> Look for "vb CreateMutex" in newsgroups for samples.
>
> Obtaining Windows' Version Information
> http://vbnet.mvps.org/index.html?code/system/getversionex.htm
>
>
>
> "Someone" <nobody@xxxxxxx> wrote in message
> news:hgI0f.320$MN6.220@xxxxxxxxxxxxx
> >> Only the first batch line is executed when my app is not running
> >
> > I can't see your code, so I can only speculate. I think that your app
> > maybe executing 4 times, but your the logic that checks for PrevInstance
> > maybe terminating the App without further processing. There maybe
> > something you have overlooked. Again, I can't see your code. To be sure
> > whether your App runs once or 4 times, use a message box at the very
> > begging of Main. Example:
> >
> > MsgBox "Main called, PrevInstance = " & App.PrevInstance
> >
> > If you see 4 copies of the MsgBox, then the batch file is executing as
> > expected and you could go to the next step...
> >
> >
> > "Jack" <replyto@newsgroup> wrote in message
> > news:%23YcBf9VyFHA.3812@xxxxxxxxxxxxxxxxxxxxxxx
> >>I appreciate your help.
> >> We are close but not close enough.
> >> My batch file has 4 lines.
> >> Only the first batch line is executed when my app is not running, but
> >> command prompt widow shows all batch lines processed(?)
> >> At least there is not any error indication and there is not any
> >> interruption in batch processing.
> >> Jack
> >> "Someone" <nobody@xxxxxxx> wrote in message
> >> news:iFH0f.314$MN6.228@xxxxxxxxxxxxx
> >>> Use this instead:
> >>>
> >>> start "MyTitle" "<path>test.exe" /55512340453
> >>>
> >>> When "start" sees the first quote, it treats it as a window title.
> >>> Apparently this is only supported in XP and most likely Windows 2000.
> >>> Windows 9x does not support the title option. If you use quotes around
> >>> the path and don't include any option, then you have to use the title
> >>> option as well. Here are some valid examples:
> >>>
> >>> start "" "<path>test.exe" /55512340453
> >>> start /i "<path>test.exe" /55512340453
> >>> start /normal "<path>test.exe" /55512340453
> >>>
> >>> Here is what Windows 95/98 show:
> >>>
> >>> Runs a Windows program or MS-DOS program.
> >>>
> >>> START [options] program [arg...]
> >>> START [options] document.ext
> >>>
> >>> /m[inimized] Run the new program minimized (in the background).
> >>> /max[imized] Run the new program maximized (in the background).
> >>> /r[estored] Run the new program restored (in the foreground).
> >>> [default]
> >>> /w[ait] Does not return until the other program exits.
> >>>
> >>>
> >>>
> >>>
> >>> "Jack" <replyto@newsgroup> wrote in message
> >>> news:eCNTxkVyFHA.2212@xxxxxxxxxxxxxxxxxxxxxxx
> >>>>I tried your suggestion.
> >>>> When I used start followed by file name followed by traling parameter
> >>>> Windows complain about that trailing parameter.
> >>>> my line looks like that:
> >>>> start "<path>test.exe" /55512340453
> >>>> Jack
> >>>>
> >>>> "Someone" <nobody@xxxxxxx> wrote in message
> >>>> news:b0H0f.304$MN6.236@xxxxxxxxxxxxx
> >>>>> To force the batch file to not wait for your app and return
> >>>>> immediately, use "start" without the /wait option. For example, I
made
> >>>>> a test.bat with the following:
> >>>>>
> >>>>> project1
> >>>>> project1
> >>>>> project1
> >>>>>
> >>>>> This executed 1 copy at a time, each taking 10 seconds to run
because
> >>>>> the loop I had in Main. When I changed the batch file to the
> >>>>> following:
> >>>>>
> >>>>> start Project1
> >>>>> start Project1
> >>>>> start Project1
> >>>>>
> >>>>> The 3 copies were executed almost simultaneously, and 3 Project1.exe
> >>>>> appeared in Task Manager each using about %33 of CPU time. The
prompt
> >>>>> returned immediately before they finished executing.
> >>>>>
> >>>>> Using "start" this way insures consistent behavior if your OS
happens
> >>>>> to behave differently.
> >>>>>
> >>>>>
> >>>>>
> >>>>> "Jack" <replyto@newsgroup> wrote in message
> >>>>> news:eBfB3EVyFHA.3312@xxxxxxxxxxxxxxxxxxxxxxx
> >>>>>>I am confused about your suggestion.
> >>>>>> My app primary task is not accepting commands from the batch file.
> >>>>>> It is a big, universal app, and one of the added (on request)
> >>>>>> features is to accept commands from a batch file.
> >>>>>> When commands are incoming my app is not smart enough to know
whether
> >>>>>> it is a single command from command prompt or it is part of batch
> >>>>>> file execution. As a consequence of that I cannot just ignore
> >>>>>> checking for previous instance. I have to do that to avoid multiple
> >>>>>> instances.
> >>>>>> Hope it clears up a little.
> >>>>>> Jack
> >>>>>> "Someone" <nobody@xxxxxxx> wrote in message
> >>>>>> news:iaG0f.292$MN6.75@xxxxxxxxxxxxx
> >>>>>>> It appears that outside a batch file, i.e., in Command Prompt, the
> >>>>>>> app is started and you are returned to the "C:\" prompt
immediately.
> >>>>>>> In a batch file it waits for the App to finish before going to the
> >>>>>>> next line, so checking for previous instance is not necessary. If
> >>>>>>> you are at Command Prompt and wanted to type the EXE name and wait
> >>>>>>> till the program finishes, use:
> >>>>>>>
> >>>>>>> start /wait yourapp /para1 /para2...
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> "DanS" <t.h.i.s.n.t.h.a.t@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
> >>>>>>> news:Xns96E5DB32A2E19idispcom@xxxxxxxxxxxxxxxxx
> >>>>>>>> "Jack" <replyto@newsgroup> wrote in
> >>>>>>>> news:evhDSZUyFHA.464@xxxxxxxxxxxxxxxxxxxx:
> >>>>>>>>
> >>>>>>>>> I do not understand and maybe someone please can explain to why,
> >>>>>>>>> after
> >>>>>>>>> executing the first line of the batch file the batch execution
> >>>>>>>>> stops
> >>>>>>>>> until I close my application.
> >>>>>>>>> What kind of mechanism is that?
> >>>>>>>>> sample of batch file:
> >>>>>>>>> [].exe /5553331234
> >>>>>>>>> [].exe /5556770808
> >>>>>>>>> [].exe /5553451234
> >>>>>>>>>
> >>>>>>>>> That happens only if there is not previous instance running.
> >>>>>>>>> I can see batch execution in CMD window. I can see the first
batch
> >>>>>>>>> line being executed and then nothing. I close my app and then
> >>>>>>>>> second
> >>>>>>>>> line of batch file appears and my app is alive again. I close my
> >>>>>>>>> app
> >>>>>>>>> and then the third line of batch file will appear.
> >>>>>>>>> If I understand the mechanism of that behaviour maybe I can
patch
> >>>>>>>>> over
> >>>>>>>>> that problem
> >>>>>>>>> Jack
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>> Is that 3 seperate lines in the batch file ?
> >>>>>>>>
> >>>>>>>> In the OP, I thought by accept multiple command line params I
> >>>>>>>> thought you
> >>>>>>>> meant like: program.exe /param1 /param2 /param3
> >>>>>>>>
> >>>>>>>> The batch file acts exactly as it was intended. It runs the first
> >>>>>>>> line,
> >>>>>>>> waits until that program ends, then runs the next line.
> >>>>>>>>
> >>>>>>>> I would have written the command$ handler to parse the string and
> >>>>>>>> look for
> >>>>>>>> multiple params, which is what I thought you did, and you
wouldn't
> >>>>>>>> have had
> >>>>>>>> this issue.
> >>>>>>>>
> >>>>>>>> Regards,
> >>>>>>>>
> >>>>>>>> DanS
> >>>>>>>>
Another easy way to manage a TS Mutex is to call GetUser and affix the user
name to the created Mutex.
Also third party TSs often allow configurations to insure single instances
for "published" apps.
-ralph
.
- Follow-Ups:
- Re: Problem when executing application from batch file
- From: Someone
- Re: Problem when executing application from batch file
- References:
- Problem when executing application from batch file
- From: Jack
- Re: Problem when executing application from batch file
- From: Jack
- Re: Problem when executing application from batch file
- From: DanS
- Re: Problem when executing application from batch file
- From: Someone
- Re: Problem when executing application from batch file
- From: Someone
- Re: Problem when executing application from batch file
- From: Jack
- Re: Problem when executing application from batch file
- From: Someone
- Re: Problem when executing application from batch file
- From: Jack
- Re: Problem when executing application from batch file
- From: Someone
- Re: Problem when executing application from batch file
- From: Someone
- Problem when executing application from batch file
- Prev by Date: Re: a question about moving pictures
- Next by Date: Re: Variable changes
- Previous by thread: Re: Problem when executing application from batch file
- Next by thread: Re: Problem when executing application from batch file
- Index(es):
Relevant Pages
|