KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

RemoteExec() - Executes Remote (and local) commands
Goto page 1, 2  Next
 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
jim
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 76
Location: Philadelphia, PA

PostPosted: Fri Apr 25, 2003 6:23 pm    Post subject: RemoteExec() - Executes Remote (and local) commands Reply with quote

Third in the series...

Code:

;FUNCTION         RemoteExec($Comp,$RExecuteDAT)
;
;AUTHOR           Jim Tokach
;
;ACTION           Execute Commands Remotely (and locally)
;
;SYNTAX           RemoteExec($Comp,$RExecuteDAT)
;
;PARAMETERS       $Comp (Required) [String]
;                    The hostname of the computer to execute commands on.
;
;                 $RExecuteDAT (Required) [String]
;                    Path and filename or just filename of the database that
;                    will contain the command history. If the file does not
;                    exist, it will be created if a history item is added.
;                    Additionally, any changes or addtions made to the history
;                    automatically create a backup of the current DB with a rev.
;                    number appended to the filename.
;
;REMARKS          Due to the nature of telnet sessions, the remotely executed
;                 command will not have access to network resources.  The
;                 command is also executed in the context of the executor, i.e.
;                 you or the ID you ran as. If you don't know what this means,
;                 or do not understand the risk and/or implications, do not use
;                 this code. From what I understand, using delegation can
;                 accomplish running commands under the remote logged on account.
;                 However, this has not been proven or disproven.  Refer to the
;                 Kixtart BBS (www.kixtart.org) or the MSDN (msdn.microsoft.com)
;                 regarding impersonation and delegation.
;
;RETURNS          Nothing
;
;DEPENDENCIES     Kixtart 4.20
;                 KixForms 2.3.0.38
;                 WMI
;
;EXAMPLES         RemoteExec(@wksta,"RemoteExec.log")

; Unremark the following line to run locally
;RemoteExec("vfesnewlav","RemoteExec.log")

Function RemoteExec($Comp,$RExecuteDAT)
    Dim $Default
    $Default='cmd /c net send @wksta "This is a test."'

   $frmRExec = CreateObject("Kixtart.Form")
   $frmRExec.Text = "Execute Remote Command on $Comp"
   $frmRExec.width=350
   $frmRExec.height=270

   $La = 10
   $Ta = 12
   $Wa = $frmRExec.ClientWidth-42
   $Ha = 18
   
   $Lb=$La+30
    $Wb = 50
   $Hb = 22

   $Wc = ($frmRExec.ClientWidth-22)/2

    $fraRXTools= $frmRExec.frame("Command to Execute Remotely",$La,$Ta,$frmRExec.ClientWidth-22,70)
    $fraRXTools.fontbold=1

   $txtRXcmd=$frmRExec.combobox('',$La+10,30,$Wa,20)

   $=Open(1,$RExecuteDAT)
        $x=Readline(1)
        While @Error=0
            If "X"+Trim($x)+"X"<>"XX" and $x<>$Default
                $txtRxcmd.additem($x)
            EndIf
            $x=Readline(1)
        Loop
    $=Close(1)

   $txtRxcmd.additem($Default)

    $cmdRXAdd=$frmRExec.button("Add",$La+10,$txtRXcmd.bottom+2,$w,20)
    $cmdRXAdd.OnClick='AddRXDAT_Click($RExecuteDAT)'

    $cmdRXRemove=$frmRExec.button("Remove ",$cmdRXAdd.right,$txtRXcmd.bottom+2,$w,20)
    $cmdRXRemove.OnClick='RemoveRXDAT_Click($RExecuteDAT)'

   $lblRXLastA=$frmRExec.label("Last Command Status: ",$La,$fraRXTools.bottom+6,$Wa,$Ha)
   $lblRXLastA.fontbold=1

   $optRXself=$frmRExec.optionbutton("Execute as Self",$La,$lblRXLastA.bottom+6,$Wa,$Ha)
    $optRXSelf.value=1
    $optRXSelf.OnClick='UpdateRXOpts()'

   $optRXother=$frmRExec.optionbutton("Execute as Other",$La,$optRXself.bottom+2,$Wa,$Ha)
   $optRXother.OnClick='UpdateRXOpts()'

   $lblRXUser=$frmRExec.label("Username",$Lb,$optRXother.bottom+4,$Wb,$Hb)
   $txtRXUser=$frmRExec.textbox("",$lblRXUser.Right+6,$optRXother.bottom,$Wc,$Hb)

   $lblRXPW=$frmRExec.label("Password",$Lb,$lblRXUser.bottom+6,$Wb,$Hb)
   $txtRXPW=$frmRExec.textbox("",$lblRXPW.Right+6,$lblRXUser.bottom+2,$Wc,$Hb)
   $txtRXPW.PasswordChar="*"

   $cmdRXExecute=$frmRExec.button("Execute",$La,$lblRXPW.Bottom+8,$Wc,$Hb)
   $cmdRXExecute.onclick = "cmdRXExecute_click($Comp)"

   $cmdRXCancel=$frmRExec.button("Cancel",$cmdRXExecute.right,$lblRXPW.Bottom+8,$Wc,$Hb)
   $cmdRXCancel.SetAsDefault
   $cmdRXCancel.onclick = "cmdRXCancel_click()"

    UpdateRXOpts()
   $frmRExec.show
   While $frmRExec.Visible
      $=Execute($frmRExec.DoEvents())
   Loop
