Start-process window position

Needing your help once again.

I have a PS script that installs TeamViewer (TV). After the installation, I’m using Start-process to launch TV so that the operator can record the ID and Password.

I need to position the TV window at the far-right side of the screen. Can anyone tell me how to do that?

start-process 'c:\program files\teamviewer\teamviewer.exe'

This brings up a window with the info I want, but it’s on top of other stuff, so it needs to be on the right-side. Hoping that’s not too terribly complicated.

Thanks!

—K

PowerShell does not have a built in way to control the size or position of an external application. That’s controlled by the external application or by Windows.

What do you mean by that? :thinking:

Why actually? :thinking:

What info are you after? There might be a another/better way of doing that. :man_shrugging:

Hi Olaf, thanks for responding

  1. per the code snippet, I launch TeamViewer immediately after installation which then displays the machine’s ID and Password for remote access, and I ask the operator to record those two items. For new installations, our TV manager needs them to configure new machine in the TV console.

  2. because it pops up over some info from the powershell screen that I would prefer remain visible to the operator.

  3. I am after the TeamViewer Machine ID and Password.
    I researched on other ways to get the info, but was not able to locate anything which will also gets the password. Recommendations only return the ID number. I would prefer the script get the TV ID and PW directly if that can be done - one less place the operator could make a mistake.

Hope that makes Gee (i.e. it’s clarifying)

You used to be able to use the SetWindowPos (in the API) to do this, but . . .

As part of the Vista re-architecture, all services were moved off the interactive desktop into Session 0. hwnd and window manager operations are only effective inside a session and cross-session attempts to manipulate the hwnd will fail.

Well, not the news I’d hoped for, but thanks for helping. Perhaps another approach.

I have two pop-ups I make with this:

$TVClockID = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the TeamViewer ID:', 'TeamViewer Device ID')
$TVClockPW = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the TeamViewer Password:', 'TeamViewer Device Password')

I could accomplish an acceptable window positioning if I could move these to the left side of the screen. (TV pops over these)

Is that doable?

So, I am now using PS to get the ClientID for TeamViewer which eliminates one of the pop-up input boxes.

Anybody know how to make the pop-up appear on top of all the other windows?

The two lines in my previous post are now this:

$TVClockID = (Get-ItemProperty -path HKLM:\Software\Teamviewer -name "ClientID").ClientID
$TVClockPW = [Microsoft.VisualBasic.Interaction]::InputBox('Enter the TeamViewer Password:', 'TeamViewer Device Password')

So, If I can get the pop-up box that is generated in line two to be on top, then I can roll

Thoughts?

I’d think you may be better off in a TeamViewer related forum. :man_shrugging:

I don’t think what I am looking for is specific to TeamViewer.

Positioning a VB InputBox or a PS Start-Process screen position have nothing directly to do with TV. TV is just the application involved in the PS scripting.

<IMHO>

But you’re trying to manage your TeamViewer installation. I’d expect - if I use an enterprise remote assistance solution - that there are already features built in for onboarding.

Using graphical interfaces for unattended installations are usually a bad idea.
</IMHO>

Again, I’m not looking for any odd stuff about managing or deploying TV. I have the installation working as I want. The pop-up works to get what I need from the operator running my PS script.

The problem is when TV displays the information that I want the operator to record for me - via the pop-up box asking for the password - the pop-up is hidden behind the PS and TV windows, not on top. Perhaps Windows Focus or something else would be involved. I don’t yet know.

I just need to make the pop-up be on top of all the other windows. That SHOULD be (i would expect) part of the PS syntax which generates the pop-up in the first place. Again, not specific to TV installation, configuration, or operation.

I wonder if you could tackle this the other way around, and move the PowerShell window out of the way?

The script posted here works with the standard console host. You’ll need something different if you’re using Windows Terminal.

https://stackoverflow.com/questions/76395669/how-to-get-set-current-window-position-on-screen-in-powershll

Thanks to everyone for good suggestions and input. I was able to cobble this together from a couple of posts. It’s more complicated that I’d hoped but is a lot less than some examples I encountered.
Anyway, it does what I need. Now just need to integrate it into my main script and give it a whirl.

#Load the System.Windows.Forms assembly
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$monitor = [System.Windows.Forms.Screen]::PrimaryScreen

# Define the form object
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "TeamViewer Password"
$Form.Size = New-Object System.Drawing.Size(325,175)
$Form.StartPosition = "Manual"
$form.Left = $monitor.WorkingArea.Width - $form.Width
$form.Top = 10
$form.AutoSize = $true
# Define the input box
$InputBox = New-Object System.Windows.Forms.TextBox
$InputBox.Location = New-Object System.Drawing.Point(50,50)
$InputBox.Size = New-Object System.Drawing.Size(200,20)
$Form.Controls.Add($InputBox)

#Prompt above the input box
$label = New-Object Windows.Forms.Label
$label.Text = "Enter Password from TeamViewer window:"
$label.Location = New-Object Drawing.Point(30, 15)
$form.Controls.Add($label)

# Define the OK button
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(100,75)
$Button.Size = New-Object System.Drawing.Size(100,30)
$Button.DialogResult = [Windows.Forms.DialogResult]::OK
$Button.Text = "OK"
$Form.Controls.Add($Button)
# Put the box on the screen
$Result = $Form.ShowDialog()
 
# Check if the OK button was clicked
if ($Result -eq [Windows.Forms.DialogResult]::OK) {
    $TVPassword = $InputBox.Text
    Write-Host "You entered: $TVPassword"
}
 
# Dispose of the form
$form.Dispose()

One extra thing for others who, like me, have a limited understanding of all this coding, here’s how to adjust the location.

VERTICAL:
In the Define the Form Object block, change

$form.Top = 10

Higher number moves the input box down from top of the screen

HORIZONTAL:
Same block, in this line:

$form.Left = $monitor.WorkingArea.Width - $form.Width

Change the end to look like this:

$form.Left = $monitor.WorkingArea.Width - ($form.Width + 100)

That will move the window left, away from the right border, by 100 pixels

Oh, and Olaf, it works same on other stuff than TeamViewer. :grin:
(just kidding, I always appreciate your help along my way)

—K

1 Like

FWIW, I also like to force my dialogs to the front using:

$Form.TopMost = $true
$Result = $Form.ShowDialog()

Thank you Tony! That is exactly the next thing I was going to try to figure out. I thought there’d be a way to force the input box on top of everything

Just what I needed!!

—K

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.