C# - Hide Command Line Window - command-line

I am starting a bat-File within my code with
System.Diagnostics.Process.Start(path + ".bat");
How can I hide the command line window of that bat-file?
Thank you.

Use ProcessStartInfo for more control, e.g.
var psi = new ProcessStartInfo(path + ".bat"));
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);

Related

Using powershell to change an image in MS office publisher

I am creating a powershell script that will auto generate publisher files for wristbands. On the Wristband is a QR code and a few other details to personally identify the wearer. I currently have a template file set up, a script that copies this, renames it, and edits some of the text on the page.
What I need it the script to change the placeholder image in the template to a QR code image, the data in the QR is only every going to be from a set amount of images (one of 1800), all have been generated and named to match up with the names used in Powershell.
Has anyone changed an image in MS Publisher using powershell before? Below is the code I currently have.
$CurrentMember = "M001S001"
$CurrectDocumet = "C:\Users\Rob\Documents\DistrictCamp2017\GeneratedFiles\" + $CurrentMember + ".pub"
copy-item "C:\Users\Rob\Documents\DistrictCamp2017\TemplateWristband.pub" "C:\Users\Rob\Documents\DistrictCamp2017\GeneratedFiles"
Rename-Item "C:\Users\Rob\Documents\DistrictCamp2017\GeneratedFiles\TemplateWristband.pub" "$CurrentMember.pub"
Add-Type -AssemblyName Microsoft.Office.Interop.Publisher
$Publisher = New-Object Microsoft.Office.Interop.Publisher.ApplicationClass
$OpenDoc = $Publisher.Open("C:\Users\Rob\Documents\DistrictCamp2017\GeneratedFiles\M001S001.pub")
###Replace Barcode and text
$pbReplaceScopeAll = 2
$OpenDoc.Find.Clear()
$OpenDoc.Find.FindText = "DEFAULT"
$OpenDoc.Find.ReplaceWithText = $CurrentMember
$OpenDoc.Find.ReplaceScope = "2" #$pbReplaceScopeAll
$OpenDoc.Find.Execute()
$OpenDoc.Save()
$OpenDoc.Close()
$Publisher.quit()
The image in the template document is currently a blank 145*145 pixel square, to be replaced by the appropriate QR code image, dependant on the value of $CurrentMember. I haven't yet written anything to try and change the image as I cannot find anything online, anything I search for seems to return results about Azure publisher server images.
Many thanks,
Rob
The easiest way is probably to get the shape by index, then add a new picture in its place, then remove the original shape:
Sub ReplaceFirstShapeWithImage()
Dim oPage As Page
Dim oShape As Shape
Dim newImage As Shape
Set oPage = Application.ActiveDocument.ActiveView.ActivePage
Set oShape = oPage.Shapes(1)
''https://msdn.microsoft.com/en-us/library/office/ff940072.aspx
Set newImage = oPage.Shapes.AddPicture("C:\Users\johanb\Pictures\X.png", msoFalse, msoTrue, oShape.Left, oShape.Top, oShape.Width, oShape.Height)
oShape.Delete
End Sub
This should help you find the right index
Sub GetIndexOfSelectedShape()
If Application.Selection.ShapeRange.Count = 0 Then
MsgBox "Please select a shape first"
Exit Sub
End If
Dim oShape As Shape
Dim oLoopShape As Shape
Dim i As Long
Set oShape = Application.Selection.ShapeRange(1)
For i = 1 To oShape.Parent.Shapes.Count
Set oLoopShape = oShape.Parent.Shapes(i)
If oLoopShape Is oShape Then
MsgBox oShape.Name & " has index " & i
End If
Next i
End Sub
Unfortunately I can't use PowerShell right now, but this VBA code should help you with the object model

Get path of selected Windows Explorer file in AutoIt

