简体   繁体   中英

How to Create “Instant Messaging” in Notepad++ - VBScript

As a past time with a couple of friends, I'm trying to make a sort of "instant messaging" through notepad++.

The setup is as follows: Three computers are connected on a network. On computer 2, there is Notepad++ in its directory. On computer 3, there is the VBScript and the text file (which is opened in Notepad++). The "F5" key in Notepad++ has been rebound to "Reload From Disk" respectively.

The goal is to have Notepad++ refresh every 2 seconds or so, but exclusively in Notepad++, even in the background. The VBScript is meant to close upon Notepad++ closing.

The VBScript is as follows (keep in mind I have no prior experience with VBScripts; expect major flaws):

strFileName = "\\08-111096-CISCO\Users\Straka.J\Downloads\Notepad++"  
Dim oShell

set oShell = CreateObject("wScript.Shell")  
oShell.Run "notepad++ ""\\08-111099-CISCO\Users\Javorsky.G\Downloads\New Text Document.txt"""  
oShell.AppActivate "\\08-111096-CISCO\Users\Straka.J\Downloads\Notepad++\notepad++.exe"  
Do    
    WScript.Sleep 500  
    oShell.SendKeys "{F5}"  
    wScript.Sleep 2000  
Loop Until Quit  

Notepad++ will open the text file and will begin the F5 loop. However, the F5 will continue regardless if Notepad++ is the active window or not, and the script does not close upon Notepad++ closing.

I'm certainly missing something, but after several hours of research and experimenting, I couldn't find a solution.

Is it possible to achieve these results with just a VBScript?

AppActivate() returns True if the call was successful (if it found and activated the window). Use that return value to determine whether to continue refreshing or to close your script.

Do While oShell.AppActivate("\\08-111096-CISCO\Users\Straka.J\Downloads\Notepad++\notepad++.exe")

    oShell.SendKeys "{F5}"
    WScript.Sleep 2000

Loop

' Script exit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM