Sign in to follow this  
Followers 0
Digi

ControlSend Problems...

4 posts in this topic

#1 ·  Posted (edited)

Hey again :whistle:

I got yet another prob, this time with controlsend.....

I have this.....

;..............
controlSend("C:\WINDOWS\system32\cmd.exe","","", "rconsole{SPACE}" & $servername)
sleep(1500)
;..............

My problem is this I even put in a msgbox to confirm it My $servername value is not being entered correctly in the control send.

Before the control send the Value is say CNA_LOWVELD but when the controlsend executes it places

cna-lowveld

How can i get it so it keeps the case and a _ not - ??????????

Edited by Digi

Saru Mo Ki Kara Ochiru[u]Direct Translation[/u]: Even monkeys will fall from trees.[u]I.E.:[/u] To Error is HumanMy Splash Screen applet: Splash Screen Coding

Share this post


Link to post
Share on other sites



A console window is not a win32 application so ControlSend suffers a shift state issue with the window. There is a UDF called ControlSendPlus that may help to workaround the issue. Have a search for it in scripts'n'scraps.

Share this post


Link to post
Share on other sites

Ok I Found it, and I'll post it here also for the Guys that might have the same prob... :P

I take no Fame for this code, all I did was find it, Code was done By SlimShady or Pekster?????? I think....

Well here it is. :whistle:

Func ControlSendPlus($Title, $Text, $className, $String, $flag)
   ;VERSION 2.0.3 (06/13/2004)
   Local $ctrl = 0, $alt = 0, $upper, $start, $end, $i, $char, $and, $Chr5Index, $isUpper, $ret
   If $flag = 2 Or $flag = 3 Then $ctrl = 1
   If $flag = 2 Or $flag = 4 Then $alt = 1
   If $flag <> 1 Then $flag = 0 ;set the flag to the default function style
   $upper = StringSplit('~!@#$%^&*()_+|{}:"<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ', "")
   
   If $flag <> 1 Then ;don't replace special chars if it's raw mode
      ;replace {{} and {}} with +[ and +] so they will be displayed properly
      $String = StringReplace($String, "{{}", "+[")
      $String = StringReplace($String, "{}}", "+]")
      ;replace all special chars with Chr(5)
      ;add the special char to an array.  each Chr(5) corresponds with an element
      Local $Chr5[StringLen($String) / 2 + 1]
      For $i = 1 To StringLen($String)
         $start = StringInStr($String, "{")
         If $start = 0 Then ExitLoop ;no more open braces, so no more special chars
         $end = StringInStr($String, "}")
         If $end = 0 Then ExitLoop ;no more close braces, so no more special chars
         ;parse inside of braces:
         $Chr5[$i] = StringMid($String, $start, $end - $start + 1)
         ;replace with Chr(5) leaving the rest of the string:
         $String = StringMid($String, 1, $start - 1) & Chr(5) & _
               StringMid($String, $end + 1, StringLen($String))
      Next
      ;take out any "!", "^", or "+" characters
      ;add them to the $Modifiers array to be used durring key sending
      Local $Modifiers[StringLen($String) + 1]
      For $i = 1 To StringLen($String)
         $char = StringMid($String, $i, 1)
         $and = 0
         If $char = "+" Then
            $and = 1
         ElseIf $char = "^" Then
            $and = 2
         ElseIf $char = "!" Then
            $and = 4
         ElseIf $char = "" Then
            ExitLoop
         EndIf
         If $and <> 0 Then
            $Modifiers[$i] = BitOR($Modifiers[$i], $and)
            $String = StringMid($String, 1, $i - 1) & _
                  StringMid($String, $i + 1, StringLen($String))
            $i = $i - 1
         EndIf
      Next
   Else ;it is raw mode, so set up an all-0 modifier array
      Local $Modifiers[StringLen($String) + 1]
   EndIf
   
   ;now send the chars
   $Chr5Index = 1
   For $i = 1 To StringLen($String)
      $char = StringMid($String, $i, 1)
      If $char = Chr(5) Then
         $char = $Chr5[$Chr5Index]
         $Chr5Index = $Chr5Index + 1
      EndIf
      $isUpper = 0
      For $j = 1 To UBound($upper) - 1
         If $char == $upper[$j] Then $isUpper = 1
      Next
      ;1 SHIFT, 2 CTRL, 4 ALT (programmer note to keep the bits straight)
      If $isUpper = 1 Or BitAND($Modifiers[$i], 1) = 1 Then Send("{SHIFTDOWN}")
      If BitAND($Modifiers[$i], 4) = 4 And Not $alt Then $char = "!" & $char
      If BitAND($Modifiers[$i], 2) = 2 And Not $ctrl Then $char = "^" & $char
      If BitAND($Modifiers[$i], 4) = 4 And $alt Then Send("{ALTDOWN}")
      If BitAND($Modifiers[$i], 2) = 2 And $ctrl Then Send("{CTRLDOWN}")
      $ret = ControlSend($Title, $Text, $className, $char, $flag)
      If BitAND($Modifiers[$i], 4) = 4 And $alt Then Send("{ALTUP}")
      If BitAND($Modifiers[$i], 2) = 2 And $ctrl Then Send("{CTRLUP}")
      If $isUpper = 1 Or BitAND($Modifiers[$i], 1) = 1 Then Send("{SHIFTUP}")
      If Not $ret Then Return 0 ;window or control not found
   Next
   Return 1
EndFunc   ;==>ControlSendPlus

Thanks to Pekster and SlimShady for the Coding..... ;)


Saru Mo Ki Kara Ochiru[u]Direct Translation[/u]: Even monkeys will fall from trees.[u]I.E.:[/u] To Error is HumanMy Splash Screen applet: Splash Screen Coding

Share this post


Link to post
Share on other sites

Ok here is something for anyone before you ask....

You need all the Parameters for the line to work so in my case

This is the norm way

ControlSend("C:\WINDOWS\system32\cmd.exe","","", "rconsole{SPACE}" & $servername)

But for ControlSendPlus you need to do it like this.

ControlSendplus("C:\WINDOWS\system32\cmd.exe","","", "rconsole{SPACE}" & $servername,"" )

Ypu MUST have the Flag section Highlighted in red Above, or you get a error

C:\Documents and Settings\tacgt1\My Documents\Stuffs\AutoIT scripts\Auto CSdown V1.2.au3 (74) : ==> Incorrect number of parameters in function call.:

ControlSendplus("C:\WINDOWS\system32\cmd.exe","","", "rconsole{SPACE}" & $servername)


Saru Mo Ki Kara Ochiru[u]Direct Translation[/u]: Even monkeys will fall from trees.[u]I.E.:[/u] To Error is HumanMy Splash Screen applet: Splash Screen Coding

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