Jump to content

Trying to store the ClassName into Variable


Go to solution Solved by 636C65616E,

Recommended Posts

Hello all. 

I'm learning AutoIt and having much fun doing challenges for myself or for some friends. I usually search and follow the topics but I'm with an issue right now trying to get the class name from MSSQL inputs to target and create conditions. 

I don't know if am I doing something really stupid or using _WinAPI_GetClassName doesn't give what I Want. 

I can store into a variable to show into msgbox but, can't use the value to do more things. 

below an example of my script and everytime I got the error :  Undefined Function 

#include ".\bibliotecas\AutoItConstants.au3"
#include ".\bibliotecas\MsgBoxConstants.au3"

Local $user = "Fix"
Local $password = "xxxx"
Local $Domain = "contoso.corp"
Local $server = "SRVNOREAL"
Local $Condition = 0

;Local $iPID =
MSSQL()

Func MSSQL()

   if $Condition = 1 Then

    Global $MSSQL = RunAs($user, $domain, $password, $RUN_LOGON_PROFILE, "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe", "")
    local $hWnd = WinWait("[TITLE:Connect to Server]", "", 0)

     Sleep(200)
     ;limpar campo de servidor
      ControlFocus($hWnd, "", "Edit1")
      Send("{BACKSPACE}")
     ;campo server
     ControlSend($hWnd, "", "Edit1", $Server, 1)
     ;botão connect
     Send('{ENTER}')

   ElseIf $Condition = 0 Then

   Global $MSSQL_LOCAL = Run("C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe")
     Winwait("[TITLE:Connect to Server]", "", 0)
     Global $hWnd
     $hwnd= WinGetHandle("[Active]")
     $classed = _WinAPI_GetClassName($hwnd)
     local $var = WinList("[CLASS:"&$classed&"]")


     MsgBox($MB_OK, "FOk", $Classed)

 EndIf
 EndFunc

 

Sorry if I'm doing something wrong, it's my frist post and don't understand so much. If you guys could send me the right libraries I'll be much thankfull. 

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Pretty much everything is perfectly well described in help file (AutoIt.chm).  Make sure you also download FULL version of Scite.  When you download AutoIt, you only get a light version of the editor.  So you need to get and install full version separately.

Edited by Nine
Link to comment
Share on other sites

I've installed the full version.

The tip that you send worked just fine. But right now I'm getting nuts about how Can I transport the Variable to use into ControlID camp. 

I've tried a lot of methods and the function controlSend seems to not understand. I used msgBOX for debug and see the values and everything is ok. 

Used the String function as well to mix variable of GetClassName. 

I researched for 6 hours but none of the solutions posted worked. Could you help me one more time? example:

 

Global $hWnd = WinWait("[TITLE:Connect to Server]", "", 0)

     Global $Class = _WinAPI_GetClassName($hWnd)
     $AuthBox = String($Class & "3")
    ControlSend($hWnd, "", $AuthBox, "SQL")

   I need to target an ClassnameNN to send string and clicks. Btw I'm trying to automate SQL Managment and the boxes are not static so I must get the classname everytime that program runs and input the instance correctly. 

Thanks again Nine

 

 

Link to comment
Share on other sites

Hey there,

On 8/8/2021 at 3:27 AM, Overthink said:

There's any other tip/advice you have for the script ou some page that gives examples of use?

If you're using the default IDE included with your AutoIt installation: Scite, just press F1 while on a native/default feature and it will open the helper (show you everything you need to know about the feature and some code example most of the time).

For your question: to be honest i dont get exactly what you want to do (why should you send msgs to the gui ?) but anyway the way you're doing it looks suspicious haha

(In a general case, for me, sending inputs to a GUI is the last last last last laaaaaaast option to use when facing a problem: always try to find a way to do it without before. Anyway, sometimes, for automation purpose, it is not doable)

As far as i understand you're trying to find the ControlID of a given Control inside your window, there's a tool inside your default AutoIt installation to help you with that: AU3Info.exe located at the root of your AutoIt installation, or runnable from Scite: tools > Au3Info. You can target a Control/Frame by dragging the target icon onto w/e.

Hope it will help :)

edit:

maybe this is what you're really looking for ^^

Edited by 636C65616E
Link to comment
Share on other sites

Global $MSSQL_LOCAL = Run("C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe")
     ;Winwait("[TITLE:Connect to Server]", "", 0)
     
     $hWnd = WinWait("[TITLE:Connect to Server]", "", 0)

     Global $Class = _WinAPI_GetClassName($hWnd)

      ;limpar campo de servidor
      ControlFocus($hWnd, "", "Edit1"); focus to erase the previous server typed.
      Send("{BACKSPACE}")

      ControlSend($hWnd, "", "Edit1", $Server, 1); Server box "Edit1" is a static classNN 

      Local $Auth = $Class&"3" ;here I try to concatenate with the instance. 
      ControlSend($hWnd, "", $Auth, "SQL") ;Send word SQL justo to target on authentication method to SQL and not Windows Credentials

@Ninesorry about it. As you can see I'm trying to use an function ControlSend with an variable containing the ClassNN and I can't.

@636C65616E That's not suspicious. Let me explain more. The customer needs to automate the login into IDE of some users that they can't know the password for some privilege credentials. So I'll use an CmdLine array to receive those parameters and input into the boxes to login.

I've done already but using !p and Send("{ENTER}")  but I'm pretty sure that is possible to make more secure targeting using the classNN. The problem is IDE everytime you open yhe connect window those ClassNN changes. 

In version 18above of MSSQL they don't accept commandline anymore so I must do it in using the GUI unfortunally. 