EndFunction

Function UpdateRXOpts()
    If $optRXself.value=1
        $txtRXUser.enabled=0
        $txtRXPW.enabled=0
    Else
        $txtRXUser.enabled=1
        $txtRXPW.enabled=1
    EndIf
EndFunction

Function cmdRXCancel_click()
   $frmRExec.Visible = 0
EndFunction

Function cmdRXExecute_Click($Comp)
    SetOption("WrapAtEOL",on)
    $frmRExec.Mousepointer=11
    Select
        Case $optRXself.value=1
            $Connect = GetObject("winmgmts:{impersonationLevel=impersonate,(Debug)}!//$Comp/root/cimv2:Win32_Process")
            $Process = $Connect.Create($txtRXcmd.Text)
            If @Error=0
                $lblRXLastA.Text="Last Command Status: Successful"
            Else
                $lblRXLastA.Text="Last Command Status: Failed"
            EndIf

        Case $optRXother.value=1
            $ID = $txtRXUser.caption
            $PW = $txtRXPW.caption
            If $ID="" or $Comp=@wksta
                If $ID=""
                    $nul=MessageBox("A valid username and password are required to execute a remote command as another user.","Username and Password Required",16)
                EndIf
                If $Comp=@wksta
                    $nul=MessageBox("You cannot use another account to execute commands on your local workstation. This is a limitation of SWbemLocator.","Username and Password Required",16)
                EndIf
            Else
                $Connect = CreateObject("WbemScripting.SWbemLocator")
                ;? @serror
                If $Connect<>""
                    $EstCon = $Connect.ConnectServer("$Comp","root\cimv2","$ID","$PW")
                    ;? @serror
                EndIf
                If $EstCon<>""
                    $GrabProc = $EstCon.Get("Win32_Process")
                    ;? @serror
                EndIf
                If $GrabProc<>""
                    $Process = $GrabProc.Create($txtRXcmd.Text)
                    ;? @serror
                EndIf
                If @Error=0
                    $lblRXLastA.Text="Last Command Status: Successful"
                    $txtRxcmd.additem($txtRXcmd.Text)
                Else
                    $lblRXLastA.Text="Last Command Status: Failed"
                EndIf
            EndIf
        EndSelect
        $Connect    =""
        $Process    =""
        $EstCon     =""
        $GrabProc   =""
        $ID         =""
        $PW         =""
    $frmRExec.Mousepointer=0
EndFunction

Function AddRXDAT_Click($RExecuteDAT)
    $txtRXcmd.AddItem ($txtRXcmd.Text)
    SaveRXDAT($RExecuteDAT)
EndFunction

Function RemoveRXDAT_Click($RExecuteDAT)
    $txtRXcmd.RemoveItem ($txtRXcmd.ListIndex)
    SaveRXDAT($RExecuteDAT)
EndFunction

