Get hibernate status [closed] - powershell

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Is it possible to get hibernation status using shell ?
I am using powercfg.exe to enable/disable it and there doesn't seem to be any way to get the status, even using /Q (query).
I also tried to base that on existence of %SystemDrive%\hiberfil.sys but that requires admin rights.
EDIT
Current solution is outdated:
From version 1809 the registry setting “HibernateEnabled” was renamed “HibernateEnabledDefault”. If you use cmd (powercfg.exe /hibernate off), it is created in addition to the “HibernateEnabledDefault” parameter “HibernateEnabled” with all of the control circuits of the supply.
Setting registry didn't have any effect for me since this version. I had to go to Control Panel\Hardware and Sound\Power Options\System Settings to enable it, after that powercfg options worked again. If both HibernateEnabled and HibernateEnabledDefault are deleted, I still got Hibernate option active.

You could check the registry key:
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\Power -name HibernateEnabled
Or remotely using .Net and Remote Registry:
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', "ExampleComputer")
$RegKey = $Reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Power")
$RegKey.GetValue("HibernateEnabled")

Here is an alternative for cmd, based on the registry query by BenH's answer:
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled"
To capture the result and store it into a variable, use this:
for /F "delims=" %V in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled"') do set "Hibernate=%V"

Related

How to find port on windows (using pid or processes name) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 29 days ago.
Improve this question
How to find port on windows (using pid or processes name)
I know the PID, but I need the port on which the processes are running
you can use the following CMD command (Open it as administrator)
netstat -aon | findstr PID
There more different ways to find process port available here.
The accepted answer to the question that Nikita's answer links to - https://stackoverflow.com/a/48199/45375 - can be adapted to your needs with the following PowerShell command (assumes that the PID of interest is stored in $yourPid):
(Get-NetTCPConnection | Where-Object OwningProcess -eq $yourPid).LocalPort |
Select-Object -Unique
Note that even weeding out duplicates can result in multiple ports getting returned.
See also:
Get-NetTCPConnection

gvim 8.2 doesn't redraw the screen when editing a git commit message in windows 10 powershell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I installed vim on windows 10 using chocolatey. When I edit a file in powershell, everything works great! I even got copy and paste to work. However, when I edit a git commit message, vim doesn't redraw my screen properly. If I force a screen redraw, I can see my updated text properly, but that is super annoying.
I configured git to use vim with:
git config --global core.editor vim
How can I make vim behave properly?
TLDR
Giving git the direct fully-qualified path to my vim executable fixed things, and I don't know why:
git config --global core.editor "'C:\tools\vim\vim82\vim.exe' -f -i NONE"
Single quotes around the path are important because git doesn't know how to handle paths with backslashes.
Double quotes around the whole configuration are important so that git doesn't apply -f -f NONE to the git config command.
I found -f -i NONE on this answer, and I don't know what it does, but git commit didn't work without it.
How I found the full path
vim adds a c:\windows\vim.bat file, which is what powershell uses to launch vim when you type vim:
PS C:\Users\heath> Get-Command vim
CommandType Name Version Source
----------- ---- ------- ------
Application vim.bat 0.0.0.0 C:\windows\vim.bat
vim.bat is pretty simple:
#echo off
rem -- Run Vim --
rem # uninstall key: vim82 #
setlocal
set VIM_EXE_DIR=C:\tools\vim\vim82
if exist "%VIM%\vim82\vim.exe" set VIM_EXE_DIR=%VIM%\vim82
if exist "%VIMRUNTIME%\vim.exe" set VIM_EXE_DIR=%VIMRUNTIME%
if not exist "%VIM_EXE_DIR%\vim.exe" (
echo "%VIM_EXE_DIR%\vim.exe" not found
goto :eof
)
"%VIM_EXE_DIR%\vim.exe" %*
Thus, my full vim path is C:\tools\vim\vim82\vim.exe

Embedded Chocolatey Installer Failing [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I keep getting the same error with my chocolatey package: Exit code was '-1'. I am not sure if it is something wrong with my chocolateyinstall.ps1 or the setup.exe I am using to make this embedded installer. The image below shows both the chocolateyinstall.ps1 and the cmd when trying to run choco install (packagename). Thanks.
Here is the code:
$packageArgs = #{
packageName = 'armrvds'
fileType = 'exe'
file = "$(Split-Path -parent $MyInvocation.Mycommand.Definition)\setup.exe"
validExitCodes = #(0)
softwareName = 'ARM RVDS 4.1*'
Install-ChocolateyInstallPackage #packageArgs
https://ibb.co/Mpnh0mq
Exit code was '-1' means that the exit code of the installer was -1, and not 0 or another acceptable exit code to be treated as successful. You will need to figure out why your setup.exe is failing. You may be able to find more information about why the installer failed if you look at C:\ProgramData\Chocolatey\logs\chocolatey.log as the error indicates.
One thing I notice is you are not setting the silent installation arguments as part of your arguments to Install-ChocolateyInstallPackage, which at a minimum may cause your package to require interactivity (you don't want this). You should find out what the silent installation arguments are to setup.exe.
In your case, it looks like RVDS uses a different program to install silently (page 7). Note that this is for 3.1, not 4.1, so you should either try to find up to date documentation, or see if setupcli still exists in 4.1 and start looking at the parameters it supports.

Is there a command to restart computer into safe mode? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I would like to know if there is a command that could be written in the command line to restart the computer and make it boot in safe mode?
If there isn't a command like this, is there any other way to do it?
I would like the process to be fully automated after launching the command.
My first answer!
This will set the safemode switch:
bcdedit /set {current} safeboot minimal
with networking:
bcdedit /set {current} safeboot network
then reboot the machine with
shutdown /r
to put back in normal mode via dos:
bcdedit /deletevalue {current} safeboot
In the command prompt, type the command below and press Enter.
bcdedit /enum
Under the Windows Boot Loader sections, make note of the identifier value.
To start in safe mode from command prompt :
bcdedit /set {identifier} safeboot minimal
Then enter the command line to reboot your computer.

How to run an application as "run as administrator" from the command prompt? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a batch file called test.bat. I am calling the below instructions in the test.bat file:
start /min powershell.exe %sysdrive%\testScripts\testscript1.ps1
When I run this through the command prompt, my testscript is running successfully. I want to run it as administrator (as if I have created a desktop shortcut and run as administrator. It shouldn't prompt for any username or password).
I have tried adding /elevate and /NOUAC parameters in the above test.bat, but no luck. How do I fix this issue?
I know how to do it manually, but I want this to be executed from the command prompt.
(By Marnix Klooster): ...without using any additional tools, like those suggested in an answer to Super User question How to run program from command line with elevated rights.)
Try this:
runas.exe /savecred /user:administrator "%sysdrive%\testScripts\testscript1.ps1"
It saves the password the first time and never asks again. Maybe when you change the administrator password you will be prompted again.
See this TechNet article: Runas command documentation
From a command prompt:
C:\> runas /user:<localmachinename>\administrator cmd
Or, if you're connected to a domain:
C:\> runas /user:<DomainName>\<AdministratorAccountName> cmd
It looks like psexec -h is the way to do this:
-h If the target system is Windows Vista or higher, has the process
run with the account's elevated token, if available.
Which... doesn't seem to be listed in the online documentation in Sysinternals - PsExec.
But it works on my machine.