Sign in to follow this  
Followers 0
gempie

Net Send Change name sender?!

9 posts in this topic

Hi all,

Thnx for looking in to this. Underneath is the script from CyberSlug (who i want to give credit for it's script). I added it al little but ran into the following problem. When receiving a message i only see the computername were it came from, but i want to see the username. (in cmd if i do "net name" it gives the computername and the username who is logged on) i tried to build in something like net name "computername" /delete so only the username would be left to display but this doesn't work. any idea's?

CODE
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.3.0 (beta)

Author: Pieter

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

; Proof-of-Concept for a net-send-based messenger program

; CyberSlug: Original code 3 July 2004

; Revised for new GUI syntax 10 December 2004

; Gui Recode to 3.1.1 15 August 2005

; Update with own code by evod510 2005

; Update by CyberSlug 12 Oct 2005: autoscroll via ^{End} and using arrays....

; Update by Pieter 20-3-2007: Made autoscroll functionable it didn't work, made usable for dutch windows system, made an if.. then.. for differences _

; in usernames. Made Name of Sender completely visable and made an error code when messenger is not running incl. instuctions _

; on how to activate it.

#include <GuiConstants.au3>

RunWait("net start messenger","",@SW_HIDE);Make sure messenger service is running

Opt("WinWaitDelay", 10) ;speeds things up a little

$MyGui = GuiCreate("messenger 1.0", 450,359,(@DesktopHeight-392)/2, (@DesktopHeight-359)/2 , 0x04CF0000)

;Controls might have word-wrap and/or read-only styles... maybe also styles to always show scroll bar...

$txt_output = GuiCtrlCreateEdit("", 10, 10, 433, 170, 0x50231904, 0x00000200)

;$txt_input = GuiCtrlCreateEdit("Message goes here.", 10, 230, 370, 70, 0x50231104)

$txt_input = GuiCtrlCreateEdit("Type hier je berichtje.", 10, 230, 370, 40, 0x50231104)

GuiCtrlSetState($txt_input, $GUI_FOCUS);default control with focus

$button_send = GUICtrlCreateButton("{Enter} == Send", 20, 300, 150, 30)

$checkbox_topmost = GuiCtrlCreateCheckbox("Always On Top", 210, 190, 150, 30, $BS_PUSHLIKE);looks like button....

GuiCtrlSetState($checkbox_topmost, $GUI_CHECKED);checkbox will be pushed in by default

$button_sendclear = GUICtrlCreateButton("Clear", 10, 190, 100, 30)

;;;;;;;;;;;;;;;;;;;;;;CHECHBOX USERLIST NAME START;;;;;;;;;;;;;;;;;;;;

Dim Const $NUM_PEOPLE = 14 ;define this constant so we can use it elsewhere in program

Dim $checkCN[$NUM_PEOPLE]

; Note that the array elements are indexed from 0 to $NUMPEOPLE-1

; If all the checkboxes were in a single column, we could initialize all these with a for loop....

; (assuming the names were stored in a separate array or something)

$checkCN[0] = GUICtrlCreateCheckbox ("Lily", 280, 280, 100, 20)

$checkCN[1] = GUICtrlCreateCheckbox ("Selma", 385, 320, 100, 20)

$checkCN[2] = GUICtrlCreateCheckbox ("Mike", 385, 300, 100, 20)

$checkCN[3] = GUICtrlCreateCheckbox ("Jan-Willem", 280, 300, 100, 20)

$checkCN[4] = GUICtrlCreateCheckbox ("Lucia", 385, 280, 100, 20)

$checkCN[5] = GUICtrlCreateCheckbox ("Renee", 385, 240, 100, 20)

$checkCN[6] = GUICtrlCreateCheckbox ("Mieke", 385, 340, 100, 20)

$checkCN[7] = GUICtrlCreateCheckbox ("Pieter", 280, 320, 100, 20)

$checkCN[8] = GUICtrlCreateCheckbox ("Seties", 280, 340, 100, 20)

$checkCN[9] = GUICtrlCreateCheckbox ("Stagiere", 385, 260, 100, 20)

$checkCN[10] = GUICtrlCreateCheckbox ("Toshiba", 175, 340, 100, 20)

$checkCN[11] = GUICtrlCreateCheckbox ("Philips", 175, 320, 100, 20)

$checkCN[12] = GUICtrlCreateCheckbox ("Balie", 175, 300, 100, 20)

$checkCN[13] = GUICtrlCreateCheckbox ("Koffie kamer", 175, 280, 100, 20)

;$MainCheck = GUICtrlCreateCheckbox("Select/Unselect", 30, 330, 120, 20)

;;;;;;;;;;;;;;;;;;;;;;CHECHBOX USERLIST NAME END;;;;;;;;;;;;;;;;;;;;;

GuiSetState(@SW_SHOW)

GUICtrlSendMsg($txt_input, 0xB1, 0, 99999);I want the sample text message to be highlighted upon start

WinSetOnTop($MyGui, "", 1);always on top by default...

;MAIN MESSAGE LOOP

While 1

sleep(5);sleep to prevent maxing out the CPU

; I want to trap the Enter key (but only when this GUI is active) so that it causes

; the message in the textbox to be send

If WinActive($MyGui) Then

HotKeySet("{Enter}", "EnterSends");register hotkey when our GUI messenger window is active

Else

HotKeySet("{Enter}");un-register hotkey otherwise

EndIf

; Constantly poll to see if a Net Send Popup has appeared. If so, grab its contents and close it.

If WinExists("Messenger-service","Bericht van") Then

Local $i, $t = ""

$text = StringSplit( StringReplace(WinGetText("Messenger-service","Bericht van"),@CRLF,@LF) , @LF)

WinClose("Messenger-service","Bericht van")

$sender = StringMid($text[2], 13, StringInStr($text[2]," to ")-14 )

$t = ""

For $i = 4 to $text[0]

$t = $t & $text[$i] & @CRLF

Next

$t = StringStripWS($t, 2);strip trailing whitespace

; Display contents from the Popup in the form '<TIME> SENDER: Message'

GUICtrlSetData($txt_output, GUICtrlRead($txt_output) & "<" & @Hour & ":" & @Min & ":" & @Sec & "> " & $sender & ": " & $t & @CRLF)

ControlFocus($MyGui, "", $txt_output)

ControlSend($MyGui,"",$txt_output,"^{End}")

;ControlFocus($MyGui, "", $txt_input);return focus back to the input field

ControlFocus($MyGui, "", $txt_input)

If WinActive ( "messenger 1.0") Then

TrayTip("clears any tray tip","",0)

Else

TrayTip("messenger 1.0", "Bericht ontvangen!", 600, 1)

Sleep(1)

EndIf

EndIf

$msg = GuiGetMsg() ; Get any GUI messag events

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $button_send

EnterSends()

Case $msg = $button_sendclear

Enterclear()

Case $msg = $checkbox_topmost

If GUICtrlRead($checkbox_topmost) = 1 Then

WinSetOnTop($MyGui, "", 1);checked for 'always on-top' window

Else

WinSetOnTop($MyGui, "", 0);unchecked for normal window

EndIf

EndSelect

WEnd

Exit

Func EnterSends()

ControlFocus($MyGui, "", "Edit2")

If StringStripWS(GUICtrlRead($txt_input), 3) = "" Then Return

Local $message = """" & GUICtrlRead($txt_input) & """" ;wrap message in quotes

Local $message2 = @ComputerName & " : " & GUICtrlRead($txt_input) ;wrap message in quotes

;;;;;;;;;;;;;;;;;;;;;;CHECHBOX USERLIST NAME 2 START;;;;;;;;

For $index = 0 to $NUM_PEOPLE-1

If GUICtrlRead($checkCN[$index]) = 1 Then ;check the checked state of each box

$recipient = ControlGetText($MyGui,"",$checkCN[$index]);conveniently, the text of the checkbox is the recipient...

;;;;;;;;;;;;;;;;;;;;;;;;use this if text of checkbox is not the recipient...

if $recipient = 'Lily' then $recipient = 'YpeE'

if $recipient = 'Selma' then $recipient = 'MorS'

if $recipient = 'Mike' then $recipient = 'PilM'

if $recipient = 'Jan-Willem' then $recipient = 'ArnJ'

if $recipient = 'Lucia' then $recipient = 'NauL'

if $recipient = 'Renee' then $recipient = 'PolR'

if $recipient = 'Mieke' then $recipient = 'VooM'

if $recipient = 'Pieter' then $recipient = 'GemP'

if $recipient = 'Seties' then $recipient = 'KanS'

if $recipient = 'Stagiere' then $recipient = 'NucS'

if $recipient = 'Toshiba' then $recipient = 'PC-6F2P

if $recipient = 'Philips' then $recipient = 'PC-4F2P'

if $recipient = 'Balie' then $recipient = 'PC-1NZ'

if $recipient = 'Koffie kamer' then $recipient = 'PC-FQL'

;Run('net send ' & $recipient & ' "' & $message & '"', '', @SW_HIDE)

;$exitcode = RunWait(@comspec & " /c net send "& $recipient &" "& $message,"",@sw_hide)

if RunWait(@comspec & " /c net send "& $recipient &" "& $message,"",@sw_hide) == 2 Then

;;;;;;;;;;;;;;;;;;;;;;;error code when messenger is not running

MsgBox(262192, $recipient,"Messenger moet gestart worden!, Rechterklik op deze computer-> beheren. Klik _

vervolgens op -services en toepassingen- en dan rechts in beeld dubbelklikken op services. Dan ga _

je naar -messenger- waarop je dubbel klikt. Onder 't tabblad algemeen zet je opstarttype op automatisch en klik je _

rechtsonder op -toepassen-. Klik op -OK- en dan op De Service -starten-.")

;Else

;MsgBox(48, $exitcode,"")

EndIf

EndIf

Next

;;;;;;;;;;;;;;;;;;;;;;CHECHBOX USERLIST NAME 2 END;;;;;;;;;

GuiCtrlSetData($txt_output, GUICtrlRead($txt_output) & "<" & @Hour & ":" & @Min & ":" & @Sec & "> " & $message2 & @CRLF)

GuiCtrlSetData($txt_input, '') ;clear contents of textbox

ControlFocus($MyGui, "", $txt_output)

ControlSend($MyGui,"",$txt_output,"^{End}")

ControlFocus($MyGui, "", $txt_input)

EndFunc ;==>EnterSends

Func Enterclear()

GuiCtrlSetData($txt_output, '') ;clear contents of textbox Message Typed and Received, you dont anybody else to read your message!!

EndFunc ;==>Enterclear

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you can get the IP-adress (Parse ping output?) you can use nbtstat with the -A parameter. Although this is not a 100% safe to get an username, and you will always have several candidates.

Edited by Manadar

Share this post


Link to post
Share on other sites

hmmm, doesn't seem to work. When in cmd you automaticly get to the C:\Documents and Settings\user\Desktop> folder. Is this info stored somerwere? or is it possible to retrieve the user name from here?

Share this post


Link to post
Share on other sites

CODE
runwait("cmd /c echo %username% > c:\user.txt", "", @SW_HIDE)

runwait("cmd /c echo %userdomain% > c:\domain.txt", "", @SW_HIDE)

$userfile = "c:\user.txt"

$domainfile = "c:\domain.txt"

$openuser = FileOpen($userfile,0)

$opendomain = FileOpen($domainfile,0)

$userline = FileRead($openuser)

$domainline = FileRead($opendomain)

MsgBox (0, "Logged in user details", "Domain = " & $domainline & " Username = " & $userline)

Oke, got a way to get the username. Now is there a way to add this in the script so the receiver of the message gets the username instead of the computername???

Share this post


Link to post
Share on other sites

Manadar, you were right afterall but still need some help.

CODE
runwait("cmd /c nbtstat -A PC-4F2PB1J > c:\ipretrieve.txt", "", @SW_HIDE)

$userip = "c:\ipretrieve.txt"

$openip = FileOpen($userip,0)

Now i need the IP which is between the [xxx.xxx.xxx.xx] is there a way to get this info out of the .txt file?

then i need to do runwait("cmd /cnbtstat -A xxx.xxx.xxx.xx > c:\username.txt", "", @SW_HIDE)

this gives mee a list. I need the last name in the list which is always 6 char. long

any idea??

Share this post


Link to post
Share on other sites

Oke, i found out ho to change the PC-name to an ip adres:

CODE
$ipretrieve = TCPNameToIP($sender2)

msgbox (262192,'IP??', $ipretrieve)

runwait("cmd /c nbtstat -A "&$ipretrieve&" > c:\nameretrieve.txt", "", @SW_HIDE)

$userip = "c:\nameretrieve.txt"

$openip = FileOpen($userip,0)

The only thing i need help for is how to get the username from the .txt file???[/color]

The username is always 6 characters long and is last in the list.

Thnx for looking in to this!!

nameretrieve:

---------------------

LAN-verbinding:

IP-adres van knooppunt: [194.12.178.195] Scope-ID: []

Tabel met NetBIOS-externe computernamen

Naam Type Status

---------------------------------------------

PC-4F2PB1J <00> Uniek Geregistreerd

MCB <00> Groep Geregistreerd

PC-4F2PB1J <20> Uniek Geregistreerd

PC-4F2PB1J <01> Uniek Geregistreerd

PC-4F2PB1J <03> Uniek Geregistreerd

GEMPOO <03> Uniek Geregistreerd

MAC-adres = 00-0F-2F-B4-63-8B

-------------------------------------

Share this post


Link to post
Share on other sites

$Info = _GetMacAndName("192.168.2.103")
If Not @error Then
    MsgBox(0x40,"_GetMacAndName()","PC Name: " & @TAB & $Info[0] & @CRLF & "Username: " & @TAB & $Info[1] & @CRLF &"MAC Adress: " & @TAB & $Info[2])
Else
    MsgBox(0x20,"_GetMacAndName()", "Connection timed out. We were unable to get the mac-adress and name of the remote computer.")
EndIf


Func _GetMacAndName($g_IP)
    Dim $Return[3]
    $PID = Run(@ComSpec & " /c nbtstat -A " & $g_IP,@ScriptDir,@SW_HIDE,2)
    While ProcessExists($PID)
        Sleep(50)
    WEnd
    $nRead = StdoutRead($PID,1024)
    $Mac = StringRegExp($nRead,"([A-F0-9]{2}-?){6}",2)
    If Not @error Then
        $RegExp = StringRegExp($nRead,"[^\n]+<..>",3)
        If Not @error Then
            $Return[0] = StringStripWS(StringTrimRight($RegExp[0],4),8)
            $Return[1] = StringStripWS(StringTrimRight($RegExp[UBound($RegExp)-1],4),8) ;this supposedly returns username on some computers..  I know it doesn't do on mine..
            $Return[2] = $Mac[0]
            SetError(0)
            Return $Return
        EndIf
    EndIf
    SetError(1)
    Return 0
EndFunc

Share this post


Link to post
Share on other sites

Thnx, didn't work on my machine either. I made the script look for the user while comparing to a user list. That worked out great.

Share this post


Link to post
Share on other sites

Thnx, didn't work on my machine either. I made the script look for the user while comparing to a user list. That worked out great.

Happy to help. :whistle:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0