Context
I created a Github Actions workflow that generates a .msi file that I wan't to execute afterwards to test if the application is working as expected.
The workflow implementation is as below
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2.3.4
- name: Create binary from branch
run: |
choco install make
make build-windows
- name: Generate msi
shell: powershell
run: .\.github\scripts\windows\gen-win.ps1
- name: Install msi
run: |
echo "Start Msiexec"
msiexec /qn /i "file.msi" /L*vx!
echo "End Msiexec"
Basically this workflow creates the .exe file (Create binary from branch step), then use a script in powershell that generates the .msi file (Generate msi step), and finally try to install the .msi file (Install msi step).
Issue
The problem occurs on the Install msi step, the runner logs only returns:
Start Msiexec
End Msiexec
... without showing any log, or creating the directories and files as the installation should do on the $HOME directory.
What I tried
Using the default shell for windows-latest runner (which is cmdlet), I tried to run those commands in the workflow without success, using "file.msi" or "path/to/file.msi":
msiexec /i "file.msi"
msiexec /qn /i "file.msi"
msiexec /qn /i "file.msi" /L*vx!
I'm not very familiar with the windows operating system, but for what I searched online, this msiexec command should work.
I also tried to install the .msi file generated manually on a windows 10 computer using those commands with success (so the generated .msi file is valid and working locally). However, it opens another prompt window automatically showing the installation and setup logs (it's not in the same terminal window) and I imagine this may not happen on Github Actions.
Question
➡️ How can I install this application from the .msi file through a command line on the windows-latest runner?
After asking the same thing on the Github Community forum, I got the following answer from #Simran-B (Github Advisory Council Member):
msiexec doesn’t seem to log anything to a terminal. If your MSI does
(even if in a separate window), then it must be something that is
specific to that MSI…
What msiexec supports is to log to a file. Based on Is there anyway
to get msiexec to echo to stdout instead of logging to a file - Server
Fault,
I successfully ran the following PowerShell script (using a Blender
MSI as a test):
$file = "file.msi"
$log = "install.log"
$procMain = Start-Process "msiexec" "/i `"$file`" /qn /l*! `"$log`"" -NoNewWindow -PassThru
$procLog = Start-Process "powershell" "Get-Content -Path `"$log`" -Wait" -NoNewWindow -PassThru
$procMain.WaitForExit()
$procLog.Kill()
I can’t recommend /l*vx!, because the forced flush for every log
line makes things slow and the verbose output with additional
debugging information can produce thousands of lines. Alternatively,
you could log everything to a file without flushing, wait for
msiexec to exit, and then print the file contents to the console in
one go, which should be significantly faster (but you lose live
logging).
If I remember correctly, GitHub-hosted runners use elevated
permissions by default. In my local test, I had to run the above
script from an elevated PowerShell because the MSI tried to install to
C:\Program Files\, which is not writable unless you have elevated
permissions, and that made the installation fail without obvious log
entry. If there’s something wrong with the .msi path, you may get an
exit code of 1619 ($procMain.ExitCode), which is also not very
intuitive. Another possible reason for nothing getting installed (at
least apparently) can be that you don’t actually wait for msiexec to
finish - the command immediately returns and the installation process
runs in the background. You can use Start-Process with the -Wait
option or get the handle with -PassThru and call .WaitForExit() on
it to wait until it is done.
It worked for me! With those commands, I could execute the .msi file to install the software, then use it afterwards in my github actions workflow to perform my tests!
I am trying to open a Command Prompt as administrator, (elevated), from a normal user privileged Command Prompt.
I searched Google a lot, but cannot find a method to achieve it.
Is there any CLI command, to open an Administrator: Command Prompt, from a normal Command Prompt?
Thanks in advance!
I don't know the meaning or any other explanation for this command but, it works with all Windows Operating system's (Windows 7,8,8.1,10,11 - Tested). Run this command in your normal user privileged Command Prompt Which will open another Administrator: CMD window.
powershell -Command "Start-Process cmd -Verb RunAs"
I got this Command from Google while searching on the Internet. If anybody know the meaning of this command plz update (Edit) my Answer!
There is no such command. Cmd needs to be invoked with the credentials you want to use. So changing users like for example in Terminal on Ubuntu is not possible at the moment. You can open a new Terminal by using
runas /user:(UserNameHere) CMD.exe
Below is the command I use in powershell to launch the app, I have deliberately used * wildcard as the app folder name changes slightly for each device. I want to replicate the wildcard in the bat file.
Start-Process -FilePath "C:\ProgramData\theapp*\theapp.exe"
therefore, for the bat file version could I use:
start "C:\ProgramData\theapp*" theapp.exe
Also, if this could be used : what install line would be best to launch this in sccm?
Massive thank you!
There are plenty of questions here which asks how to elevate priviliges from powershell, and almost all of them recommend this command:
Start-Process -Verb RunAs powershell.exe .....
(or pwsh.exe for Powershell Core)
And this works, it opens up a new Powershell window with elevated privileges, after having gone through a UAC block to verify access.
However, while I'm using Powershell, I'm doing it inside Windows Terminal, the new terminal application for Windows 10, and I would like to open a new instance of Windows Terminal with elevated privileges, not just a Powershell window.
So I tried these commands:
Start-Process -Verb RunAs wt
Start-Process -Verb RunAs wt.exe
Start-Process -Verb RunAs (Get-Command wt)
Start-Process -Verb RunAs "C:\Users\lasse\AppData\Local\Microsoft\WindowsApps\wt.exe"
They all fail with:
Start-Process: This command cannot be run due to the error: The file cannot be accessed by the system..
I'm assuming this has something to do with where the executable is located, within my profile, but if I right-click the Windows Terminal icon I have on my task bar and choose to run it as administrator, it opens up just fine. This is what I want to duplicate.
So is there a way for me to modify either the commands I tried above, or change some access setting that would make this work?
For my specific instance, I simply want to make it simpler to pop open an admin terminal, I don't need a way to elevate arbitrary commands, then I will happily use the commands I have already shown here.
Currently you cannot open an elevated wt.exe session from the command line without workarounds. Workarounds include using gsudo, Using Task Scheduler (I tested this one and it works but you need to use the full path to wt.exe and you can skip the shortcut creation step) OR if you are ok with a keyboard shortcut, the simplest way; using a keyboard shortcut to run Windows Terminal as Admin from the taskbar.
For your use case:
For my specific instance, I simply want to make it simpler to pop open
an admin terminal, I don't need a way to elevate arbitrary commands,
then I will happily use the commands I have already shown here.
The simplest approach will work:
Pin Windows Terminal as the first item on the task bar. Then hit Win+Ctrl+Shift+1 to open it as admin.
If you really must launch Windows Terminal from the command line from within Windows Terminal then create a task in the Task Scheduler:
Give the task a name, check 'Run with highest privileges'.
Choose the 'Actions' tab, click 'New', select 'Start a program' as the action. Put the full path to wt.exe in the 'Program/script field'. Click OK. Click OK again.
Click 'Conditions' tab, uncheck "Start the task only if the computer is on AC power".
Click 'Settings' tab, make sure "Allow task to be run on demand" is checked and uncheck "Stop the task if running for longer than".
Finally in your shell (Powershell), launch an elevated Windows Terminal session by running the command: schtasks /run /TN "TASK_NAME" where TASK_NAME is the name you gave the task in step 1.
Try this:
powershell "Start-Process -Verb RunAs cmd.exe '/c start wt.exe'"
Also check out these links:
WT.exe command line arguments:
https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows
Article about adding Open Windows Terminal Command Prompt to the context menu in Explorer (includes Admin):
https://dkcool.tailnet.net/2020/07/add-open-windows-terminal-command-prompt-to-the-explorer-context-menu-in-windows-10/
Article about adding Open Admin Command Prompt to the context menu in Explorer:
https://dkcool.tailnet.net/2019/05/add-open-admin-command-prompt-to-the-explorer-context-menu-in-windows-10/
Not a direct answer but another option if you have PowerToys is to:
Alt + Space, type Terminal,
Select Run as Administrator (or Ctrl + Shift + Enter)
You can install PowerToys using WinGet
With recent releases, this issue appears to be fixed. It works now, doing exactly as you originally tried and failed (Start-Process -verb RunAs wt). I would recommend trying again now with the latest releases (at least Windows Terminal, and perhaps PowerShell as well).
No need for workarounds anymore!!
Windows Terminal has a feature to automatically run as administrator in the preview; no need for workarounds now.
Pin to the Taskbar and hold Ctrl + Shift while left clicking on the Windows Terminal icon.
In my particular case I also need Windows Terminal opened as administrator all the time. This is what I did, run "where wt" to display the path where Windows Terminal application exe is located, it should be C:\Users\YOURUSER\AppData\Local\Microsoft\WindowsApps\wt.exe.
I created a shortcut to that file and checked "Run as administrator" in the advanced properties, then I just pinned it to start and voila. You can delete your temporary shortcut after that if you want.
You can create a shortcut to always run Windows Terminal as administrator using this powershell script:
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Windows Terminal.lnk")
$Shortcut.TargetPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe"
$Shortcut.Save()
$bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\Windows Terminal.lnk")
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes("$Home\Desktop\Windows Terminal.lnk", $bytes)
You can just paste it and run it from Windows Powershell ISE, it will create a Windows Terminal.lnk file on your desktop. Whenever you double click on that shortcut Windows terminal will run as an admnnistrator
I know this answer does not fully match your question but given that also other answers were oriented in this way I hope this won't disturb the discussion.
I always need to run PowerShell as Administrator and I only want to use Windows Terminal, which given it's restrictions cannot be configured to run always as Administrator.
I hated the need to use shortcuts and other hacks I found being suggested online, so I think I found a better solution but you have to pay the cost of a 1/2 seconds at startup.
Locate your user profile (A profile is a Windows PowerShell ISE script that runs automatically when you start a new session) using _ $PROFILE
Edit profile with any preferred editor _ code $PROFILE
Adde the following code to the profile file and save it
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$host.ui.rawui.windowtitle="Bootstrapper"
Start-Process -Verb RunAs wt
} else {
$Processes = Get-Process | Where-Object {$_.mainWindowTitle -eq 'Bootstrapper' -and $_.name -eq 'WindowsTerminal'}
if($Processes.count -gt 0)
{
Stop-Process -Id $Processes[0].id
}
}
What the script do?
You can pin Windows Terminal icon to your application bar and when you click there WT will start as non elevated user, but the profile will understand if this is the case.
When you are not running as Administrator it will change the name of the window and start a new WT as administrator.
The new instance will also execute the profile file and if the instance is runinng as Administrator, it will look for the WT named Bootstrapper and kill it.
This proces takes between one and two seconds, I prefer this way other than right clicking on the icon.
It's likely you were just facing a Path issue. I know that the command examples you gave (e.g. Start-Process -verb RunAs wt) have worked for me for some time (as mentioned in #fialdrexs's answer).
Did you install Windows Terminal from a Github release or from the Store?
I currently have the following entry in my settings.json profiles list to add an elevated Windows Terminal to the drop down options:
{
// https://github.com/microsoft/terminal/issues/632#issuecomment-663686412
"name": "Windows Terminal (elevated)",
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command Start-Process -Verb RunAs \"shell:appsFolder\\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App\"",
"hidden": false,
"icon": "ms-appx:///Images/Square44x44Logo.targetsize-32.png"
}
The comment with the GitHub link should get you to where I originally found this information.
I find a away to workaround, just create a file bat with content
powershell Start-Process -Verb RunAs wt.exe
Save file yourfile.bat to folder you want.
Add path folder to System Environment.
Press WINDOW + R and type file bat name.
Currently this problem was fixed, but it ended up with a weird issue. Running wt.exe from Win+R, searching it on start menu, and starting itself from the terminal, show the same error message.
The application was unable to start correctly (0xc0000022). Click OK
to close the application.
However it works when executing wt via Command Prompt, PowerShell, and PowerShell Core.
So just a quick workaround answer, start PowerShell and run the command,
Start-Process -Verb RunAs wt.exe;
or the simpler
start -verb runas wt
I am trying to execute a Powershell command from within qmake. A simplified .pro file looks like this:
$$system(powershell -NonInteractive -Command \"[long]((date).touniversaltime()-[datetime]'1970-01-01').totalmilliseconds\")
However, running qmake with this file or opening it in QtCreator will create a powershell.exe process which hangs indefinitely. Running Powershell from the command line works without problems, the command prints the expected timestamp and exits immediately.
What could be causing this hang and how to resolve it?
Tested on Windows 7 x64 with Powershell version 2.0 and qmake version 3.1 / Qt 5.9.8.
Don't use the quote.
The possible command is:
$$system(powershell -Command Get-Date -Format "yyyy.MM.dd.HH.mm")