How to get logged in username when running Powershell as Administrator? - windows

I tried to run this command in powershell:
(Get-CimInstance -ClassName Win32_ComputerSystem).Username
But it prints me an empty string.
Is there a command to get the output? this command worked for me on other machine but not on different machine.
Worked on machine with version of powershell:
Major: 5
Minor: 1
Build: 19041
Revision: 1682
Did not work on powershell version:
Major: 5
Minor: 1
Build: 17763
Revision: 2931

Related

How to use docker in windows 10?

I am trying to use docker on my windows, but kept getting the docker: error during connection: This error may indicate that the docker daemon is not working. I have used all the solutions described on the Internet, but so far I have not been able to solve my problem.
For example, I applied all the answers with good evaluation of this one error during connection: This error may indicate that the docker daemon is not working.
Some of the things I have done:
Launch command: & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon
I have already uninstalled and installed docker again, using the installer as administrator.
I have changed the initialization type of the docker desktop service to as Automatic (Delayed).
PS C:\Users\diego\Stuffs\RiseIT\getting-started> & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon
PS C:\Users\diego\Stuffs\RiseIT\getting-started> docker run -d -p 80:80 docker/getting-started
docker: error during connect: This error may indicate that the docker daemon is not running.: Post "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/create": open //./pipe/docker_engine: The system cannot find the file specified.
See 'docker run --help'.
I was having the same problem, in my case, I had forgotten to Enable the WSL 2 feature on Windows.
You can enable it using the official tutorial https://docs.microsoft.com/en-us/windows/wsl/install-win10.
Or if you prefer you can follow these steps:
1 . (PowerShell Admin): dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
2 . (PowerShell Admin):
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
3 . RESTART THE COMPUTER
4 . (Download the Linux kernel update package):
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi>
5 . (PowerShell Admin): wsl --set-default-version 2
6 . (Install o docker): Tutorial: https://docs.docker.com/docker-for-windows/install/

Matlab, Windows compatible Docker Container Fails to run Matlab job steps of Azure Devops CI/CD job