Function SaveRXDAT($RExecuteDAT)
; If profile exists, delete it ...
    If Exist("$RExecuteDAT")
      Copy "$RExecuteDAT" "$RExecuteDAT.bak.@date.@Time"
      Del "$RExecuteDAT"
   EndIf

   ; For each item in the view, write out details ...
   $=Open(1,$RExecuteDAT,5)
   For $i=0 to $txtRxcmd.ListCount-1
        $txtRXcmd.ListIndex=$i
        $=WriteLine(1,$txtRXcmd.Text+@CRLF)
   Next
   $=Close(1)
EndFunction
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Mon May 05, 2003 11:57 am    Post subject: Reply with quote

uh?
function?

it looks like script which includes 100 of UDFs and returns nothing...

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Rod
KiXforms Webmaster
KiXforms Webmaster


Joined: 22 Feb 2003
Posts: 202
Location: United Kingdom

PostPosted: Mon May 05, 2003 12:50 pm    Post subject: Reply with quote

At the head of the script, see:
Quote:
;Unremark the following line to run locally
;RemoteExec("vfesnewlav","RemoteExec.log")

Rod.

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sun May 11, 2003 10:26 pm    Post subject: Reply with quote

what about it?
_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Mon Apr 10, 2006 6:17 pm    Post subject: Reply with quote

I like this... Cool

But why is not working with IP instead of host name?
"cmd /c" could be buildin.

Cool done jim!
Back to top
View user's profile Send private message
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Mon Apr 10, 2006 6:52 pm    Post subject: Reply with quote

If I use a machine with a hypen in the name it errors on line 1 and ends
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Mon Apr 10, 2006 6:54 pm    Post subject: Reply with quote

BTW, have you seen "Remote Execution Manager" on KORG?
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Mon Apr 10, 2006 10:25 pm    Post subject: Reply with quote

REM ? some quick search on korg.... hummm

the www.wheelerfam.com/Documents/REM.kix
is bad link - Error 404: NOT FOUND!

"requires: WOL.exe
dhcpcmd.exe from the MS reskit
and kixforms "

Why is WOL needed?
Is it not using RemoteExec() udf?

Well there is sysinternals PsExec, but it could be fun have some kixart+kixform internal soultion without using external command tools...
some console terminal to execute remotly....

maybe move to solaris Wink

_________________
"... Great minds talk about idea's, average minds talk about events and samll minds talks about people...!"
Back to top
View user's profile Send private message
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Tue Apr 11, 2006 2:24 pm    Post subject: Reply with quote

well, it uses DHCPCMD to harvest MAC addresses from DHCP Server

It use WOL to wake PCs that are powered off

Then it can preform RemoteExec on the PCs enmass.


I've moved web hosts, and haven't recreated my kixsite,,,

New site will be http://kixtart.radprojects.net
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Tue Apr 11, 2006 3:22 pm    Post subject: Reply with quote

Oh cool.

I like your Inquisitor/SIm solution Nod
In fact it was partly thanx to your Inquisitor I got intrest for kix.

hum....I cannot find REM on your new site...
Back to top
View user's profile Send private message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Tue Apr 11, 2006 3:29 pm    Post subject: Reply with quote

oh...I found it on korg. excellent...

let me check it out...
Back to top
View user's profile Send private message
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Tue Apr 11, 2006 3:32 pm    Post subject: Reply with quote

Would like to cut the remote execute part of it...
I need only that for my project ....
Back to top
View user's profile Send private message
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Tue Apr 11, 2006 5:15 pm    Post subject: Reply with quote

Actually, I just harvested much of the code from this form and added it to a tab on SIM 1.32.

Thanks Jim Smile
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Floyd
KiXforms Supporter
KiXforms Supporter


Joined: 21 Apr 2004
Posts: 78

PostPosted: Tue Apr 11, 2006 5:22 pm    Post subject: Reply with quote

hum....

how do i make Jim's code to use ip instead of host... cannot not make it work...
Back to top
View user's profile Send private message
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Tue Apr 11, 2006 5:33 pm    Post subject: Reply with quote

sim1.32 is at
http://kixtart.radprojects.net/files/sim-1.32-radimus.zip


Last edited by Radimus on Tue Apr 11, 2006 7:50 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group