vb.net - Trying to make command like "Shell" with commands with RichTextBox -


trying make command shell commands richtextbox.

can make simple way make it? im searching on entire webs can't find way make it. should terminal / shell / console app can add custom commands whatismyip shows me ip address etc.

should this.

private sub button1_click(sender object, e eventargs) handles button1.click    integer = 0 richtextbox1.lines.count - 1      dim parts() string = richtextbox1.lines(i).split      select case parts(0).toupper        case "getip"          richtextbox1.appendtext("sys $~ 127.0.0.1")        case else          richtextbox1.appendtext("sys $~ invalid command.")      end select    next  end sub 

try this:

private sub form1_load(sender object, e eventargs) handles mybase.load     commands = new dictionary(of string, func(of string, ienumerable(of string), string))() _     { _         {"getip", function(c, ps) me.getip().tostring()}, _         {"nop", function(c, ps) "no command"} _     } end sub  private commands dictionary(of string, func(of string, ienumerable(of string), string)) = nothing  private sub button1_click(sender object, e eventargs) handles button1.click     dim command = {"nop"}.concat(me.richtextbox1.lines) _                   .reverse().first(function(l) not [string].isnullorwhitespace(l))      if (if(me.richtextbox1.lines.lastordefault(), "")).length > 0         me.richtextbox1.appendtext(environment.newline)     end if      dim parts = command.split({" "c}, stringsplitoptions.removeemptyentries)     dim result = "invalid command"     if commands.containskey(parts(0).tolower())         result = commands(parts(0))(parts(0), parts.skip(1).toarray())     end if     me.richtextbox1.appendtext("sys $~ " + result) end sub  private function getip() string     dim host iphostentry     dim localip string = "?"     host = dns.gethostentry(dns.gethostname())     each ip ipaddress in host.addresslist         if ip.addressfamily = addressfamily.internetwork             localip = ip.tostring()         end if     next     return localip end function 

you'll need add following imports:

imports system.net imports system.net.sockets 

then can build out dictionary each of commands.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -