Page 1 of 1

Do not open notepad if notepad is already open

Posted: Thu Aug 02, 2012 2:30 pm
by Darren
Can anybody help?

I have the following code...

Dim TextFile As String

TextFile = "C:Documents and SettingsdsmithDesktopMechTools Project FilesThings To do.txt"

Shell ("C:WindowsNotePad.exe", Chr$(34) + TextFile + Chr$(34), Sw_ShowNormal)

Everything works OK

But If I run it with NotePad.exe already running it opens another instance of NotePad.exe.

How can I prevent it from opening up another instance of NotePad.exe
rather than just opening up the text file.

Many thanks in advance!!!

Do not open notepad if notepad is already open

Posted: Sun Aug 19, 2012 8:15 pm
by Marco
Here `s somthing you can use for it.
best regards

declare check as "WaitForSingleObject" of "kernel32.dll"
  hhandle as integer
  dwmilliseconds as integer
  result as integer
end declare

``get windows folder
dim winfolder as string
Declare getwindir as "GetWindowsDirectoryA" of "kernel32"
  lpBuffer As String byaddress
  nSize As integer
end declare
getwindir.lpbuffer=space$(256)
getwindir.nsize=256
getwindir.execute
winfolder=rtrim$(getwindir.lpbuffer)+""

``testform
object testform as form
  object npad as button
    caption="open notepad"
    onclick=npad_onclick
  end object
  showmodal
end object

sub npad_onclick
  ``check if application is running
  dim pid as integer
  check.hhandle=pid
  check.execute
  if check.result > 0 then
    showmessage "notepad already running"
    exit sub
  end if
  pid=shell(winfolder+"notepad.exe")
end sub

Do not open notepad if notepad is already open

Posted: Mon Aug 20, 2012 2:39 pm
by cvirus
It works very good :D

Do not open notepad if notepad is already open

Posted: Mon Aug 20, 2012 2:42 pm
by cvirus
If you can do this you also can put focus on the notepad or whatever prgram you run right?
;D

this is the API, i think this is the one

declare focus as "SetFocus"  of "User32"
  hhandle as integer byadress
  result as integer
end declare

Do not open notepad if notepad is already open

Posted: Mon Aug 20, 2012 3:04 pm
by Marco
busy with that because you need a window handle for that and whe have a process handle.

best regards

Do not open notepad if notepad is already open

Posted: Mon Aug 20, 2012 4:57 pm
by cvirus
[quote author=6461686C6B050 link=1343917838/4#4 date=1345475067]busy with that because you need a window handle for that and whe have a process handle.

best regards[/quote]


Sorry Admin i didn?t understood, isn`t possible at the moment?

Do not open notepad if notepad is already open

Posted: Tue Aug 21, 2012 3:13 pm
by Marco
I think it is somehow possible but i did not find the solution yet.
best regards