Page 2 of 2 <12
Topic Options
#155421 - 2006-01-19 12:06 PM Re: Net Send Scripting.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yup.
no nonblocking doEvents in kf .net currently.
_________________________
!

download KiXnet

Top
#155422 - 2006-01-19 01:54 PM Re: Net Send Scripting.
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Jooel,

Can you post a method of using a timer to return a no-op event so that control is passed back to the script every (say) 0.1 seconds?

Top
#155423 - 2006-01-19 02:15 PM Re: Net Send Scripting.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
out of hat code would be:
Code:

$Timer = $System.Timer
$Timer.Interval = 1000 ;1000ms = 1s
$Timer.Tick = "doSomeOtherScriptStuff()" ;the event that fires every second
$Timer.Start

function doSomeOtherScriptStuff()
"hey, we have control." ?
"in this udf we can do what ever we want."
?
endfunction

_________________________
!

download KiXnet

Top
#155424 - 2006-01-19 04:54 PM Re: Net Send Scripting.
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Thx Richard H, Jooel, Shawn and Les

It works splendidly now, here's the final code:
(keep in mind, the dialog is very plain and simple)
Code:

Break On

$System = CreateObject("Kixforms.System")
If Not $System
$nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

; GLOBAL SETUP - PLACE AT SCRIPT START----------------------
GLOBAL $oAutoIT, $sMessengerTitle, $iControlMessage
$sMessengerTitle="Messenger-service"
$iControlMessage=65535

$oAutoIT=CreateObject("AutoItX3.Control")
If @ERROR OR VarType($oAutoIT)<>9 "Cannot create AutoIT object - no registered perhaps?"+@CRLF Exit @ERROR EndIf

; Set some useful options.
$=$oAutoIT.Opt("MouseCoordMode",0)
$=$oAutoIT.Opt("WinTitleMatchMode",4)

; Timer to catch messages
$Timer = $System.Timer
$Timer.Interval = 1000 ;1000ms = 1s
$Timer.Tick = "CatchMSG()" ;the event that fires every second
$Timer.Start

; END OF GLOBAL SETUP---------------------------------------

$Form1 = $System.Form()
$Form1.Left = 368
$Form1.StartPosition = 0 ;FormStartPosition_Manual
$Form1.Size = $System.Size(240,358) ;(Width,Height)
$Form1.Text = "LAN Messenger"
$Form1.Top = 0

$Label1 = $System.Label()
$Label1.BorderStyle = 0 ;FixedSingle
$Label1.Left = 24
$Label1.Text = "Gebruiker"
$Label1.TextAlign = 16 ;MiddleLeft
$Label1.Top = 19
$Label1.Width = 55
$nul = $Form1.Controls.Add($Label1)

$ComboBox1 = $System.ComboBox()
$ComboBox1.Height = 21
$ComboBox1.ItemHeight = 13
$ComboBox1.Left = 89
$ComboBox1.Text = "Select..."
$ComboBox1.Top = 20
$nul = $Form1.Controls.Add($ComboBox1)

$RichTextBox1 = $System.RichTextBox()
$RichTextBox1.Height = 171
$RichTextBox1.Left = 13
$RichTextBox1.Text = ""
$RichTextBox1.Top = 68
$RichTextBox1.Width = 209
$nul = $Form1.Controls.Add($RichTextBox1)

$TextBox1 = $System.TextBox()
$TextBox1.Height = 61
$TextBox1.Left = 13
$TextBox1.Text = ""
$TextBox1.Top = 258
$TextBox1.Width = 125
$TextBox1.Multiline = -1
$nul = $Form1.Controls.Add($TextBox1)

$Button1 = $System.Button()
$Button1.Height = 61
$Button1.Left = 152
$Button1.Text = "Send!"
$Button1.Top = 258
$Button1.Width = 70
$Button1.Click = "SendMSG()"
$nul = $Form1.Controls.Add($Button1)

$Form1.Show ;Displays the Form
Init()
While $Form1.Visible
$Nul = Execute($Form1.DoEvents())
Loop
Exit 0

