Solved

Detect that a Dos instance is running

Posted on 2000-05-02
6
249 Views
Last Modified: 2013-12-28
I need to detect that a dos program (a compiled Clipper program) is running so I can inhibit a user from loading a second instance. I have tried to do this by testing to see if a specific database file is open but this doesn't work.
0
Comment
Question by:mrl
  • 3
  • 3
6 Comments
 

Author Comment

by:mrl
ID: 2771611
I forgot to mention I'm running win98 in a 5 station Peer-to-Peer network.
0
 
LVL 3

Expert Comment

by:Dassa
ID: 2772954
If you can recompile the program you could have it set an environment variable on startup and clear it when shutdown.  Otherwise you could do the same thing by having the program started from a batch file and using the set command to control the variable.  You could use a test of the variable to decide to run the program or not.  You can do the same thing by having the batch file create a file and delete it when the program is shut down if you would be more comfortable with that idea.
0
 

Author Comment

by:mrl
ID: 2774896
Dassa
I have tried using Batch environment vars and trying to detect files open but I can still run multiple instances of the program. It's as if totally new DOS environment partitions are opened and environment vars are not shared between DOS partitions. (I am using an icon to start the program). I think I need to have win98 forced to open only one DOS environment! If I use Run/Command/name of Bat file.. method to open a dos window the environment var will work but my users want an icon and that's when I have the problem. If I am missing something please tell me.  
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 3

Expert Comment

by:Dassa
ID: 2776715
mmm...forgot about Windows running programs in DOS boxes, they each have their own environment space.  Using the file exist test would be the way to overcome this.  If you test in the batch file for the existance of a file in say c:\temp and if it exists, exit the batch file, if it doesn't create it and run your program.  After your program runs, delete the file.  That should overcome the problem.  If it is a network program, you may have to test for the file on a networked drive, so that any user with the icon (batch file startup) for the program can utilise the file test.  If you like I could do you up a sample batch file.

You could also try forcing your batch file to run in MSDOS mode.  The option is found in the properties of the icon, under Program -- Advanced.  If you wish to use the environment approach.  This should stop it from running the program in a DOS box.
0
 

Author Comment

by:mrl
ID: 2779416
Dassa
Thank you for your offer of an example file-test bat file...could I please have that? I have successfully tested doing this in one my clipper programs but I have a hundred or more of these and to recompile that many would be too costly. If I can do it with bat files it would be a lot simpler.
What actually would be the best solution is to stop the user loading the Menu that calls all my progs. This is some old compiled Basic Menu (has BRUN30 with it) that I got as freeware in 1986! It executes from a .Bat calling a (MenuMain.exe) but doesn't show up on the list of running progs in mem /c. Any ideas about inhibiting the running of this program.  Thanks for your continued help. Mal
0
 
LVL 3

Accepted Solution

by:
Dassa earned 100 total points
ID: 2779958
@Echo off
Rem Batch file to only allow one instance of a DOS program to run under Windows
Rem Above line turns off screen echo of batch commands
Echo Starting Program ...  Please wait ......
Rem We now test for the existance of the file.
Rem Be aware, if batch file illegally terminated this may need to be manually deleted.
if exist c:\temp\single.txt goto duplicate
Rem If the file doesn't exist we next create it.
copy c:\sstart.bat c:\temp\single.txt >nul
Rem Now we call the program
call c:\windows\command\edit.com
Rem Now we can delete the file (This is important)
del c:\temp\single.txt > nul
Rem We can exit now.
goto exit
Rem If program is already running post a message
:duplicate
Echo !!!!!!!!!!!!!!!!!!!!!!!!!Warning!!!!!!!!!!!!!!!!!!!!!!!!
Echo .
Echo ################## Program is already running on this system #####################
Echo ################## Program ending .... Contact Administrator #####################
:exit
Echo Program Ended  .....


This is fairly rough.  I used a copy of the batch file itself to create the test file.  You would need to change the paths appropriately etc.  Also, you will need to edit the shortcut for the batch file so that the window is closed automatically when the batch file finishes (program tab on properties).  You may want to add a pause to the :duplicate section at the end so they can see the message.

Tested this with the DOS edit program as indicated in the about text.  Works well :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question