#System.Drawing.Point
Explore tagged Tumblr posts
Text
Hacer click en una posición de la pantalla con PowerShell
$MouseEventSig=@' [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)] public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); '@ $MouseEvent = Add-Type -memberDefinition $MouseEventSig -name "MouseEventWinApi" -passThru [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(10,10)…
View On WordPress
#Add-Type#Drawing#mouse_event#MouseEventWinApi#New-Object#System.Drawing#System.Drawing.Point#System.Windows.Forms.Cursor#user32.dll#Windows
0 notes
Text
MySQL Connect Dialog
About a month ago, I published how you can connect to MySQL with a small form. One suggestion, or lets promote it to a request, from that post was: “Nice, but how do you create a reusable library for the MySQL Connection Dialog box?” That was a good question but I couldn’t get back until now to write a new blog post. This reusable MySQL connection dialog lets you remove MySQL connection data from the command-line history. This post also shows you how to create and test a Powershell Module. The first step to create a module requires that you set the proper %PSModulePath% environment variable. If you fail to do that, you can put it into a default PowerShell module location but that’s not too effective for testing. You launch the System Properties dialog and click the Environment Variables button: Then, you edit the PSModulePath environment variable in the bottom list of environment variables and add a new path to the PSModulePath. My development path in this example is: C:Datacit225mysqlpsmod I named the file the same as the function Get-Credentials.psm1 consistent with the Microsoft instructions for creating a PowerShell module and their instructions for Pascal case name with an approved verb and singular noun. Below is the code for the Get-Credentials.psm1 file: function Get-Credentials { # Add libraries for form components. Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing # Define a user credential form. $form = New-Object System.Windows.Forms.Form $form.Text = 'User Credential Form' $form.Size = New-Object System.Drawing.Size(300,240) $form.StartPosition = 'CenterScreen' # Define a button and assign it and its controls to a form. $loginButton = New-Object System.Windows.Forms.Button $loginButton.Location = New-Object System.Drawing.Point(60,160) $loginButton.Size = New-Object System.Drawing.Size(75,23) $loginButton.Text = 'Login' $loginButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.AcceptButton = $loginButton $form.Controls.Add($loginButton) # Define a button and assign it and its controls to a form. $cancelButton = New-Object System.Windows.Forms.Button $cancelButton.Location = New-Object System.Drawing.Point(155,160) $cancelButton.Size = New-Object System.Drawing.Size(75,23) $cancelButton.Text = 'Cancel' $cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.CancelButton = $cancelButton $form.Controls.Add($cancelButton) # Define a label and assign it and its controls to a form. $userLabel = New-Object System.Windows.Forms.Label $userLabel.Location = New-Object System.Drawing.Point(30,15) $userLabel.Size = New-Object System.Drawing.Size(100,20) $userLabel.Text = 'Enter User Name:' $form.Controls.Add($userLabel) # Define a TextBox and assign it and its controls to a form. $userTextBox = New-Object System.Windows.Forms.TextBox $userTextBox.Location = New-Object System.Drawing.Point(140,15) $userTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($userTextBox) # Define a label and assign it and its controls to a form. $pwdLabel = New-Object System.Windows.Forms.Label $pwdLabel.Location = New-Object System.Drawing.Point(30,40) $pwdLabel.Size = New-Object System.Drawing.Size(100,20) $pwdLabel.Text = 'Enter Password:' $form.Controls.Add($pwdLabel) # Define a TextBox and assign it and its controls to a form. $pwdTextBox = New-Object System.Windows.Forms.TextBox $pwdTextBox.Location = New-Object System.Drawing.Point(140,40) $pwdTextBox.Size = New-Object System.Drawing.Size(100,20) $pwdTextBox.PasswordChar = "*" $form.Controls.Add($pwdTextBox) # Define a label and assign it and its controls to a form. $hostLabel = New-Object System.Windows.Forms.Label $hostLabel.Location = New-Object System.Drawing.Point(30,65) $hostLabel.Size = New-Object System.Drawing.Size(100,20) $hostLabel.Text = 'Enter Hostname:' $form.Controls.Add($hostLabel) # Define a TextBox and assign it and its controls to a form. $hostTextBox = New-Object System.Windows.Forms.TextBox $hostTextBox.Location = New-Object System.Drawing.Point(140,65) $hostTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($hostTextBox) # Define a label and assign it and its controls to a form. $portLabel = New-Object System.Windows.Forms.Label $portLabel.Location = New-Object System.Drawing.Point(30,90) $portLabel.Size = New-Object System.Drawing.Size(100,20) $portLabel.Text = 'Enter Port #:' $form.Controls.Add($portLabel) # Define a TextBox and assign it and its controls to a form. $portTextBox = New-Object System.Windows.Forms.TextBox $portTextBox.Location = New-Object System.Drawing.Point(140,90) $portTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($portTextBox) # Define a label and assign it and its controls to a form. $dbLabel = New-Object System.Windows.Forms.Label $dbLabel.Location = New-Object System.Drawing.Point(30,115) $dbLabel.Size = New-Object System.Drawing.Size(100,20) $dbLabel.Text = 'Enter DB Name:' $form.Controls.Add($dbLabel) # Define a TextBox and assign it and its controls to a form. $dbTextBox = New-Object System.Windows.Forms.TextBox $dbTextBox.Location = New-Object System.Drawing.Point(140,115) $dbTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($dbTextBox) $form.Topmost = $true $form.Add_Shown({$userTextBox.Select()}) $result = $form.ShowDialog() if ($result -eq [System.Windows.Forms.DialogResult]::OK) { # Assign inputs to connection variables. $uid = $userTextBox.Text $pwd = $pwdTextBox.Text $server = $hostTextBox.Text $port= $portTextBox.Text $dbName = $dbTextBox.Text # Declare connection string. $credentials = 'server=' + $server + ';port=' + $port + ';uid=' + $uid + ';pwd=' + $pwd + ';database=' + $dbName } else { $credentials = $null } return $credentials } You must create a Get-Connection directory in your C:Datacit225mysqlpsmod directory that you added to the PSModulePath. Then, you must put your module code in the Get-Connection subdirectory as the Get-Connection.psm1 module file. The test.ps1 script imports the Get-Credentials.psm1 PowerShell module, launches the MySQL Connection Dialog form and returns the connection string. The test.ps1 code is: # Import your custom module. Import-Module Get-Credentials # Test the Get-Credentials function. if (($credentials = Get-Credentials) -ne $undefinedVariable) { Write-Host($credentials) } You can test it from the local any directory with the following command-line: powershell .test.ps1 It should print something like this to the console: server=localhost;port=3306;uid=student;pwd=student;database=studentdb If you got this far, that’s great! You’re ready to test a connection to the MySQL database. Before you do that, you should create the same avenger table I used in the initial post and insert the same or some additional data. Connect to the any of your test databases and rung the following code to create the avenger table and nine rows of data. -- Create the avenger table. CREATE TABLE db_connect ( db_connect_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT , version VARCHAR(10) , user VARCHAR(24) , db_name VARCHAR(10)); -- Seed the avenger table with data. INSERT INTO avenger ( first_name, last_name, avenger ) VALUES ('Anthony', 'Stark', 'Iron Man') ,('Thor', 'Odinson', 'God of Thunder') ,('Steven', 'Rogers', 'Captain America') ,('Bruce', 'Banner', 'Hulk') ,('Clinton', 'Barton', 'Hawkeye') ,('Natasha', 'Romanoff', 'Black Widow') ,('Peter', 'Parker', 'Spiderman') ,('Steven', 'Strange', 'Dr. Strange') ,('Scott', 'Lange', 'Ant-man'); Now, let’s promote our use-case test.ps1 script to a testQuery.ps1 script, like: # Import your custom module. Import-Module Get-Credentials # Test the Get-Credentials function. if (($credentials = Get-Credentials) -ne $undefinedVariable) { # Connect to the libaray MySQL.Data.dll Add-Type -Path 'C:Program Files (x86)MySQLConnector NET 8.0Assembliesv4.5.2MySql.Data.dll' # Create a MySQL Database connection variable that qualifies: # [Driver]@ConnectionString # ============================================================ # You can assign the connection string before using it or # while using it, which is what we do below by assigning # literal values for the following names: # - server= or 127.0.0.1 for localhost # - uid= # - pwd= # - port= or 3306 for default port # - database= # ============================================================ $Connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString=$credentials} $Connection.Open() # Define a MySQL Command Object for a non-query. $sqlCommand = New-Object MySql.Data.MySqlClient.MySqlCommand $sqlDataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter $sqlDataSet = New-Object System.Data.DataSet # Assign the connection and command text to the MySQL command object. $sqlCommand.Connection = $Connection $sqlCommand.CommandText = 'SELECT CONCAT(first_name," ",last_name) AS full_name ' + ', avenger ' + 'FROM avenger' # Assign the connection and command text to the query method of # the data adapter object. $sqlDataAdapter.SelectCommand=$sqlCommand # Assign the tuples of data to a data set and return the number of rows fetched. $rowsFetched=$sqlDataAdapter.Fill($sqlDataSet, "data") # Print to console the data returned from the query. foreach($row in $sqlDataSet.tables[0]) { write-host "Avenger:" $row.avenger "is" $row.full_name } # Close the MySQL connection. $Connection.Close() } It should give you the MySQL Connection Dialog and with the correct credentials print the following to your console: Avenger: Iron Man is Anthony Stark Avenger: God of Thunder is Thor Odinson Avenger: Captain America is Steven Rogers Avenger: Hulk is Bruce Banner Avenger: Hawkeye is Clinton Barton Avenger: Black Widow is Natasha Romanoff Avenger: Spiderman is Peter Parker Avenger: Dr. Strange is Steven Strange Avenger: Ant-man is Scott Lange As always, I hope this helps those looking to exploit technology. https://blog.mclaughlinsoftware.com/2021/05/21/mysql-connect-dialog/
0 notes
Text
Form1.Designer.cs
namespace Project1 { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Windows Form Designer generated code
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.panel1 = new System.Windows.Forms.Panel(); this.lblTime = new System.Windows.Forms.Label(); this.lblStaticTime = new System.Windows.Forms.Label(); this.lblNumGuess = new System.Windows.Forms.Label(); this.lblStaticNumGuess = new System.Windows.Forms.Label(); this.card_3_6 = new System.Windows.Forms.Button(); this.card_3_5 = new System.Windows.Forms.Button(); this.card_3_7 = new System.Windows.Forms.Button(); this.card_3_4 = new System.Windows.Forms.Button(); this.card_3_3 = new System.Windows.Forms.Button(); this.card_3_2 = new System.Windows.Forms.Button(); this.card_3_1 = new System.Windows.Forms.Button(); this.card_3_0 = new System.Windows.Forms.Button(); this.card_2_6 = new System.Windows.Forms.Button(); this.card_2_5 = new System.Windows.Forms.Button(); this.card_2_7 = new System.Windows.Forms.Button(); this.card_2_4 = new System.Windows.Forms.Button(); this.card_2_3 = new System.Windows.Forms.Button(); this.card_2_2 = new System.Windows.Forms.Button(); this.card_2_1 = new System.Windows.Forms.Button(); this.card_2_0 = new System.Windows.Forms.Button(); this.card_1_6 = new System.Windows.Forms.Button(); this.card_1_5 = new System.Windows.Forms.Button(); this.card_1_7 = new System.Windows.Forms.Button(); this.card_1_4 = new System.Windows.Forms.Button(); this.card_1_3 = new System.Windows.Forms.Button(); this.card_1_2 = new System.Windows.Forms.Button(); this.card_1_1 = new System.Windows.Forms.Button(); this.card_1_0 = new System.Windows.Forms.Button(); this.card_0_6 = new System.Windows.Forms.Button(); this.card_0_5 = new System.Windows.Forms.Button(); this.card_0_7 = new System.Windows.Forms.Button(); this.card_0_4 = new System.Windows.Forms.Button(); this.card_0_3 = new System.Windows.Forms.Button(); this.card_0_2 = new System.Windows.Forms.Button(); this.card_0_1 = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.card_0_0 = new System.Windows.Forms.Button(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // panel1 // this.panel1.BackColor = System.Drawing.Color.Black; this.panel1.Controls.Add(this.lblTime); this.panel1.Controls.Add(this.lblStaticTime); this.panel1.Controls.Add(this.lblNumGuess); this.panel1.Controls.Add(this.lblStaticNumGuess); this.panel1.Location = new System.Drawing.Point(-3, 644); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(931, 66); this.panel1.TabIndex = 2; // // lblTime // this.lblTime.AutoSize = true; this.lblTime.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblTime.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); this.lblTime.Location = new System.Drawing.Point(712, 18); this.lblTime.Name = "lblTime"; this.lblTime.Size = new System.Drawing.Size(0, 24); this.lblTime.TabIndex = 3; // // lblStaticTime // this.lblStaticTime.AutoSize = true; this.lblStaticTime.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblStaticTime.ForeColor = System.Drawing.Color.White; this.lblStaticTime.Location = new System.Drawing.Point(523, 18); this.lblStaticTime.Name = "lblStaticTime"; this.lblStaticTime.Size = new System.Drawing.Size(84, 24); this.lblStaticTime.TabIndex = 2; this.lblStaticTime.Text = "Time (s):"; // // lblNumGuess // this.lblNumGuess.AutoSize = true; this.lblNumGuess.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblNumGuess.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); this.lblNumGuess.Location = new System.Drawing.Point(215, 18); this.lblNumGuess.Name = "lblNumGuess"; this.lblNumGuess.Size = new System.Drawing.Size(0, 24); this.lblNumGuess.TabIndex = 1; // // lblStaticNumGuess // this.lblStaticNumGuess.AutoSize = true; this.lblStaticNumGuess.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblStaticNumGuess.ForeColor = System.Drawing.Color.White; this.lblStaticNumGuess.Location = new System.Drawing.Point(26, 18); this.lblStaticNumGuess.Name = "lblStaticNumGuess"; this.lblStaticNumGuess.Size = new System.Drawing.Size(183, 24); this.lblStaticNumGuess.TabIndex = 0; this.lblStaticNumGuess.Text = "Number of Guesses:"; // // card_3_6 // this.card_3_6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_6.BackgroundImage"))); this.card_3_6.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_6.Location = new System.Drawing.Point(685, 509); this.card_3_6.Name = "card_3_6"; this.card_3_6.Size = new System.Drawing.Size(90, 100); this.card_3_6.TabIndex = 33; this.card_3_6.Text = " "; this.card_3_6.UseVisualStyleBackColor = true; this.card_3_6.Click += new System.EventHandler(this.card_Click); // // card_3_5 // this.card_3_5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_5.BackgroundImage"))); this.card_3_5.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_5.Location = new System.Drawing.Point(578, 509); this.card_3_5.Name = "card_3_5"; this.card_3_5.Size = new System.Drawing.Size(90, 100); this.card_3_5.TabIndex = 31; this.card_3_5.Text = " "; this.card_3_5.UseVisualStyleBackColor = true; this.card_3_5.Click += new System.EventHandler(this.card_Click); // // card_3_7 // this.card_3_7.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_7.BackgroundImage"))); this.card_3_7.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_7.Location = new System.Drawing.Point(792, 509); this.card_3_7.Name = "card_3_7"; this.card_3_7.Size = new System.Drawing.Size(90, 100); this.card_3_7.TabIndex = 32; this.card_3_7.Text = " "; this.card_3_7.UseVisualStyleBackColor = true; this.card_3_7.Click += new System.EventHandler(this.card_Click); // // card_3_4 // this.card_3_4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_4.BackgroundImage"))); this.card_3_4.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_4.Location = new System.Drawing.Point(471, 509); this.card_3_4.Name = "card_3_4"; this.card_3_4.Size = new System.Drawing.Size(90, 100); this.card_3_4.TabIndex = 30; this.card_3_4.Text = " "; this.card_3_4.UseVisualStyleBackColor = true; this.card_3_4.Click += new System.EventHandler(this.card_Click); // // card_3_3 // this.card_3_3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_3.BackgroundImage"))); this.card_3_3.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_3.Location = new System.Drawing.Point(364, 509); this.card_3_3.Name = "card_3_3"; this.card_3_3.Size = new System.Drawing.Size(90, 100); this.card_3_3.TabIndex = 29; this.card_3_3.Text = " "; this.card_3_3.UseVisualStyleBackColor = true; this.card_3_3.Click += new System.EventHandler(this.card_Click); // // card_3_2 // this.card_3_2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_2.BackgroundImage"))); this.card_3_2.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_2.Location = new System.Drawing.Point(257, 509); this.card_3_2.Name = "card_3_2"; this.card_3_2.Size = new System.Drawing.Size(90, 100); this.card_3_2.TabIndex = 28; this.card_3_2.Text = " "; this.card_3_2.UseVisualStyleBackColor = true; this.card_3_2.Click += new System.EventHandler(this.card_Click); // // card_3_1 // this.card_3_1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_1.BackgroundImage"))); this.card_3_1.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_1.Location = new System.Drawing.Point(150, 509); this.card_3_1.Name = "card_3_1"; this.card_3_1.Size = new System.Drawing.Size(90, 100); this.card_3_1.TabIndex = 27; this.card_3_1.Text = " "; this.card_3_1.UseVisualStyleBackColor = true; this.card_3_1.Click += new System.EventHandler(this.card_Click); // // card_3_0 // this.card_3_0.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_3_0.BackgroundImage"))); this.card_3_0.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_3_0.Location = new System.Drawing.Point(43, 509); this.card_3_0.Name = "card_3_0"; this.card_3_0.Size = new System.Drawing.Size(90, 100); this.card_3_0.TabIndex = 26; this.card_3_0.Text = " "; this.card_3_0.UseVisualStyleBackColor = true; �� this.card_3_0.Click += new System.EventHandler(this.card_Click); // // card_2_6 // this.card_2_6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_6.BackgroundImage"))); this.card_2_6.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_6.Location = new System.Drawing.Point(685, 393); this.card_2_6.Name = "card_2_6"; this.card_2_6.Size = new System.Drawing.Size(90, 100); this.card_2_6.TabIndex = 25; this.card_2_6.Text = " "; this.card_2_6.UseVisualStyleBackColor = true; this.card_2_6.Click += new System.EventHandler(this.card_Click); // // card_2_5 // this.card_2_5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_5.BackgroundImage"))); this.card_2_5.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_5.Location = new System.Drawing.Point(578, 393); this.card_2_5.Name = "card_2_5"; this.card_2_5.Size = new System.Drawing.Size(90, 100); this.card_2_5.TabIndex = 23; this.card_2_5.Text = " "; this.card_2_5.UseVisualStyleBackColor = true; this.card_2_5.Click += new System.EventHandler(this.card_Click); // // card_2_7 // this.card_2_7.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_7.BackgroundImage"))); this.card_2_7.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_7.Location = new System.Drawing.Point(792, 393); this.card_2_7.Name = "card_2_7"; this.card_2_7.Size = new System.Drawing.Size(90, 100); this.card_2_7.TabIndex = 24; this.card_2_7.Text = " "; this.card_2_7.UseVisualStyleBackColor = true; this.card_2_7.Click += new System.EventHandler(this.card_Click); // // card_2_4 // this.card_2_4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_4.BackgroundImage"))); this.card_2_4.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_4.Location = new System.Drawing.Point(471, 393); this.card_2_4.Name = "card_2_4"; this.card_2_4.Size = new System.Drawing.Size(90, 100); this.card_2_4.TabIndex = 22; this.card_2_4.Text = " "; this.card_2_4.UseVisualStyleBackColor = true; this.card_2_4.Click += new System.EventHandler(this.card_Click); // // card_2_3 // this.card_2_3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_3.BackgroundImage"))); this.card_2_3.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_3.Location = new System.Drawing.Point(364, 393); this.card_2_3.Name = "card_2_3"; this.card_2_3.Size = new System.Drawing.Size(90, 100); this.card_2_3.TabIndex = 21; this.card_2_3.Text = " "; this.card_2_3.UseVisualStyleBackColor = true; this.card_2_3.Click += new System.EventHandler(this.card_Click); // // card_2_2 // this.card_2_2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_2.BackgroundImage"))); this.card_2_2.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_2.Location = new System.Drawing.Point(257, 393); this.card_2_2.Name = "card_2_2"; this.card_2_2.Size = new System.Drawing.Size(90, 100); this.card_2_2.TabIndex = 20; this.card_2_2.Text = " "; this.card_2_2.UseVisualStyleBackColor = true; this.card_2_2.Click += new System.EventHandler(this.card_Click); // // card_2_1 // this.card_2_1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_1.BackgroundImage"))); this.card_2_1.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_1.Location = new System.Drawing.Point(150, 393); this.card_2_1.Name = "card_2_1"; this.card_2_1.Size = new System.Drawing.Size(90, 100); this.card_2_1.TabIndex = 19; this.card_2_1.Text = " "; this.card_2_1.UseVisualStyleBackColor = true; this.card_2_1.Click += new System.EventHandler(this.card_Click); // // card_2_0 // this.card_2_0.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_2_0.BackgroundImage"))); this.card_2_0.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_2_0.Location = new System.Drawing.Point(43, 393); this.card_2_0.Name = "card_2_0"; this.card_2_0.Size = new System.Drawing.Size(90, 100); this.card_2_0.TabIndex = 18; this.card_2_0.Text = " "; this.card_2_0.UseVisualStyleBackColor = true; this.card_2_0.Click += new System.EventHandler(this.card_Click); // // card_1_6 // this.card_1_6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_6.BackgroundImage"))); this.card_1_6.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_6.Location = new System.Drawing.Point(685, 277); this.card_1_6.Name = "card_1_6"; this.card_1_6.Size = new System.Drawing.Size(90, 100); this.card_1_6.TabIndex = 17; this.card_1_6.Text = " "; this.card_1_6.UseVisualStyleBackColor = true; this.card_1_6.Click += new System.EventHandler(this.card_Click); // // card_1_5 // this.card_1_5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_5.BackgroundImage"))); this.card_1_5.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_5.Location = new System.Drawing.Point(578, 277); this.card_1_5.Name = "card_1_5"; this.card_1_5.Size = new System.Drawing.Size(90, 100); this.card_1_5.TabIndex = 15; this.card_1_5.Text = " "; this.card_1_5.UseVisualStyleBackColor = true; this.card_1_5.Click += new System.EventHandler(this.card_Click); // // card_1_7 // this.card_1_7.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_7.BackgroundImage"))); this.card_1_7.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_7.Location = new System.Drawing.Point(792, 277); this.card_1_7.Name = "card_1_7"; this.card_1_7.Size = new System.Drawing.Size(90, 100); this.card_1_7.TabIndex = 16; this.card_1_7.Text = " "; this.card_1_7.UseVisualStyleBackColor = true; this.card_1_7.Click += new System.EventHandler(this.card_Click); // // card_1_4 // this.card_1_4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_4.BackgroundImage"))); this.card_1_4.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_4.Location = new System.Drawing.Point(471, 277); this.card_1_4.Name = "card_1_4"; this.card_1_4.Size = new System.Drawing.Size(90, 100); this.card_1_4.TabIndex = 14; this.card_1_4.Text = " "; this.card_1_4.UseVisualStyleBackColor = true; this.card_1_4.Click += new System.EventHandler(this.card_Click); // // card_1_3 // this.card_1_3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_3.BackgroundImage"))); this.card_1_3.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_3.Location = new System.Drawing.Point(364, 277); this.card_1_3.Name = "card_1_3"; this.card_1_3.Size = new System.Drawing.Size(90, 100); this.card_1_3.TabIndex = 13; this.card_1_3.Text = " "; this.card_1_3.UseVisualStyleBackColor = true; this.card_1_3.Click += new System.EventHandler(this.card_Click); // // card_1_2 // this.card_1_2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_2.BackgroundImage"))); this.card_1_2.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_2.Location = new System.Drawing.Point(257, 277); this.card_1_2.Name = "card_1_2"; this.card_1_2.Size = new System.Drawing.Size(90, 100); this.card_1_2.TabIndex = 12; this.card_1_2.Text = " "; this.card_1_2.UseVisualStyleBackColor = true; this.card_1_2.Click += new System.EventHandler(this.card_Click); // // card_1_1 // this.card_1_1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_1.BackgroundImage"))); this.card_1_1.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_1.Location = new System.Drawing.Point(150, 277); this.card_1_1.Name = "card_1_1"; this.card_1_1.Size = new System.Drawing.Size(90, 100); this.card_1_1.TabIndex = 11; this.card_1_1.Text = " "; this.card_1_1.UseVisualStyleBackColor = true; this.card_1_1.Click += new System.EventHandler(this.card_Click); // // card_1_0 // this.card_1_0.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_1_0.BackgroundImage"))); this.card_1_0.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_1_0.Location = new System.Drawing.Point(43, 277); this.card_1_0.Name = "card_1_0"; this.card_1_0.Size = new System.Drawing.Size(90, 100); this.card_1_0.TabIndex = 10; this.card_1_0.Text = " "; this.card_1_0.UseVisualStyleBackColor = true; this.card_1_0.Click += new System.EventHandler(this.card_Click); // // card_0_6 // this.card_0_6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_6.BackgroundImage"))); this.card_0_6.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_6.Location = new System.Drawing.Point(685, 161); this.card_0_6.Name = "card_0_6"; this.card_0_6.Size = new System.Drawing.Size(90, 100); this.card_0_6.TabIndex = 9; this.card_0_6.Text = " "; this.card_0_6.UseVisualStyleBackColor = true; this.card_0_6.Click += new System.EventHandler(this.card_Click); // // card_0_5 // this.card_0_5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_5.BackgroundImage"))); this.card_0_5.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_5.Location = new System.Drawing.Point(578, 161); this.card_0_5.Name = "card_0_5"; this.card_0_5.Size = new System.Drawing.Size(90, 100); this.card_0_5.TabIndex = 8; this.card_0_5.Text = " "; this.card_0_5.UseVisualStyleBackColor = true; this.card_0_5.Click += new System.EventHandler(this.card_Click); // // card_0_7 // this.card_0_7.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_7.BackgroundImage"))); this.card_0_7.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_7.Location = new System.Drawing.Point(792, 161); this.card_0_7.Name = "card_0_7"; this.card_0_7.Size = new System.Drawing.Size(90, 100); this.card_0_7.TabIndex = 8; this.card_0_7.Text = " "; this.card_0_7.UseVisualStyleBackColor = true; this.card_0_7.Click += new System.EventHandler(this.card_Click); // // card_0_4 // this.card_0_4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_4.BackgroundImage"))); this.card_0_4.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_4.Location = new System.Drawing.Point(471, 161); this.card_0_4.Name = "card_0_4"; this.card_0_4.Size = new System.Drawing.Size(90, 100); this.card_0_4.TabIndex = 7; this.card_0_4.Text = " "; this.card_0_4.UseVisualStyleBackColor = true; this.card_0_4.Click += new System.EventHandler(this.card_Click); // // card_0_3 // this.card_0_3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_3.BackgroundImage"))); �� this.card_0_3.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_3.Location = new System.Drawing.Point(364, 161); this.card_0_3.Name = "card_0_3"; this.card_0_3.Size = new System.Drawing.Size(90, 100); this.card_0_3.TabIndex = 6; this.card_0_3.Text = " "; this.card_0_3.UseVisualStyleBackColor = true; this.card_0_3.Click += new System.EventHandler(this.card_Click); // // card_0_2 // this.card_0_2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_2.BackgroundImage"))); this.card_0_2.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_2.Location = new System.Drawing.Point(257, 161); this.card_0_2.Name = "card_0_2"; this.card_0_2.Size = new System.Drawing.Size(90, 100); this.card_0_2.TabIndex = 5; this.card_0_2.Text = " "; this.card_0_2.UseVisualStyleBackColor = true; this.card_0_2.Click += new System.EventHandler(this.card_Click); // // card_0_1 // this.card_0_1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_1.BackgroundImage"))); this.card_0_1.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_1.Location = new System.Drawing.Point(150, 161); this.card_0_1.Name = "card_0_1"; this.card_0_1.Size = new System.Drawing.Size(90, 100); this.card_0_1.TabIndex = 4; this.card_0_1.Text = " "; this.card_0_1.UseVisualStyleBackColor = true; this.card_0_1.Click += new System.EventHandler(this.card_Click); // // pictureBox1 // this.pictureBox1.BackgroundImage = global::Project1.Properties.Resources.memory; this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pictureBox1.Location = new System.Drawing.Point(208, 12); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(495, 125); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 3; this.pictureBox1.TabStop = false; // // card_0_0 // this.card_0_0.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("card_0_0.BackgroundImage"))); this.card_0_0.Font = new System.Drawing.Font("Arial", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.card_0_0.Location = new System.Drawing.Point(43, 161); this.card_0_0.Name = "card_0_0"; this.card_0_0.Size = new System.Drawing.Size(90, 100); this.card_0_0.TabIndex = 0; this.card_0_0.Text = " "; this.card_0_0.UseVisualStyleBackColor = true; this.card_0_0.Click += new System.EventHandler(this.card_Click); // // Form1 // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.ClientSize = new System.Drawing.Size(925, 705); this.Controls.Add(this.card_3_6); this.Controls.Add(this.card_3_5); this.Controls.Add(this.card_3_7); this.Controls.Add(this.card_3_4); this.Controls.Add(this.card_3_3); this.Controls.Add(this.card_3_2); this.Controls.Add(this.card_3_1); this.Controls.Add(this.card_3_0); this.Controls.Add(this.card_2_6); this.Controls.Add(this.card_2_5); this.Controls.Add(this.card_2_7); this.Controls.Add(this.card_2_4); this.Controls.Add(this.card_2_3); this.Controls.Add(this.card_2_2); this.Controls.Add(this.card_2_1); this.Controls.Add(this.card_2_0); this.Controls.Add(this.card_1_6); this.Controls.Add(this.card_1_5); this.Controls.Add(this.card_1_7); this.Controls.Add(this.card_1_4); this.Controls.Add(this.card_1_3); this.Controls.Add(this.card_1_2); this.Controls.Add(this.card_1_1); this.Controls.Add(this.card_1_0); this.Controls.Add(this.card_0_6); this.Controls.Add(this.card_0_5); this.Controls.Add(this.card_0_7); this.Controls.Add(this.card_0_4); this.Controls.Add(this.card_0_3); this.Controls.Add(this.card_0_2); this.Controls.Add(this.card_0_1); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.panel1); this.Controls.Add(this.card_0_0); this.Name = "Form1"; this.Text = "Form1"; this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button card_0_0; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button card_0_1; private System.Windows.Forms.Button card_0_2; private System.Windows.Forms.Button card_0_3; private System.Windows.Forms.Button card_0_4; private System.Windows.Forms.Button card_0_7; private System.Windows.Forms.Button card_0_5; private System.Windows.Forms.Button card_0_6; private System.Windows.Forms.Button card_1_6; private System.Windows.Forms.Button card_1_5; private System.Windows.Forms.Button card_1_7; private System.Windows.Forms.Button card_1_4; private System.Windows.Forms.Button card_1_3; private System.Windows.Forms.Button card_1_2; private System.Windows.Forms.Button card_1_1; private System.Windows.Forms.Button card_1_0; private System.Windows.Forms.Button card_2_6; private System.Windows.Forms.Button card_2_5; private System.Windows.Forms.Button card_2_7; private System.Windows.Forms.Button card_2_4; private System.Windows.Forms.Button card_2_3; private System.Windows.Forms.Button card_2_2; private System.Windows.Forms.Button card_2_1; private System.Windows.Forms.Button card_2_0; private System.Windows.Forms.Button card_3_6; private System.Windows.Forms.Button card_3_5; private System.Windows.Forms.Button card_3_7; private System.Windows.Forms.Button card_3_4; private System.Windows.Forms.Button card_3_3; private System.Windows.Forms.Button card_3_2; private System.Windows.Forms.Button card_3_1; private System.Windows.Forms.Button card_3_0; private System.Windows.Forms.Label lblTime; private System.Windows.Forms.Label lblStaticTime; private System.Windows.Forms.Label lblNumGuess; private System.Windows.Forms.Label lblStaticNumGuess; } }
0 notes
Text
Mover el ratón a una posición de la pantalla y hacer click con PowerShell
Mover el ratón a una posición de la pantalla y hacer click con PowerShell
$MouseEventSig=@' [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)] public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); '@ $MouseEvent = Add-Type -memberDefinition $MouseEventSig -name "MouseEventWinApi" -passThru [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(100,100)…
View On WordPress
#Add-Type#Drawing#mouse_event#MouseEventWinApi#New-Object#System.Drawing#System.Drawing.Point#System.Windows.Forms.Cursor#user32.dll#Windows
0 notes
Text
Mover el ratón a una posición de la pantalla con PowerShell
Mover el ratón a una posición de la pantalla con PowerShell
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(100,100)
View On WordPress
0 notes
Text
MySQL+Credentials
The first tutorial supplementing the MySQL Connector/NET Developer Guide showed you how to connect and run static INSERT statement. It was a barebones PowerShell script with the MySQL Connector. This post shows you how to run a PowerShell script that uses a dynamic form to gather the MySQL credentials and then run a static query. Below is the MySQL Credentials form. You enter the correct user name, password, hostname (or IP address), port, and database, like this: Here’s the complete code for this staticQuery.ps1 PowerShell script: # Add libraries for form components. Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing # Define a user credential form. $form = New-Object System.Windows.Forms.Form $form.Text = 'User Credential Form' $form.Size = New-Object System.Drawing.Size(300,240) $form.StartPosition = 'CenterScreen' # Define a button and assign it and its controls to a form. $loginButton = New-Object System.Windows.Forms.Button $loginButton.Location = New-Object System.Drawing.Point(60,160) $loginButton.Size = New-Object System.Drawing.Size(75,23) $loginButton.Text = 'Login' $loginButton.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.AcceptButton = $loginButton $form.Controls.Add($loginButton) # Define a button and assign it and its controls to a form. $cancelButton = New-Object System.Windows.Forms.Button $cancelButton.Location = New-Object System.Drawing.Point(155,160) $cancelButton.Size = New-Object System.Drawing.Size(75,23) $cancelButton.Text = 'Cancel' $cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.CancelButton = $cancelButton $form.Controls.Add($cancelButton) # Define a label and assign it and its controls to a form. $userLabel = New-Object System.Windows.Forms.Label $userLabel.Location = New-Object System.Drawing.Point(30,15) $userLabel.Size = New-Object System.Drawing.Size(100,20) $userLabel.Text = 'Enter User Name:' $form.Controls.Add($userLabel) # Define a TextBox and assign it and its controls to a form. $userTextBox = New-Object System.Windows.Forms.TextBox $userTextBox.Location = New-Object System.Drawing.Point(140,15) $userTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($userTextBox) # Define a label and assign it and its controls to a form. $pwdLabel = New-Object System.Windows.Forms.Label $pwdLabel.Location = New-Object System.Drawing.Point(30,40) $pwdLabel.Size = New-Object System.Drawing.Size(100,20) $pwdLabel.Text = 'Enter Password:' $form.Controls.Add($pwdLabel) # Define a TextBox and assign it and its controls to a form. $pwdTextBox = New-Object System.Windows.Forms.TextBox $pwdTextBox.Location = New-Object System.Drawing.Point(140,40) $pwdTextBox.Size = New-Object System.Drawing.Size(100,20) $pwdTextBox.PasswordChar = "*" $form.Controls.Add($pwdTextBox) # Define a label and assign it and its controls to a form. $hostLabel = New-Object System.Windows.Forms.Label $hostLabel.Location = New-Object System.Drawing.Point(30,65) $hostLabel.Size = New-Object System.Drawing.Size(100,20) $hostLabel.Text = 'Enter Hostname:' $form.Controls.Add($hostLabel) # Define a TextBox and assign it and its controls to a form. $hostTextBox = New-Object System.Windows.Forms.TextBox $hostTextBox.Location = New-Object System.Drawing.Point(140,65) $hostTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($hostTextBox) # Define a label and assign it and its controls to a form. $portLabel = New-Object System.Windows.Forms.Label $portLabel.Location = New-Object System.Drawing.Point(30,90) $portLabel.Size = New-Object System.Drawing.Size(100,20) $portLabel.Text = 'Enter Port #:' $form.Controls.Add($portLabel) # Define a TextBox and assign it and its controls to a form. $portTextBox = New-Object System.Windows.Forms.TextBox $portTextBox.Location = New-Object System.Drawing.Point(140,90) $portTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($portTextBox) # Define a label and assign it and its controls to a form. $dbLabel = New-Object System.Windows.Forms.Label $dbLabel.Location = New-Object System.Drawing.Point(30,115) $dbLabel.Size = New-Object System.Drawing.Size(100,20) $dbLabel.Text = 'Enter DB Name:' $form.Controls.Add($dbLabel) # Define a TextBox and assign it and its controls to a form. $dbTextBox = New-Object System.Windows.Forms.TextBox $dbTextBox.Location = New-Object System.Drawing.Point(140,115) $dbTextBox.Size = New-Object System.Drawing.Size(100,20) $form.Controls.Add($dbTextBox) $form.Topmost = $true $form.Add_Shown({$userTextBox.Select()}) $result = $form.ShowDialog() if ($result -eq [System.Windows.Forms.DialogResult]::OK) { # Assign inputs to connection variables. $uid = $userTextBox.Text $pwd = $pwdTextBox.Text $server = $hostTextBox.Text $port= $portTextBox.Text $dbName = $dbTextBox.Text # Declare connection string. $credentials = 'server=' + $server + ';port=' + $port + ';uid=' + $uid + ';pwd=' + $pwd + ';database=' + $dbName # Connect to the libaray MySQL.Data.dll Add-Type -Path 'C:Program Files (x86)MySQLConnector NET 8.0Assembliesv4.5.2MySql.Data.dll' # Create a MySQL Database connection variable that qualifies: # [Driver]@ConnectionString # ============================================================ # You can assign the connection string before using it or # while using it, which is what we do below by assigning # literal values for the following names: # - server= or 127.0.0.1 for localhost # - port= # - uid= # - pwd= # - database= # ============================================================ $Connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString=$credentials} $Connection.Open() # Define a MySQL Command Object for a non-query. $sqlCommand = New-Object MySql.Data.MySqlClient.MySqlCommand $sqlDataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter $sqlDataSet = New-Object System.Data.DataSet # Assign the connection and command text to the MySQL command object. $sqlCommand.Connection = $Connection $sqlCommand.CommandText = 'SELECT CONCAT(first_name," ",last_name) AS full_name ' + ', avenger ' + 'FROM avenger' # Assign the connection and command text to the query method of # the data adapter object. $sqlDataAdapter.SelectCommand=$sqlCommand # Assign the tuples of data to a data set and return the number of rows fetched. $rowsFetched=$sqlDataAdapter.Fill($sqlDataSet, "data") # Print to console the data returned from the query. foreach($row in $sqlDataSet.tables[0]) { write-host "Avenger:" $row.avenger "is" $row.full_name } # Close the MySQL connection. $Connection.Close() } I created an avenger table and populated it with six rows of data: -- Create the avenger table. CREATE TABLE db_connect ( db_connect_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT , version VARCHAR(10) , user VARCHAR(24) , db_name VARCHAR(10)); -- Seed the avenger table with data. INSERT INTO avenger ( first_name, last_name, avenger ) VALUES ('Anthony', 'Stark', 'Iron Man') ,('Thor', 'Odinson', 'God of Thunder') ,('Steven', 'Rogers', 'Captain America') ,('Bruce', 'Banner', 'Hulk') ,('Clinton', 'Barton', 'Hawkeye') ,('Natasha', 'Romanoff', 'Black Widow'); You run the staticQuery.ps1 PowerShell script from the Windows command shell with the following syntax: powershell .staticQuery.ps1 After running the staticQuery.ps1 PowerShell script, it writes the following to the local console but with minimal effort you can redirect it to a file: Avenger: Iron Man is Anthony Stark Avenger: God of Thunder is Thor Odinson Avenger: Captain America is Steven Rogers Avenger: Hulk is Bruce Banner Avenger: Hawkeye is Clinton Barton Avenger: Black Widow is Natasha Romanoff As always, I hope this helps those looking to use this technology. My guess is the principal uses will be DevOps and Data Engineers. https://blog.mclaughlinsoftware.com/2021/04/28/mysqlcredentials/
0 notes