Function SendMSG()
Dim $msg, $rcpt, $x
$msg = $TextBox1.Text
$rcpt = $ComboBox1.Text
If $rcpt = "Select..."
$x = MessageBox("You have to select a user first!","Info",0)
Goto "end"
EndIf
$log = $log + @CRLF + "Jij zegt tegen " + $rcpt + ":" + @CRLF + $msg + @CRLF
$RichTextBox1.Text = $log
run "net send $rcpt $msg"
$TextBox1.Text = ""
:end
EndFunction

Function CatchMSG()
Dim $sMessageText, $sFrom, $sDate, $sTime
If $oAutoIT.WinExists($sMessengerTitle)
$sMessageText=$oAutoIT.ControlGetText("last","",$iControlMessage)
$=$oAutoIt.WinClose("last")

$sMessageText=split($sMessageText,@CRLF)
$sFrom=Split($sMessageText[0]+" ")[2]
$sTo=Split($sMessageText[0]+" ")[4]
$sDate=Split($sMessageText[0]+" ")[6]
$sTime=Split($sMessageText[0]+" ")[7]+" "+Split($sMessageText[0]+" ")[8]
$sMessageText[0]=""
$sMessageText=SubStr(Join($sMessageText,@CRLF),5)

$log = $log + @CRLF + $sFrom + " zegt tegen jou:" + @CRLF + $sMessageText + @CRLF
$RichTextBox1.Text = $log
EndIf
EndFunction

Function Init()
;ComboBoxbox 1 Info
$Users = GetObject("WinNT://@ldomain")
$Users.filter = "User",""
For Each $User In $Users
$x = $ComboBox1.Items.Add($User.Name)
Next
EndFunction


Top
#155425 - 2006-01-19 05:05 PM Re: Net Send Scripting.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hehee, I'm impressed. It even works on my non-properly-joined-to-domain laptop using local admins ... getting NET SEND messages displayed to the console though. Can you silence them by shelling and redirecting output to bit-bucket, or will that screw things up ?
Top
#155426 - 2006-01-19 05:19 PM Re: Net Send Scripting.
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Instead of the Users Filter one could also use the Computers filter of course. (Keep in mind: EN = "Messenger Service", NL = "Messenger-service")
I think it'll screw things up since it grabs the text directly from the "Messenger-service" window. But you could, as Les mentioned before" grab the msg's from the logs, that way you could hide em altogether I think.

Top
#155427 - 2006-01-19 05:37 PM Re: Net Send Scripting.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I was getting console messages like this:

An error occurred while sending a message to ADMINISTRATOR.

The message alias could not be found on the network.

More help is available by typing NET HELPMSG 2273.

Found that if I changed this line:

run "net send $rcpt $msg"

to this:

shell "cmd /c net send $rcpt $msg >nul 2>nul"

then the messages went away.

Top
#155428 - 2006-01-19 05:57 PM Re: Net Send Scripting.
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Oh! I thought you were referring to the Incomming messages
Yeah the outgoing is very primitive, usually once I get something to work for myself I leave it at what it is I only really clean up and script nice when it's for someone else

Top
#155429 - 2006-01-19 06:04 PM Re: Net Send Scripting.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
wah - you saying we dont count as "someone else" ? You getting kinda comfortable on the old board here eh ? ;0)
Top
#155430 - 2006-01-19 06:33 PM Re: Net Send Scripting.
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
LOL, well you we're helping me in the first place
Besides, yeah I am gettin kinda comfortable, whenever help is needed there is always someone around to help, you don't find that very often anymore. So to express my gratitude I've cleaned it up, still the Dialog is a simple one

Code:

Break On

$System = CreateObject("Kixforms.System")
If Not $System
$nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

GLOBAL $oAutoIT, $sMessengerTitle, $iControlMessage, $log
$sMessengerTitle="Messenger-service"
$iControlMessage=65535

$oAutoIT=CreateObject("AutoItX3.Control")
If @ERROR OR VarType($oAutoIT)<>9
? "Cannot create AutoIT object - no registered perhaps?" + @CRLF
Exit @ERROR
EndIf

