[Gena01 Logo]
August 29, 2008, 01:54:46 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Tags Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Single instance check  (Read 334 times)
0 Members and 1 Guest are viewing this topic.
element
Newbie
*
Posts: 1


View Profile
« on: July 05, 2008, 05:39:50 AM »
Reply with quoteQuote

I'm on the quest to find the ultimate tiny Notepad replacement (tiny = under 100kB exe). One thing I've noticed is that all tiny Notepad replacements (metapad, SkimEdit, etc) have the same flaw: they all allow multiple instances, so you may end up editing multiple copies of the same file. Win32Pad comes the closes to my ideal, because at least it detects file changes on disk. Still... is it impossible to implement a single-instance check in an "under 100kB" editor?
Report to moderator   Logged
Roger
Newbie
*
Posts: 12


View Profile
« Reply #1 on: July 05, 2008, 01:14:35 PM »
Reply with quoteQuote

One way you can make sure that you are running only a single instance of Win32Pad.exe is to launch Win32Pad from a batch file, like below. Name the batch file something like «GoW32Pad.bat» or something even shorter like «gownpd.bat». Add the directory to the PATH or even easier locate it in the root of your drive, which means that you'll always run it like this from the command-line: \gownpd [ENT]

@echo off
tasklist|find /i /c "win32pad.exe" > nul
set INSTANCE=%errorlevel%
if "%INSTANCE%"=="0" goto already
start win32pad.exe %1
:: «%1» is the name and path of the file you want to run.
goto end
:already
echo. & echo  Win32Pad is already running somewhere.
echo. & echo  Tap spacebar to conclude this batch file.
pause>nul
:end
set INSTANCE=
exit

Sincerely,

Roger
Report to moderator   Logged
Roger
Newbie
*
Posts: 12


View Profile
« Reply #2 on: July 15, 2008, 12:40:37 PM »
Reply with quoteQuote

Dear fans of Win32Pad!

Here is a more nearly complete answer to the question how to make sure that only one instance of Win32Pad is running. The following batch file supplies the details. Beginners need not do anything of course except copy and paste the batch file text into Win32Pad, or even into NotePad if a person doesn't have Win32Pad up and running yet.

To bring up a copy of NotePad, hold down the WinKey and tap letter R. In the small window that pops up, press Delete, type in «notepad» (without quotes) and press ENTER (unless, of course the word NOTEPAD is already present for you in the run-window: in that case just tap ENTER.

After copying and pasting (and making sure that the copying did pick up the whole contents), save the file to the root directory of your drive (most conveniently a flash- or portable hard drive). Save the batch file (we suggest) under the name «GoW32Pad.bat».

Quit from Win32Pad or NotePad by holding down the ALT key and tapping F4.

Code:
@ echo off
if not exist \win32pad\win32pad.exe goto end
::
::  GoW32Pad.bat is designed to make sure that only one instance is run-
::  ning, anywhere on the operating system, of the program Win32Pad.exe .
::
::  GoW32Pad assumes you've installed Win32Pad.exe to N:\Win32Pad folder.
::  «\» means «root directory» and «N:» is the drive letter of the drive.
::  «Win32Pad» in «N:\Win32Pad» means the «Win32Pad» folder on the drive.
::  Modify if not line and start line to show correct path for YOUR case.
::  Whatever follows the initial «N:\» (if anything) is named the «path».
::  The goto end command will of course terminate this bat-file abruptly
::  if win32pad.exe isn't located in the N:\Win32Pad directory specified.
::
tasklist|find /i /c "win32pad.exe" > nul
::
:: «tasklist» is a function native to Windows (probably from Win2000 on).
::  It doesn't need a prefix for path to it. Type tasklist at any prompt
::  to see how it lists what is currently running on your Windows system.
::
::  Here, we pipe the list into find, where /i and /c mean «case insensi-
::  tive» and «count». If win32pad.exe is already running, find will say
::  so. The «> nul» masks what would otherwise be screen chatter that we
::  don't need. The set INSTANCE line captures the yes|no 0|1 errorlevel
::  («yes» is usually 1, but not in the case of %errorlevel% output with
::  MSoft's cmd.exe = formerly command.com). Goto already in case of «0».
::  %errorlevel% is a hidden feature that shows only if we make it do so
::  as we have here: by setting it = to a temporary environment variable.
::
set INSTANCE=%errorlevel%
if "%INSTANCE%"=="0" goto already
start \Win32Pad\win32pad.exe %1
::
::  «%1» is the name in batch-talk of the file you want to run or create.
::  GoW32Pad.bat WILL run Win32Pad.exe without a somename.ext, but we do
::  not recommend it because File, SaveAs won't be cued to the directory
::  from which you had run GoW32Pad.bat. If, however, you do supply file-
::  name: File, Save As WILL be cued up to exactly the current directory.
::  Current directory means the directory whose prompt you are typing at.
::  If creating a new file, W32Pd will ask if that's what you want to do.
::  The ask window is already cued up to Yes, so all you do is tap ENTER.
::  The typing area inside Win32Pad will of course be empty:  get typing!
::
::  Run this batch file from the directory prompt where an existing file
::  is found OR where you want to create a new file. The syntax reads --
::
::  N:\Some_Directory>\goW32Pad somename.ext [ENT] -- Where GoW32Pad.bat
::  is assumed to dwell in the root directory of your drive named by «N:»
::  Be sure to include the backslash \ in front of goW32Pad somename.ext.
::  Notice how, in the start command above, we likewise supply backslash.
::  We purposely don't supply drive-letter N: since it varies by host PC.
::  On any host where you take your flash-drive a backslash will suffice.
::
goto end
::
:already
echo. & echo  Win32Pad is already running somewhere.
echo. & echo  Tap [spacebar] to end this batch file.
echo.
pause>nul
:end
set INSTANCE=
exit

To summarize: by running Win32Pad by means of the batch file above, only a single instance is allowed of Win32Pad anywhere on the host PC or workstation. Instead of the Win32Pad developers taking the time to build in this single-instance feature, the developers are able to turn their attention to whatever next version they may have time to provide.

mit herzlichem Gruß,

Roger

«Es macht keinen Sinn, daß die Kühe Milch geben —
 Die Bauern nehmen sie ihnen einfach weg.»
Report to moderator   Logged
Steve
Guest
« Reply #3 on: August 23, 2008, 10:00:22 PM »
Reply with quoteQuote

tasklist.exe does not come on XP Home.  And the download I got from MS did not produce the output expected at the DOS prompt.  So there was nothing to "find".

Where to get the version of tasklist.exe you used to make this BAT file?
Report to moderator   Logged
Tags:
Pages: [1]
  Reply  |  Print  
 
Jump to:  

BoldItalicizedUnderlineStrikethrough|GlowShadowMarquee|Preformatted TextLeft AlignCenteredRight Align|Horizontal Rule|Font SizeFont Face
Insert FlashInsert ImageInsert HyperlinkInsert EmailInsert FTP Link|Insert TableInsert Table RowInsert Table Column|SuperscriptSubscriptTeletype|Insert CodeInsert Quote|Insert List
Smiley Wink Cheesy Grin Angry Sad Shocked Cool Huh Roll Eyes Tongue Embarrassed Lips sealed Undecided Kiss Cry
Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.039 seconds with 19 queries.