I have created desktop application with generate qr code like below
I want make a script using batch script or powershell with the qrcode.exe based on value enter url and Qr Image Name using command line.the output should be QR Code Image too.
can try with this but first import the QRCodeGenerator before running the script
#Import-Module QRCodeGenerator
[string] $webname, [string] $url, [string] $output = ".\images\"
$webname = 'Google'
$url = 'https://www.google.com'
$outputfolder = $outputfolder + $webname +'.JPG'
New-PSOneQRCodeURI -URI $url -Width 15 -OutPath $output
and then the output result will be showing as JPG type.
Install-Module -Name QRCodeGenerator
Import-Module QRCodeGenerator
Add-Type -assembly System.Windows.Forms
$qr_base_form = New-Object System.Windows.Forms.Form
$qr_base_form.Height = 150
$qr_base_form.Width = 350
$qr_base_form.Text = "QR Code Generator"
$qr_base_form.AutoSize = $true
$qr_label_url = New-Object System.Windows.Forms.Label
$qr_label_url.Location = '10,10'
$qr_label_url.Size = '100,15'
$qr_label_url.Text = "URL:"
$qr_input_url = New-Object System.Windows.Forms.TextBox
$qr_input_url.Location = '10,30'
$qr_input_url.Size = '100,25'
$qr_label_name = New-Object System.Windows.Forms.Label
$qr_label_name.Location = '10,70'
$qr_label_name.Size = '100,15'
$qr_label_name.Text = "Name:"
$qr_input_name = New-Object System.Windows.Forms.TextBox
$qr_input_name.Location = '10,90'
$qr_input_name.Size = '100,25'
$qr_png_viewer = New-Object System.Windows.Forms.PictureBox
$qr_png_viewer.Image = $img
$qr_png_viewer.SizeMode = "Autosize"
$qr_png_viewer.Anchor = "Bottom, left"
$qr_png_viewer.Location = '150,10'
$qr_button_create = New-Object System.Windows.Forms.Button
$qr_button_create.Location = '150,150'
$qr_button_create.Size = '100,25'
$qr_button_create.Text = "Create Code"
$qr_button_create.Add_Click({
$path = "H:\LIVE\" + "$name"+ ".jpg"
$urllink = $qr_input_url.Text
$name = $qr_input_name.Text
New-PSOneQRCodeURI -URI "$urllink" -Width 15 -OutPath "$path"
$img = $path
})
$qr_base_form.Controls.Add($qr_label_url)
$qr_base_form.Controls.Add($qr_input_url)
$qr_base_form.Controls.Add($qr_label_name)
$qr_base_form.Controls.Add($qr_input_name)
$qr_base_form.Controls.Add($qr_png_viewer)
$qr_base_form.Controls.Add($qr_button_create)
$qr_base_form.ShowDialog()
This code should work for you. Just try changing the variables and try running it. GUI is also included.
Related
As stated in the Title, I would like to add an image into a Word document. Though my goal is to NOT use a path (stating where the image is located).
**Like this: **
$word = New-Object -ComObject Word.Application
$word.visible = $true
$document = $word.documents.Add()
$selection = $word.selection
$newInlineShape = $selection.InlineShapes.AddPicture($path)
But rather using some type of Base64String, so that this skript works with every device, regardless if the image path doesn't exist.
My attempt:
$word = New-Object -ComObject Word.Application
$word.visible = $true
$document = $word.documents.Add()
$selection = $word.selection
$base64ImageString = [Convert]::ToBase64String((Get-Content $path -encoding byte))
$imageBytes = [Convert]::FromBase64String($base64ImageString)
$ms = New-Object IO.MemoryStream($imageBytes, 0, $imageBytes.Length)
$ms.Write($imageBytes, 0, $imageBytes.Length);
$alkanelogo = [System.Drawing.Image]::FromStream($ms, $true)
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width = $alkanelogo.Size.Width;
$pictureBox.Height = $alkanelogo.Size.Height;
$pictureBox.Location = New-Object System.Drawing.Size(153,223)
$pictureBox.Image = $alkanelogo;
$newInlineShape = $selection.InlineShapes.AddPicture($pictureBox.Image)
Note: The variable "$path" is only here as a placeholder
I've figured it out. I downloaded the image to my local computer, converted it to a base64 string and then back to an image.
So that this script works with every user regardless of there path, I built in it to download the file to a specific path (that I created).
Powershell will then extract the image from the path I created.
$filepath = 'C:\temp\image.png'
$folderpath = 'C:\temp\'
if([System.IO.File]::Exists($filepath -or $folderpath)){
rmdir 'C:\temp\image.png'
$b64 = "AAA..."
$bytes = [Convert]::FromBase64String($b64)
[IO.File]::WriteAllBytes($filepath, $bytes)
}else{
mkdir 'C:\temp\' -ErrorAction SilentlyContinue
$b64 = "AAA..."
$bytes = [Convert]::FromBase64String($b64)
[IO.File]::WriteAllBytes($filepath, $bytes)
}
I'm working on a small gui project, sending messages to Teams channel via Powershell.
I created the Gui with text box, and enabled function activation on button press.
I would like the cursor to remain at the begining of the box i.e. 0 place on first line. Haven't been able to find any solution to that. Code below. Please advise.
Add-Type -AssemblyName System.Windows.Forms
Function ButtonClick
{
$test = $textBoxDisplay.Text
Invoke-RestMethod -Method Post -ContentType 'Application/Json' -Body "{`"text`":`"$test`"}" -Uri $myTeamsWebhook
$textBoxDisplay.Clear()
}
$myTeamsWebhook = 'xxx'
[System.Windows.Forms.Application]::EnableVisualStyles()
$button = New-Object 'System.Windows.Forms.Button'
$button.Location = '10, 10'
$button.Name = "buttonGo"
$button.Size = '75, 25'
$button.TabIndex = 0
$button.Text = "&Go"
$button.UseVisualStyleBackColor = $true
$button.Add_Click({ButtonClick})
$textBoxDisplay = New-Object 'System.Windows.Forms.TextBox'
$textBoxDisplay.Location = '12, 50'
$textBoxDisplay.Multiline = $true
$textBoxDisplay.Name = "textBoxDisplay"
$textBoxDisplay.Size = '470, 150'
$textBoxDisplay.TabIndex = 1
$textBoxDisplay.Focus()
$textBoxDisplay.AcceptsReturn = $false
$textBoxDisplay.WordWrap = $true
$textBoxDisplay.add_KeyDown({
if ($_.KeyCode -eq "Enter"){ButtonClick}
})
$mainForm = New-Object 'System.Windows.Forms.Form'
$mainForm.Size = '500, 250'
$mainForm.Controls.Add($button)
$mainForm.Controls.Add($textBoxDisplay)
$mainForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$mainForm.Name = "mainForm"
$mainForm.Text = "GUI Test"
$mainForm.ShowDialog()
Is there a way to generate a url to download files either when uploading or after a file has been uploaded?
I'm working a powershell script that will either upload a single file or zip a directory and upload it to Sharefile.
I have most of it complete, but I cannot figured out how generate a download url or have one created at the time of the upload.
Code for the form below
###### Share Link Automation
### Environment Setting
If (-not(test-path -path "C:\windows\ARP\ShareLink")) {
New-Item -Force -Path C:\Windows\ARP\ShareLink -ItemType Directory
}
$SFLinkDestination = "C:\windows\ARP\ShareLink"
# Function to upload files to share file
Function Upload-File {
param (
$LocalData
)
Add-PSSnapin ShareFile
#Run the following interactively to create a login token that can be used by Get-SfClient in unattended scripts
$sfClient = Get-SfClient -Name ((Join-Path $env:USERPROFILE "Documents\Sharefile") + "\MySubdomain.sfps")
#upload directory is relative to the root of the account
#get the current user's home folder to use as the starting point
$ShareFileHomeFolder = (Send-SfRequest $sfClient -Entity Items).Url
# Create a PowerShell provider for ShareFile pointing to Personal Folsers\Send
New-PSDrive -Name sfDrive -PSProvider ShareFile -Client $sfClient -Root "\Personal Folders\Send" -RootUri $ShareFilePath
#upload all the files (recursively) in the local folder to the specified folder in ShareFile
Copy-SfItem -Path $LocalData -Destination "sfDrive:"
#Remove the PSProvider when we are done
Remove-PSDrive sfdrive
Exit
}
#### Init PowerShell Gui
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
#### The Form
[System.Windows.Forms.Application]::EnableVisualStyles()
$SFLinkForm = New-Object system.Windows.Forms.Form
$SFLinkForm.ClientSize = '480,300'
$SFLinkForm.text = "Share File Link"
$SFLinkForm.BackColor = "#ffffff"
$SFLinkForm.TopMost = $false
# $Image = [system.drawing.image]::FromFile("G:\APPS\temp\abp_main.bmp")
$SFLinkForm.BackgroundImage = $Image
$SFLinkForm.BackgroundImageLayout = "None"
$SFLinkForm.AutoSizeMode = "GrowAndShrink"
$SFLinkFormTitle = New-Object system.Windows.Forms.Label
$SFLinkFormTitle.text = "Share File Link"
$SFLinkFormTitle.ForeColor = "DarkRed"
$SFLinkFormTitle.AutoSize = $true
$SFLinkFormTitle.width = 45
$SFLinkFormTitle.height = 20
$SFLinkFormTitle.location = New-Object System.Drawing.Point(20,100)
$SFLinkFormTitle.Font = 'Microsoft Sans Serif,13,style=Bold'
$SFLinkFormTitleZiP = New-Object system.Windows.Forms.Label
$SFLinkFormTitleZip.text = "Share File Zip Name:"
$SFLinkFormTitleZip.ForeColor = "DarkRed"
$SFLinkFormTitleZip.AutoSize = $true
$SFLinkFormTitleZip.width = 45
$SFLinkFormTitleZip.height = 20
$SFLinkFormTitleZip.location = New-Object System.Drawing.Point(20,175)
$SFLinkFormTitleZip.Font = 'Microsoft Sans Serif,10,style=Bold'
$SFLinkFormDescription = New-Object system.Windows.Forms.Label
$SFLinkFormDescription.text = "When creating a link ..... TBD"
$SFLinkFormDescription.ForeColor = "DarkRed"
$SFLinkFormDescription.AutoSize = $false
$SFLinkFormDescription.width = 450
$SFLinkFormDescription.height = 20
$SFLinkFormDescription.location = New-Object System.Drawing.Point(20,125)
$SFLinkFormDescription.Font = 'Microsoft Sans Serif,10'
### Zip File Namer
$SFLinkFormZip = New-Object System.Windows.Forms.TextBox
$SFLinkFormZip.Location = New-Object System.Drawing.Size(20,200)
$SFLinkFormZip.Size = New-Object System.Drawing.Size(220,20)
$SFLinkForm.Controls.Add($SFLinkFormZip)
#### File Selector
$SFLinkFormFileBtn = New-Object system.Windows.Forms.Button
$SFLinkFormFileBtn.BackColor = "#ffffff"
$SFLinkFormFileBtn.text = "File"
$SFLinkFormFileBtn.width = 90
$SFLinkFormFileBtn.height = 20
$SFLinkFormFileBtn.location = New-Object System.Drawing.Point(200,230)
$SFLinkFormFileBtn.Font = 'Microsoft Sans Serif,10,style=Bold'
$SFLinkFormFileBtn.ForeColor = "#0"
$SFLinkForm.Controls.Add($SFLinkFormFileBtn)
$SFLinkFormFileBtnLabel = New-Object system.Windows.Forms.Label
$SFLinkFormFileBtnLabel.text = "Click to Select a File:"
$SFLinkFormFileBtnLabel.ForeColor = "DarkRed"
$SFLinkFormFileBtnLabel.AutoSize = $true
$SFLinkFormFileBtnLabel.width = 25
$SFLinkFormFileBtnLabel.height = 20
$SFLinkFormFileBtnLabel.location = New-Object System.Drawing.Point(20,232)
$SFLinkFormFileBtnLabel.Font = 'Microsoft Sans Serif,10,style=Bold'
$SFLinkFormFileBtn.Add_Click(
{
Add-Type -AssemblyName System.Windows.Forms
$SFLinkFormFClick = New-Object System.Windows.Forms.OpenFileDialog
$SFLinkFormFClick.Title = "Please Select File"
$SFLinkFormFClick.InitialDirectory = $InitialDirectory
$SFLinkFormFClick.filter = “All files (*.*)| *.*”
# If ($SFLinkFormFClick.ShowDialog() -eq "Cancel") {
If ($SFLinkFormFClick.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
$LocalData = ($SFLinkFormFClick).FileName
# [System.Windows.Forms.MessageBox]::Show("No File Selected. Please select a file !", "Error", 0,
# [System.Windows.Forms.MessageBoxIcon]::Exclamation)
}
Write-Host "The File Selected is ($SFLinkFormFClick).FileName"
Write-Host "$LocalData"
Upload-File -LocalData "$LocalData"
$SFLinkForm.Close()
Return
Exit
# $LocalData = ($SFLinkFormFClick).FileName
}
)
### Directory Selector
$SFLinkFormDirBtn = New-Object system.Windows.Forms.Button
$SFLinkFormDirBtn.BackColor = "#ffffff"
$SFLinkFormDirBtn.text = "Directory"
$SFLinkFormDirBtn.width = 90
$SFLinkFormDirBtn.height = 20
$SFLinkFormDirBtn.location = New-Object System.Drawing.Point(200,255)
$SFLinkFormDirBtn.Font = 'Microsoft Sans Serif,10,style=Bold'
$SFLinkFormDirBtn.ForeColor = "#0"
$SFLinkForm.Controls.Add($SFLinkFormDirBtn)
$SFLinkFormDirBtnLabel = New-Object system.Windows.Forms.Label
$SFLinkFormDirBtnLabel.text = "Click to Select a Directory:"
$SFLinkFormDirBtnLabel.ForeColor = "DarkRed"
$SFLinkFormDirBtnLabel.AutoSize = $true
$SFLinkFormDirBtnLabel.width = 25
$SFLinkFormDirBtnLabel.height = 20
$SFLinkFormDirBtnLabel.location = New-Object System.Drawing.Point(20,257)
$SFLinkFormDirBtnLabel.Font = 'Microsoft Sans Serif,10,style=Bold'
$SFLinkFormDirBtn.Add_Click(
{
$SFLinkFormDClick = New-Object System.Windows.Forms.FolderBrowserDialog
if ($SFLinkFormDClick.ShowDialog() -eq [System.Windows.Forms.DialogResult]::"OK") {
$SFLinkFormDirName = $SFLinkFormDClick.SelectedPath
$ZipWrapper = $SFLinkFormZip.Text
$LocalData = (Join-Path C:\windows\ARP\ShareLink\ "$ZipWrapper.zip")
### Directgory Compression
# cd C:\windows\ARP\ShareLink
Compress-Archive "$SFLinkFormDirName\*" "$LocalData"
Upload-File -LocalData "$LocalData"
$SFLinkForm.Close()
Return
Exit
}
}
)
$SFLinkForm.controls.AddRange(#($SFLinkFormTitle,$SFLinkFormDescription,$SFLinkFormFileBtn,$SFLinkFormDirBtn,$SFLinkFormFileBtnLabel,$SFLinkFormDirBtnLabel,$SFLinkFormZip,$SFLinkFormTitleZiP))
$SFLinkForm.ShowDialog()
$SFLinkForm.Close()
Exit
Search all the API codes for Sharefile and could not find the powershell equivalence of "Get A Link" in the API Entities.
I’m trying to make a signature maker and I want to write name and job in Hebrew but it starts from the left like English. There is a way that the text will start from the right?
This is my code for example:
Add-Type -AssemblyName System.Drawing
$uname='סער'#Read-Host "insert name:"
$job='יינחןינצל'#Read-Host "insert job:"
$filename = "$home\desktop\sign.png"
$bmp = new-object System.Drawing.Bitmap 600,200
#Get the image
#$source=Get-Item
#$img = [System.Drawing.Image]::FromFile($_.FullName)
#Create a bitmap
#$bmp = new-object System.Drawing.Bitmap([int]($img.width)),([int]($img.height))
$font = new-object System.Drawing.Font Consolas,18
$brushBg = [System.Drawing.Brushes]::White
$brushFg = [System.Drawing.Brushes]::Black
$graphics = [System.Drawing.Graphics]::FromImage($bmp)
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height)
$graphics.DrawString($uname,$font,$brushFg,10,10)
$graphics.DrawString($job,$font,$brushFg,90,100)
$graphics.Dispose()
$bmp.Save($filename)
Invoke-Item $filename
As commented, the DrawString() method has a constructor with which you can give it a StringFormat object where you can set RightToLeft text direction.
In your code try:
$rtlFormat = [System.Drawing.StringFormat]::new([System.Drawing.StringFormatFlags]::DirectionRightToLeft)
$graphics.DrawString($uname, $font, $brushFg, [System.Drawing.PointF]::new(10,10), $rtlFormat)
$graphics.DrawString($job, $font, $brushFg, [System.Drawing.PointF]::new(90,100), $rtlFormat)
If you are using a PowerShell version that is too old for the [type]::new() syntax, use
$rtlFormat = New-Object -TypeName System.Drawing.StringFormat('DirectionRightToLeft')
$graphics.DrawString($uname, $font, $brushFg, (New-Object -TypeName System.Drawing.PointF(10,10)), $rtlFormat)
$graphics.DrawString($job, $font, $brushFg, (New-Object -TypeName System.Drawing.PointF(90,100)), $rtlFormat)
$sf = [System.Drawing.StringFormat]::New()
$sf.Alignment = 'far'
$sf.LineAlignment = 'far'
$graphics.FillRectangle($brushBg,0,0,$bmp.Width,$bmp.Height)
$graphics.DrawString($uname,$font,$brushFg,500,100,$sf)
$graphics.DrawString($job,$font,$brushFg,500,200,$sf)
This is what I did in the end
Thaks Theo
I have an GUI, I want to open a folder and select a file. When I execute my code from ISE, it works. but when I run from another environment with cmd, it shows some error
Exception calling "ShowDialog" with "0" arguument(S): "Creating an instance of the COM component with CLSID.....
Function Sel_File
{
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = "P:\Temp\MM"
$OpenFileDialog.Title = "Please Select File"
$OpenFileDialog.filter = “All files (*.*)| *.*”
If ($OpenFileDialog.ShowDialog() -eq "Cancel")
{
[System.Windows.Forms.MessageBox]::Show("No File Selected. Please select a file !", "Error", 0,
[System.Windows.Forms.MessageBoxIcon]::Exclamation)
} $Global:SelectedFile = $OpenFileDialog.SafeFileName
}
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.AutoSize = $true
$Form.text = "Auto GM Creation"
$Form.TopMost = $true
#----------------------
$ChooseML_L = New-Object system.Windows.Forms.Label
$ChooseML_L.text = "MLs"
$ChooseML_L.AutoSize = $true
$ChooseML_L.width = 25
$ChooseML_L.height = 10
$ChooseML_L.location = New-Object System.Drawing.Point(28,20)
$ChooseML_L.ForeColor = "#000000"
$SelectML = New-Object system.Windows.Forms.TextBox
$SelectML.AutoSize = $true
$SelectML.width = 150
$SelectML.height = 30
$SelectML.location = New-Object System.Drawing.Point(120,40)
$SelectML.Text = "Selected ML"
$ChooseML = New-Object System.Windows.Forms.Button
$ChooseML.text = "Select File"
$ChooseML.AutoSize = $true
$ChooseML.width = 90
$ChooseML.height = 20
$ChooseML.location = New-Object System.Drawing.Point(28,38)
$ChooseML.ForeColor = "#ffffff"
$ChooseML.BackColor = "#093c76"
$ChooseML.Add_Click({Sel_File
$SelectML.Text = $Global:SelectedFile
})
#----------
$Apply = New-Object system.Windows.Forms.Button
$Apply.BackColor = "#6996c8"
$Apply.text = "Apply"
$Apply.width = 99
$Apply.height = 30
$Apply.location = New-Object System.Drawing.Point(320,190)
#----------
$Cancel = New-Object system.Windows.Forms.Button
$Cancel.BackColor = "#6996c8"
$Cancel.text = "Cancel"
$Cancel.width = 98
$Cancel.height = 30
$Cancel.location = New-Object System.Drawing.Point(450,190)
$Cancel.Add_Click({$Form.Close()})
#-----------
$Prefix = New-Object system.Windows.Forms.Label
$Prefix.text = "Prefix"
$Prefix.AutoSize = $true
$Prefix.width = 25
$Prefix.height = 10
$Prefix.location = New-Object System.Drawing.Point(28,80)
$Prefix.ForeColor = "#000000"
$NB = New-Object system.Windows.Forms.RadioButton
$NB.text = "NB"
$NB.AutoSize = $true
$NB.BackColor = "#4a90e2"
$NB.width = 104
$NB.height = 20
$NB.location = New-Object System.Drawing.Point(28,100)
$DPC = New-Object system.Windows.Forms.RadioButton
$DPC.text = "DPC"
$DPC.AutoSize = $true
$DPC.BackColor = "#4a90e2"
$DPC.width = 104
$DPC.height = 20
$DPC.location = New-Object System.Drawing.Point(100,100)
$Form.Controls.AddRange(#($ChooseML, $Prefix, $ChooseML_L, $Apply, $Cancel, $SelectML, $NB, $DPC))
[void]$Form.ShowDialog()
This is my code updated. This is working using PS ISE, but I tried execute it from WinPE environment, It shows those error above.
Could anyone help me please. Thank you
this works ... but i think the use of LoadWithPartialName has been deprecated. i can't find the "new way" at this time, tho. [blush]
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") |
Out-Null
$SelectFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$SelectFileDialog.InitialDirectory = 'c:\temp'
$SelectFileDialog.Filter = 'Extensionless files (*)|*'
$SelectFileDialog.Title = 'Please select a file and then click [OK]'
$SelectFileDialog.ShowDialog() |
Out-Null
$SelectFileDialog.FileName
I believe it'll work if you remove | Out-Null from this line
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog | Out-Null
Just need to add this, it works well.
Thank you for all the contribution
$OpenFileDialog.AutoUpgradeEnabled =$false