I'm trying to make a Matlab/Windows/FMU Compatible docker container to run my works AzureDevops CI/CD Pipeline. But I'm having issues when I run a CI build job online.
When it tries to run any matlab code, I get his error:
Error:
2020-12-10T14:55:08.0295754Z ##[debug] cd('C:\azp\agent\_work\_temp'); command_3a2582de_1b59_40fc_8400_bb6ddbb6b019
2020-12-10T14:55:08.0312327Z [command]C:\Windows\system32\cmd.exe /D /S /C "C:\azp\agent\_work\_tasks\RunMATLABCommand_28fdff80-51b4-4b6e-83e1-cfcf3f3b25a6\0.3.7\bin\run_matlab_command.bat "cd('C:\azp\agent\_work\_temp'); command_3a2582de_1b59_40fc_8400_bb6ddbb6b019""
2020-12-10T14:55:08.8200355Z Fatal Internal Error: std::exception: Bundle#4 start failed: Loading C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error: The specified module could not be found.
I have no problem running my CI/CD loop using my own computer as a self-hosted agent, but I'm having problem running matlab inside my container.
I have tried doing this:
https://www.mathworks.com/matlabcentral/answers/384746-libmwlmgrimpl-dll-error-in-r2017b
by adding directly the dlls, to my src project, pushing the code(with the dlls) to azure and forcing dlls to be loaded to my docker container. Didn't work. A bit more info, I don't have any executables. I have a build process generated from a matlab control project and I also have a testing process running simulink files inside of a matlab unit test class.
Any ideas?
Dockerfile:
# Indicates that the windowsservercore image will be used as the base image.
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# Metadata indicating an image maintainer.
LABEL maintainer="***#***.com"
# Define Work Directory
WORKDIR /azp
RUN mkdir C:\install
# Installing Packet Manager
RUN powershell -command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell -command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser; Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
# Installing Depedencies
RUN mkdir c:\tools\cygwin && cd c:\tools\cygwin && curl -Sso cygwinsetup.exe https://cygwin.com/setup-x86_64.exe && start /wait cygwinsetup -q --root C:\tools\cygwin -P dos2unix,make,perl,python27,python38,rsync,libxml2,pbzip2,mc -X --site http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/64bit/2020/05/31/142136/
RUN setx PATH "%PATH%;C:\tools\cygwin\bin" /M
RUN powershell -command choco install -y git
RUN powershell -command choco install -y mingw
RUN powershell -command choco install -y cmake
RUN powershell -command choco install -y wget
RUN powershell -command choco install -y ninja
RUN powershell -command choco install -y python3
# Verification Step
RUN choco -?
RUN path
RUN ls
RUN wget --help
# Fetch
#RUN wget -rH https://releases.linaro.org/components/toolchain/binaries/latest-6/arm-eabi/
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python get-pip.py
# Transfert Self-Hosted Agent Script
COPY start.ps1 .
# Transfert Matlab Install & Licences
COPY _temp_matlab_R2017b_win64 C:\\install\\_temp_matlab_R2017b_win64
COPY MathWorks C:\\Users\\ContainerAdministrator\\Downloads\\MathWorks
COPY network.lic C:\\install
COPY matlab_license.dat C:\\install
COPY installer_input.txt C:\\install
# Transfert Modelon Install & Licences
COPY FMI_Toolbox-2.8-win.exe C:\\install
COPY fmi_license.lic C:\\install
RUN ls ..\install
#Install Matlab
#RUN powershell.exe -command \
# Start-Job -ScriptBlock {C:\install\_temp_matlab_R2017b_win64\setup.exe -inputFile C:\install\installer_input.txt} -Name matlabInstallContainer ;\
# Wait-Job -Name "matlabInstallContainer";\
# Stop-Job -Name "matlabInstallContainer";
RUN powershell.exe -command \
"&C:\install\_temp_matlab_R2017b_win64\setup.exe -inputFile C:\install\installer_input.txt | Out-Null"
#Install Modelon
RUN C:\install\FMI_Toolbox-2.8-win.exe /S /D=C:\Program Files (x86)\Modelon\FMI Toolbox 2.8
#RUN matlab -r "cd 'C:\Program Files (x86)\Modelon\FMI Toolbox 2.8';setup('C:\install\fmi_license.lic', true);exit;"
RUN mkdir C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Modelon\Licenses\Server
RUN cp C:\install\fmi_license.lic C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Modelon\Licenses\Server
# Sets a command or process that will run each time a container is run from the new image.
CMD powershell .\start.ps1
#CMD [ "cmd" ]
Update:
Still not working.
I have installed Windows 2016 Container, but got same errors.
...\libmwlmgrimpl.dllfailed with error: The specified module could not be found.
I'm adding a object dump,maybe it can help some of you?
I do see LIBEAY32.DLL inside of the dump, but
I don't see SSLEAY32.DLL, is that normal?
Ref:
https://www.mathworks.com/matlabcentral/answers/375270-why-does-my-matlab-compiler-standalone-application-fail-to-start-with-a-the-operating-system-cannot
C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl>objdump -x libmwlmgrimpl.dll | grep "DLL Name"
DLL Name: ddux.dll
DLL Name: instlic_4a.dll
DLL Name: jit_launcher.dll
DLL Name: libmwi18n.dll
DLL Name: libmwfl.dll
DLL Name: libmwms.dll
DLL Name: libmwservices.dll
DLL Name: libmx.dll
DLL Name: libut.dll
DLL Name: mpath.dll
DLL Name: mvm.dll
DLL Name: mlutil.dll
DLL Name: settingscore.dll
DLL Name: webproxy.dll
DLL Name: boost_date_time-vc140-mt-1_56.dll
DLL Name: boost_filesystem-vc140-mt-1_56.dll
DLL Name: boost_log-vc140-mt-1_56.dll
DLL Name: boost_system-vc140-mt-1_56.dll
DLL Name: boost_thread-vc140-mt-1_56.dll
DLL Name: CppMicroServices3.dll
DLL Name: ADVAPI32.dll
DLL Name: COMCTL32.dll
DLL Name: COMDLG32.dll
DLL Name: NETAPI32.dll
DLL Name: WS2_32.dll
DLL Name: SHLWAPI.dll
DLL Name: dhcpcsvc.DLL
DLL Name: PocoFoundation64.dll
DLL Name: PocoNet64.dll
DLL Name: PocoNetSSL64.dll
DLL Name: WININET.dll
DLL Name: msi.dll
DLL Name: CRYPT32.dll
DLL Name: IPHLPAPI.DLL
DLL Name: MAPI32.dll
DLL Name: ole32.dll
DLL Name: libsqlite3.dll
DLL Name: tbb.dll
DLL Name: xerces-c_3_1.dll
DLL Name: KERNEL32.dll
DLL Name: USER32.dll
DLL Name: SHELL32.dll
DLL Name: OLEAUT32.dll
DLL Name: MSVCP140.dll
DLL Name: VCRUNTIME140.dll
DLL Name: api-ms-win-crt-runtime-l1-1-0.dll
DLL Name: api-ms-win-crt-stdio-l1-1-0.dll
DLL Name: api-ms-win-crt-time-l1-1-0.dll
DLL Name: api-ms-win-crt-convert-l1-1-0.dll
DLL Name: api-ms-win-crt-heap-l1-1-0.dll
DLL Name: api-ms-win-crt-environment-l1-1-0.dll
DLL Name: api-ms-win-crt-locale-l1-1-0.dll
DLL Name: api-ms-win-crt-string-l1-1-0.dll
DLL Name: api-ms-win-crt-math-l1-1-0.dll
DLL Name: api-ms-win-crt-utility-l1-1-0.dll
DLL Name: api-ms-win-crt-filesystem-l1-1-0.dll
DLL Name: LIBEAY32.dll
I'm also adding a working matlab/libmwlmgrimpl dependency walker analysis done on my work computer(self-hosted agent).
I don't know how to do it via command line inside my docker container for comparison. Hope this help find with the missing module problem.
Update#2:
After talking to Mathworks, using depency walker, dependencies.exe and vim diff, I found out that the windows 2016 server has LOT less dlls in it's system 32 folder than 'Windows 10' or the 'windows 2016 server with desktop experience'. Those dlls seem to be a must to make mathlab works, hence I needed to add them to my container. I copy pasted the Right difference of my main computer and the docker container to a folder in my docker container and added it to the path. Before, my previous error happened at second in 1 seconf after launching my MATLAB job. now I get a different error(which is PROGRESS!!) and fail at second 2 (which is PROGRESS!!).
Any of you have any idea about this new one?
##[debug] cd('C:\azp\agent\_work\_temp'); command_35722346_1e7d_4546_956b_f1320bcc9adc
C:\Windows\system32\cmd.exe /D /S /C "C:\azp\agent\_work\_tasks\RunMATLABCommand_28fdff80-51b4-4b6e-83e1-cfcf3f3b25a6\0.3.7\bin\run_matlab_command.bat "cd('C:\azp\agent\_work\_temp'); command_35722346_1e7d_4546_956b_f1320bcc9adc""
Fatal Internal Error: std::exception: Bundle#4 start failed: Loading C:\Program Files\MATLAB\R2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error: %1 is not a valid Win32 application.
Matlab, Windows compatible Docker Container Fails to run Matlab job steps of Azure Devops CI/CD job
As I know, the MATLAB R2017b does not support Windows Server 2019 until MATLAB R2019a.
For MATLAB R2017b, you could try to use Windows Server 2016.
You could check the document System Requirements and Supported Compilers:
So, you could try to use the image mcr.microsoft.com/windows:1809 or mcr.microsoft.com/windows/servercore:1607.
As #Leo Liu-MSFT stated,
For MATLAB R2017b, you could try to use Windows Server 2016…⠀So, you could try to use the image mcr.microsoft.com/windows:1809 or mcr.microsoft.com/windows/servercore:1607.
To expand on that answer:
After contacting MathWorks, I understand that the Windows 2016 Server is a barebones version of Windows, with a minimalist set of System 32 DLLs. But MATLAB needs a lot of them to function. Hence, the solution was too either:
Use a Windows 2016 Server with Desktop Experience (mcr.microsoft.com/windows:1809), or
Use a Windows 2016 Server Docker Container (mcr.microsoft.com/windows/servercore:1809) and add all missing System32 DLLs. (Which can be found using dependency walker or making a Right Diff of the host and Docker container’s system32 folder)

