Do not open notepad if notepad is already open

In this category you can exchange your programming questions and solutions.
Post Reply
Darren
Posts: 63
Joined: Wed May 11, 2011 11:55 am

Do not open notepad if notepad is already open

Post: # 915Post Darren
Thu Aug 02, 2012 2:30 pm

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!!!

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Do not open notepad if notepad is already open

Post: # 916Post Marco
Sun Aug 19, 2012 8:15 pm

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

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Do not open notepad if notepad is already open

Post: # 917Post cvirus
Mon Aug 20, 2012 2:39 pm

It works very good :D

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Do not open notepad if notepad is already open

Post: # 918Post cvirus
Mon Aug 20, 2012 2:42 pm

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Do not open notepad if notepad is already open

Post: # 919Post Marco
Mon Aug 20, 2012 3:04 pm

busy with that because you need a window handle for that and whe have a process handle.

best regards

cvirus
Posts: 88
Joined: Tue Jan 12, 2010 8:33 pm

Do not open notepad if notepad is already open

Post: # 920Post cvirus
Mon Aug 20, 2012 4:57 pm

[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?

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

Do not open notepad if notepad is already open

Post: # 921Post Marco
Tue Aug 21, 2012 3:13 pm

I think it is somehow possible but i did not find the solution yet.
best regards

Post Reply