I just need to learn a trick to make the variable that receives the winAPI_Get into a "text" to use in ControlID camp of ControlSend. 

 

Thanks again

Link to comment
Share on other sites

By suspicious i meant it was not the correct way to do it.

Did you checked the control with au3info ? Because you are retrieving the Window class_name at the moment, I doubt your control has that class_name in his classnameNN. Sadly I cannot guess this informations (my only guess could be a standard window classname like 'Edit' as it is a text field), so, without au3info there's nothing I can do to help (maybe others can) because I don't use SSMS.

It's not really my concern, but, if you're working for a company (and also if you're not ...), using this kind of method to manage sensitive data is far from secure (especially in AutoIt, as there is no obfuscation at all, and this kind of feature is not the point of the langage).

It is also possible that they are using some custom controls for sensitives data to discourage automation, as noted on the official website, since version 18 they removed the -P arg from the command line, but you still can use the other ones ;) (selecting the server, the db, etc).

edit, some readings :

Edited by 636C65616E
Link to comment
Share on other sites

28 minutes ago, 636C65616E said:

By suspicious i meant it was not the correct way to do it.

Did you checked the control with au3info ? Because you are retrieving the Window class_name at the moment, I doubt your control has that class_name in his classnameNN. Sadly I cannot guess this informations (my only guess could be a standard window classname like 'Edit' as it is a text field), so, without au3info there's nothing I can do to help (maybe others can) because I don't use SSMS.

It's not really my concern, but, if you're working for a company (and also if you're not ...), using this kind of method to manage sensitive data is far from secure (especially in AutoIt, as there is no obfuscation at all, and this kind of feature is not the point of the langage).

It is also possible that they are using some custom controls for sensitives data to discourage automation, as noted on the official website, since version 18 they removed the -P arg from the command line, but you still can use the other ones ;) (selecting the server, the db, etc).

edit, some readings :

I understood whay you've said. The classNN are correct. The same info that function GetClassName retrieves are equal to the info of au3info shows to me. 

The problem is when I wrote in Controlsend manually the target works fine, but If i put an Variable in there to make dynamic...the function seems to not find the target.

Example:

$sAuth = "WindowsForms10.COMBOBOX.app.0.2e87571_r37_ad13"
 ControlSend($hWnd, "", $sAuth, "SQL")

works fine and send SQL into the box. 

But if use the variable that get the same CLASSName even after convert to string doesn't work. 

Global $hWnd = WinWait("[TITLE:Connect to Server]", "", 0)
Local $Class = _WinAPI_GetClassName($hWnd)

   Local $Auth = """"&$Class&"3""" ;Even if I use $Class&"3" Doesn't matter in MSGBOX the string are ok but the function send not work.
   
ControlSend($hWnd, "", $Auth, "SQL")

Fails /\ 

I'm really confused to be honest. I got everything you said but right now I really want to fix this and solve for self acomplish you know? Doesn't matter if they're going to use It's like something I need to learn and understand what's going on xD 

Please help me to solve so I can get a big incentive for my week. 

Thanks 

Link to comment
Share on other sites

  • Solution

try using the 'advanced mode' : "NAME:combo ...." or the ID : 197698, from one version to an other this value may change

edit: side note, double check what your concatenate string is because

Global $hWnd = WinWait("[TITLE:Connect to Server]", "", 0)
Local $Class = _WinAPI_GetClassName($hWnd)

Should return 'WindowsForms10.Window.8.app ........' (the WINDOW class) and you want the class of the control => 'WindowsForms10.COMBOBOX. .......' as i stated in my second message ^^

Edited by 636C65616E
Link to comment
Share on other sites

The _WinAPI_GetClassName($hWnd) returns the class name of the window, not the class name of the combo.  This is why it does not work.  If the combo box name change from one instance to the other you could use the feature [REGEXPCLASS:...] to identify the combo :

ControlSend($hWnd, "", "[REGEXPCLASS:WindowsForms10.COMBOBOX.*]", "SQL")

 

Edited by Nine
Link to comment
Share on other sites

@636C65616EI as able to do it using the Advance MODE. Just to notice if you use RunAs function the Advance mode name goes to change too. 

The name you told for example in your tip are static everytime that you run the SSMS using your account and not RunAs. I don't know if I'm clear. BTW, now I can input the infos right away thanks again for your expertise. 

There's just one last issue with RunAs function that I need to run this command using an credential that never login into the computer wich runs the script. Even putting the flag NOPROFILE the result still the same...no execution. 

@NineSorry about it. I'm going to search for this command you send and ways to use. Thanks again for your attention and expertise. 

Sorry for the delay I was in lunch time here in Brazil xD.

 

BRB 

Link to comment
Share on other sites

On 8/9/2021 at 9:41 PM, Overthink said:

There's just one last issue with RunAs function that I need to run this command using an credential that never login into the computer wich runs the script. Even putting the flag NOPROFILE the result still the same...no execution. 

To be fair, I never played with this before, so I can't help (but we're talking about OS privileges here, so it's not related to SSMS itself: only the Microsoft profile running the programm)

Link to comment
Share on other sites

23 hours ago, 636C65616E said:

To be fair, I never played with this before, so I can't help (but we're talking about OS privileges here, so it's not related to SSMS itself: only the Microsoft profile running the programm)

i've searched in web even in microsoft website and I solved changing RunAs to RunAsWait. So does'nt matter which flag you use(NOPROFILE, PROFILE), they will work. 

The difference between them are the time to run and discover the privileges that account used have. 

I would like to thanks @Nine and you for the support and the attention with me. 

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...