Powershell List Process in Docker Windows Container Produces Empty List

I need to get the process id of a dotnet application running in a windows container in order to attach a debugger to it, but when I try to list the processess, I get an empty list.
PS > docker exec -it --privileged elated_swartz powershell -Command Get-CimInstance Win32_Process | Select-Object ProcessId, CommandLine
ProcessId CommandLine
--------- -----------
PSVersion 5.1.15063.483
Docker Client:
Version: 17.06.0-ce
API version: 1.30
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:30:30 2017
OS/Arch: windows/amd64
Docker Server:
Version: 17.06.0-ce
API version: 1.30 (minimum version 1.24)
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 22:19:00 2017
OS/Arch: windows/amd64
Experimental: true
In *nix:
docker top <container>
In Windows
Using CMD:
docker exec <container> tasklist
Using Powershell:
docker exec <container> powershell get-process

How to install Tomcat in Docker Windows Server Container?

On my windows server 2016 tp5 virtual machine, I would like to create a simple native windows based docker example without virtualbox.
The example needs tomcat for windows and since this windows server 2016 docker container uses a shared windows kernel, installing tomcat should be straight forward, alas! Using the following powershell docker build command stops with non-zero code: 255
Dockerfile in c:\build:
FROM microsoft/windowsservercore
RUN powershell -Command wget -Uri mirror.klaus-uwe.me/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70-windows-x64.zip -OutFile "$env:TEMP\tomcat-7.0.70.zip"
Admin-powershell:
docker build c:\build
Result:
---> Running in 317a3572890e
The command 'cmd /S /C powershell -Command wget -Uri mirror.klaus-uwe.me/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomca
t-7.0.70-windows-x64.zip -OutFile "$env:TEMP\tomcat-7.0.70.zip"' returned a non-zero code: 255
Although the zip file has been downloaded in my users temp dir.
Can anybody tell me, how a native windows tomcat installation should look like, as I am not really deep in this stuff.
As mentioned here:
The error code "255" usually means that it is not able to find the file you are asking it to execute
So try and test with the full path and name of the binary(ies) involved in your RUN command line (like powershell)
But test also a simpler case:
RUN dir c:\Users\
This has been recently reported as failing with the same exit code 255, which would mean the latest docker on Windows Server 2016 Technical Preview 5 has a bug.