My AutoIt script worked as long as I used it via command line. There I could use $CmdLine[1] and pass a path as argument. Now I try to convert the script to a new method to avoid command line arguments.
You open an Explorer Window and select a file e.g C:\test.txt. After that you trigger the AutoIt function with CTRL+WIN+C. The script should look what file is selected in the active Explorer Window and retrieve the path C:\test.txt and assign it to $file variable.
This is my work-in-progress where I'm stuck.
Line 5 $CmdLine[1] needs to be changed to a secret function I don't know.
;Assign key combination "CTRL-WIN-C" to function "copyUNC"
HotKeySet("^#c", "CopyUNC")
;function to copy UNC path of selected Windows Explorer file/folder to clipboard
func CopyUNC()
$file = FileGetLongName($CmdLine[1]) ;THIS LINE NEEDS TO BE CHANGED
$drive = StringLeft($file, 2)
$UNCdrive = DriveMapGet($drive)
If $UNCdrive = "" Then
$UNCfile = $file
else
$UNCfile = $UNCdrive & StringTrimLeft($file, 2)
endif
ClipPut($UNCfile)
endfunc
;necessary loop so AutoIt script stays active and in Tray
While 1
Sleep(100)
WEnd
Q: How do I get the path of a selected file/folder from Windows Explorer into AutoIt v3.3.8.1?
Note #1: I don't want to use registry and right-click tricks to pass the argument
Note #2: If multiple files are selected just pass the first file. Don't overcomplicate things
CMDLINE[1] has nothing to do with what you want.
If you want to activate your script by hotkey AFTER manually selecting the file in Windows Explorer, you need to examine the Explorer window itself.
Here is the function to retrieve selected item in explorer
Func GetExplorerSelection()
Local $saveClip = ""
Local $filesFolders = ""
Local $handle = _WinAPI_GetForegroundWindow()
Local $className = _WinAPI_GetClassName($handle)
If $className = "ExploreWClass" Or $className = "CabinetWClass" Then
$saveClip = ClipGet()
Send("^c")
Sleep(50) ; give clipboard time to react
$filesFolders = ClipGet()
ClipPut($saveClip)
; test if $filesFolders contains #LF and split if so etc..
; code to call StringSplit() etc..
EndIf
EndFunc
maybe this
HotKeySet('{F8}','ccc')
Func ccc()
$ObjWindows = ObjCreate("Shell.Application").Windows()
For $i = 0 To $ObjWindows.Count -1
Local $w = $ObjWindows.Item($i)
Local $aSeLected = $w.Document.SelectedItems()
For $b = 0 To $aSeLected.Count -1
$x = $aSeLected.Item($b)
MsgBox(0,'',$x.Path&'_______'&$x.Name)
Next
Next
EndFunc
While 1
Sleep(100)
WEnd

How to align similar lines of code using whitespace in Netbeans/MPLab X?

Is there an existing macro or plugin which will turn this
Config.MyData1 = Data++;
Config.MyData10 = Data++;
Config.MyData100 = Data++;
Config.MyData1000 = Data++;
into this?
Config.MyData1 = *Data++;
Config.MyData10 = *Data++;
Config.MyData100 = *Data++;
Config.MyData1000 = *Data++;
Using Delphi with GExpert I used to use "Align Line" (ctrl+alt+z). Is there a similar tool for Netbeans/MPLAB-X?
I haven't seen any similar function in MPLABX. But you may try putting a tab character before the '=' using the replace function.
First, write a tabulation using tab key, and copy this.
Then press 'CTRL+H' and replace all the requires '=' by ' ='.
(The wait space is a tab, it seems to be that it doesn't support writing \t for a tab).
Regards

What is wrong with my 'selecting' code? (VB)

I have the following code in VB:
If TextBox1.Text = (Label2.Select(0, 1) Then
TextBox2.Focus()
End If
But it doesnt't work :(
This is what my code is supposed to do:
If the text in texbox1 is the same as the first letter of label 2
Then move cursor to textbox2
You're trying to write Label2.Text.Substring(0,1).

Formatting code nicely

Extremely simple question:
how can I format my code to be nicely readable. Example:
A = (B+C+D+E+F+G+H+I+J+K...)
and let's say it is so long that I have to scroll for ages to later see what I wrote.
If however I press enter to separate the line like this:
A = (B+C+D+E
+F+G+H+I...)
matlab reports error
Thanks
Use ... at the line break. It is a line continuation.
Use ... to split lines:
Instead of a = x + y + z, you can use:
a = x ...
+ y...
+ z
You're looking for "line continuation".
http://www.mathworks.com/help/techdoc/matlab_env/f0-5789.html#f0-5857