; Set some useful options.
$=$oAutoIT.Opt("MouseCoordMode",0)
$=$oAutoIT.Opt("WinTitleMatchMode",4)

; Timer to catch messages
$Timer = $System.Timer
$Timer.Interval = 1000 ;1000ms = 1s
$Timer.Tick = "CatchMSG()" ;the event that fires every second
$Timer.Start

$Form1 = $System.Form()
$Form1.Left = 368
$Form1.StartPosition = 0 ;FormStartPosition_Manual
$Form1.Size = $System.Size(240,358) ;(Width,Height)
$Form1.Text = "LAN Messenger"
$Form1.Top = 0

$Label1 = $System.Label()
$Label1.BorderStyle = 0 ;FixedSingle
$Label1.Left = 24
$Label1.Text = "Gebruiker"
$Label1.TextAlign = 16 ;MiddleLeft
$Label1.Top = 19
$Label1.Width = 55
$nul = $Form1.Controls.Add($Label1)

$ComboBox1 = $System.ComboBox()
$ComboBox1.Height = 21
$ComboBox1.ItemHeight = 13
$ComboBox1.Left = 89
$ComboBox1.Text = "Select..."
$ComboBox1.Top = 20
$nul = $Form1.Controls.Add($ComboBox1)

$RichTextBox1 = $System.RichTextBox()
$RichTextBox1.Height = 171
$RichTextBox1.Left = 13
$RichTextBox1.Text = ""
$RichTextBox1.Top = 68
$RichTextBox1.Width = 209
$nul = $Form1.Controls.Add($RichTextBox1)

$TextBox1 = $System.TextBox()
$TextBox1.Height = 61
$TextBox1.Left = 13
$TextBox1.Text = ""
$TextBox1.Top = 258
$TextBox1.Width = 125
$TextBox1.Multiline = -1
$nul = $Form1.Controls.Add($TextBox1)

$Button1 = $System.Button()
$Button1.Height = 61
$Button1.Left = 152
$Button1.Text = "Send!"
$Button1.Top = 258
$Button1.Width = 70
$Button1.Click = "SendMSG()"
$nul = $Form1.Controls.Add($Button1)

$Form1.Show ;Displays the Form
Init()
While $Form1.Visible
$Nul = Execute($Form1.DoEvents())
Loop
Exit 0

Function SendMSG()
Dim $msg, $rcpt, $x
$msg = $TextBox1.Text
$rcpt = $ComboBox1.Text
If $rcpt = "Select..."
$x = MessageBox("You have to select a user first!","Info",0)
Goto "end"
EndIf
$log = $log + @CRLF + "You said to " + $rcpt + ":" + @CRLF + $msg + @CRLF
$RichTextBox1.Text = $log
shell "%comspec% /c net send $rcpt $msg > nul"
$TextBox1.Text = ""
:end
EndFunction

Function CatchMSG()
Dim $sMessageText, $sFrom, $sTo, $sDate, $sTime
If $oAutoIT.WinExists($sMessengerTitle)
$sMessageText=$oAutoIT.ControlGetText("last","",$iControlMessage)
$=$oAutoIt.WinClose("last")
$sMessageText=split($sMessageText,@CRLF)
$sFrom=Split($sMessageText[0]+" ")[2]
$sTo=Split($sMessageText[0]+" ")[4]
$sDate=Split($sMessageText[0]+" ")[6]
$sTime=Split($sMessageText[0]+" ")[7]+" "+Split($sMessageText[0]+" ")[8]
$sMessageText[0]=""
$sMessageText=SubStr(Join($sMessageText,@CRLF),5)
$log = $log + @CRLF + $sFrom + " says to you:" + @CRLF + $sMessageText + @CRLF
$RichTextBox1.Text = $log
EndIf
EndFunction

Function Init()
Dim $Users, $User
$Users = GetObject("WinNT://@ldomain")
$Users.filter = "User",""
For Each $User In $Users
$x = $ComboBox1.Items.Add($User.Name)
Next
EndFunction


Top
Page 2 of 2 <12


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 700 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.066 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org