Not able to run the default hello-world program in docker on Windows 7

I just finished installing Docker on my Windows 7 machine using the instructions provided here https://docs.docker.com/windows/step_one/.
During the installation I did not install Git and Virtual Box as I already had them installed on my machine. After installation I fixed the missing bash.exe script issue and got docker working to some extent. But I am not able to run the default hello-world docker command. I am getting following error.
I already looked into similar issue mentioned on SO Troubleshoot Docker-On-Windows attempt to run hello-world but the error that I am getting here is different. So please do not mark this as duplicate.
$ docker run hello-world
docker: An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/containers/create: open //./pipe/docker_engine: The system cannot find the file specified..
See 'docker run --help'.
$ docker version
Client:
Version: 1.11.2
API version: 1.23
Go version: go1.5.4
Git commit: b9f10c9
Built: Wed Jun 1 21:20:08 2016
OS/Arch: windows/amd64
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/version: open //./pipe/docker_engine: The system cannot find the file specified.
$ docker-machine start default
Starting "default"...
Machine "default" is already running.
$ docker-machine env default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\chandeln\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM #FOR /f "tokens=*" %i IN ('docker-machine env default') DO #%i
$ git --version
git version 2.7.4.windows.1
Never mind. I was making a mistake as I was running the commands from Windows terminal instead of Docker quick start terminal. Some of the commands worked initially which made me think of using Windows terminal.
$ docker run hello-world
Hello from Docker.
This message shows that your installation appears to be working correctly.

Resources