#some programs doing strange checks and updates when launched by powershell

1 messages · Page 1 of 1 (latest)

keen marten
#

does it do it when your terminal isnt running as admin?

#

what if you start powershell with -noprofile

#

by terminal do you mean Windows Terminal?

#

yeah you can modify that cmd line or create a new terminal profile for powershell with -NoProfile

#

and then see if ibehaviro persists from a "blank" powershell session

#

if that makes sense

#

now open a new tab with that and see if issue persists

#

ah i see

#

Start-Process -FilePath "C:\Users\USER\AppData\Local\Discord\Update.exe" -ArgumentList "--processStart Discord.exe"

#

you'll want to do that

#

my vs code is installed system wide not user so can't tell the correct thing to use for it

#

discord.exe isn't meant to be run directly apparently. seems like thats its default behavior so when you run from PS it just displays the output

#

which you'd expect from any cmd line exec

#

i'm not 100% sure

#

you could check the different start verbs on it

#

eg

$startExe = New-Object System.Diagnostics.ProcessStartInfo -Args powershell.exe
$startExe.verbs
#

nah mine just works and launches it when i do Start-Process -FilePath 'C:\Program Files\Microsoft VS Code\Code.exe'

keen marten
#

but it has the same behavior when launched in cmd so its not a terminal or PS issue, its just how the app works

#

you can

#

just have to figure out the right way, like discord

#

there may be another way to just do it from the exe directly but im not sure what that is. someone here will know though

valid osprey
#

Just in case it explicitly answered, You want to run code using code verses code.exe

explicitly using code.exe was missing the step where it sets env vars
and then invokes code.exe with arguments.

That's why code.exe was writing to the console

#

if you want to make sure you're invoking a binary, and a function or alias named code
You can filter by Application type
This works on linux too. It'll properly return executable shell scripts under that filter even though they are text.

$binCode = gcm code -CommandType Application
& $binCode @args
valid osprey
#

so to just invoke binaries the program has to be registered as path environment variable ?
In general? No. But apps like vs code run differently. The process starts, spawns another, and the process you invoked ends almost immediately. not invoking it the way

#

I'm not sure, are you asking about filtering? -CommandType Application will ignore filter, function, alias, etc.

keen marten
#

what if you call the Update.exe instead for discord

#

not in this screenshot ?

valid osprey
#

Just invoke code with code. Like

# no args
code

# ex: pipe from stdin
get-service | Convertto-csv | code -

# ex: open file on line number 5200 ( does not error if there's only 200 lines )
code -g 'user.log:5200'

# ex: create a new file that doesn't exist
code 'newfile.ps1'

# ex: open a file, with error handling asserting the file exists
# this one is a relative path.
# code isn't invoked if Get-Item has an error.
code -g ( Get-Item -ea 'stop' .\README.md)
#

the & $binCode @args part is how you can invoke regular native apps. code handles things special

keen marten
#

oh i see, weird formatting

valid osprey
#

The problem is you're using code.exe. you don't want the exe
That causes it to write to the console.

Try this instead

$binCode = gcm -CommandType Application -TotalCount 1 Code
& $binCode --new-window
#

if you want the absolute path on windows, it's C:\Program Files\Microsoft VS Code\bin\code.cmd

keen marten
#

basically, there's no one size fits all for every app

valid osprey
#

Usually you want -CommandType Application without the file extension
that makes the same code run on windows and linux easier.

#

On windows, Application will select .exe and .cmd filetypes, and some others

clever solstice
#

I agree with ninmonkey. Don't launch the exe, launch the .cmd file

#

But if you must launch the exe, make sure you set the working directory to the install path

#

It's interesting though, that launching the exe results in getting output. One easy way to avoid that is to do the linux thing and "background" it by adding a & on the end, like:

Start-Process "C:\Program Files\Microsoft VS Code Insiders\Code - Insiders.exe" -WorkingDirectory "C:\Program Files\Microsoft VS Code Insiders" &
valid osprey