bcdedit /copy syntax not correct - powershell

I'm trying to run Oracle Virtual Box on my work laptop. I'm getting an error saying that it can't run because I'm running Hyper-v. I'm trying to follow the instructions at Scott Hanselman's Blog, which have worked for me in the past on my personal laptop with a similar issue.
I run:
bcdedit /copy {current} /d "No Hyper V"
The copy command specified is not valid.
Run "bcdedit /?" for command line assistance.
The parameter is incorrect.
I run
bcdedit /copy {current} /d /?
This command creates a copy of the specified boot entry.
bcdedit [/store <filename>] /copy {<id>} /d <description>
<filename> Specifies the store to be used. If this option is not
specified, the system store is used. For more information,
run "bcdedit /? store".
<id> Specifies the identifier of the entry to be copied.
For more information about identifiers, run
"bcdedit /? ID".
<description> Specifies the description to be applied to the new entry.
Example:
The following command creates a copy of the specified operating system boot
entry:
bcdedit /copy {cbd971bf-b7b8-4885-951a-fa03044f5d71} /d "Copy of entry"
and
bcdedit /? ID
IDENTIFIERS
Many of the Bcdedit commands require identifiers. An identifier
uniquely identifies entries contained in the store. An identifier takes the
form of a globally unique identifier, or GUID. A GUID has the following format,
where each "x" represents a hexadecimal digit.
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
For example:
{d2b69192-8f14-11da-a31f-ea816ab185e9}
The position of the dashes (-) and the braces at the beginning and end of the
GUID are required.
Several entries can be identified by well-known identifiers. If an entry has a
well-known identifier, BCDedit displays it in output unless the /v command-line
switch is used. For more information, run "bcdedit /? /v".
The well-known identifiers are as follows:
{bootmgr} Specifies the Windows boot manager entry.
{fwbootmgr} Specifies the firmware boot manager entry,
specifically on systems that implement the
Extensible Firmware Interface (EFI) specification.
{memdiag} Specifies the memory diagnostic application entry.
{ntldr} Specifies a OS loader (Ntldr) that can be used
to start operating systems earlier than Windows
Vista.
{current} Specifies a virtual identifier that corresponds to
the operating system boot entry for the operating
system that is currently running.
but it looks like there's nothing wrong with my syntax, does anyone know what I'm doing wrong?

Powershell seems to have been the problem. In my powershell prompt I typed cmd and then ran bcdedit /copy {current} /d "No Hyper V" with no errors.

bcdedit --% /copy {current} /d "No Hyper V"
stop-parsing symbol --%
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing

I had exactly the same problem. I found the solution on this documentation of bcdedit from microsoft. This is just a problem when you are using powershell instead cmd.
You just have to set the identifier of the boot entry into double quotes:
bcdedit /copy "{current}" /d "No Hyper-V"

I had the same problem when the shell/command prompt is not running as administrator.
When not running as administrator, windows does not allow any read or write to BCD
> bcdedit /v
The boot configuration data store could not be opened.
Access is denied.
Running the shell or command prompt as administrator solved the issue.

Related

How do I change the hostname of a Windows PC with batch or powershell

I want to change the hostname of a computer from Batch (a.k.a. Command Prompt) or Powershell.
Initially I started research into using the wmic command. But running wmic /? on Windows 10 21H1 indicates it is now deprecated.
Then I looked at Get-WmiObject. But when I run man Get-WmiObject in PowerShell, the description indicates it has been "superseded" by Get-CimInstance.
Using the old Get-WmiObject command you could change your own computer's hostname with (Get-WmiObject Win32_ComputerSystem).Rename("New-Hostname").
What is a non-deprecated way to change your own Windows computer's hostname using Batch or PowerShell?
Thanks to #Theo for the tip.
The PowerShell command Rename-Computer
Rename-Computer "new-hostname"
Admin privileges and a computer restart are required.
The command warns you if the length of the hostname is longer than 15 characters.
The batch-file command...
NETDOM RENAMECOMPUTER "%ComputerName%" /Newname:"NewNameGoesHere" /FORCE
I made a simple code if you want to use it
#echo off
set /p newname=The name of the new device:
wmic computersystem where name="%computername%" call rename name="%newname%"
Anyway, this is what you are looking for
wmic computersystem where name="%computername%" call rename name="newname"

Running PS1 file from batch file, same folder on thumb drive

Admittedly I'm no scripter. I piece together what already works but trying to learn.
I have a script that does a lot of the manual labor for setting up a scan user for myself and our techs. Here is a small portion of it written as a batch file. At the end before the pause I want to call a PowerShell to show what the Network type is, not to change it. At least not at this time. I did remove alot of the extra from the file to save space. Both the batch file and the PS1 file will be in the same folder on a thumb drive.
The nettype.ps1 file just has:
get-netconnectionprofile
pause
The pause of course is so the tech can see the network type.
Hope someone has a simple solution. I did look here and other websites. I may not be using the right terminology in my search or understanding what I need done.
net user Scans Scanner1 /add
net localgroup administrators Scans /add
wmic UserAccount where Name='Scans' set PasswordExpires=False
md C:\Scans
#echo off
NET SHARE Scans=C:\Scans /Grant:Scans,Full
ICACLS "C:\Scans" /Grant Scans:(OI)(CI)(F) /t /c
ICACLS "C:\Scans" /Grant Everyone:(OI)(CI)(F) /t /c
netsh advfirewall firewall set rule group="Network Discovery" new enable=Yes
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
PowerShell.exe -File "nettype.ps1"
pause
If that is all you have inside your powershell script, don't run it as a script, delete it and just run the command directly in your batch-file:
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -Command "Get-NetConnectionProfile"
Which could be probably be shortened to:
PowerShell Get-NetConnectionProfile
I found the answer, knew it would be simple.
Just had to use the following in the batch file:
powershell.exe -ExecutionPolicy Bypass -File ""%~dp0nettype.ps1""
You can change the powershell call to the following to find the ps1 file in the same directory:
powershell.exe -File "%~dp0nettype.ps1"
%~dp0 is a combination of %0 variable and ~d and ~p modifiers.
%0 is the full path to the current batch file.
~d when combined with %0 (e.g. %~d0) will get you drive letter portion (e.g. C:) from %0.
~p when combined with %0 (e.g. %~p0) will get you the path portion of %0 without the filename.
Combining them together, %~dp0, will get you the full path of the folder where current batch file is located.
You can find a complete list of these modifiers here: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490909(v=technet.10)?redirectedfrom=MSDN
One thing to note, is that %~dp0 modifier only works in batch files, not when you try to run on commandline directly.

Win10: How to activate developer mode using powershell or cmd.exe?

I want to activate the developer mode (to use the ubuntu subsystem), but I don't have admin account credentials. However, I have access to a cmd.exe with admin rights. So I can open regedit and use the powershell without restrictions. Some tutorials (this one for example) state that the dev mode can be easily activated by creating or setting special keys in the registry:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock\AllowDevelopmentWithoutDevLicense
In my case these keys did not exist in the registry before, so I added them manually. Sadly, it does not work and dev mode is still inactive. I also tried to open the Settings App using the terminal (start ms-settings:) and enable dev mode using the GUI, but it seems like the start command ignores/flushes the admin previleges and the app asks for credentials.
OS: Win10
Build Version: 14393.1198
EDIT
Because of #magicandre1981 answer, I tried to run the following command
DISM /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
But I got this error:
Deployment Image Servicing and Management tool
Version: 10.0.14393.0
Error: 11
You cannot service a running 64-bit operating system with a 32-bit version of DISM.
Please use the version of DISM that corresponds to your computer's architecture.
The DISM log file can be found at C:\WINDOWS\Logs\DISM\dism.log
With the help of google, I found out that I have to use a different cmd.exe version located in C:\\Windows\native. So I navigated there and called cmd.exe. After that I got another error, that the current directory is invalid, but after navigating back to C:\\Windows\System32 the command finished without an error. However, it still does not work. I restarted the system and the dev mode is still not activated.
In the cmd.exe that is running as admin, run the following 2 commands:
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
and
DISM /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
Depending on Which Windows 10 Build you run, you may need to reboot the system to finish setup.
To enable the Linux Subsystem, open a cmd.exe as admin and run
DISM /Online /Enable-Feature /FeatureName:Microsoft-Windows-Subsystem-Linux
Once in cmd/admin, run mmc compmgmt.msc and create yourself a user with administrator rights. Log in as that user, pwn.
There are official instructions:
https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging
To enable sideloading:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowAllTrustedApps" /d "1"
To enable developer mode:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
Bonus: to enable (outdated) SSH for UWP remote deployment & Windows Device Portal:
dism /Online /Add-Capability /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
dism /Online /Get-CapabilityInfo /CapabilityName:Tools.DeveloperMode.Core~~~~0.0.1.0
See details about capability here: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/features-on-demand-non-language-fod?view=windows-10#developer-mode

The specified path is not valid

I am in a windows console or powershell. (Windows7 x64 Pro, PowerShell 4)
When i try to type command like "cmd" i have an error message "The specified path is not valid"
PS D:\DevEnv\workspace\api-node> cmd
Microsoft Windows [version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All right reserved.
The specified path is not valid.
What i tryed after reading msdn articles but it don't solve the problem:
-delete my System variable PATH and try again
-clean my registry with ccleaner
Is there any "verbose" or "debug" mode in powershell or windows console to see what path is involved and where i can change it?
Is there any "verbose" or "debug" mode …? I don't think so; however, running next commands from an open cmd window could help to identify possible error source(s):
wmic process where "name='cmd.exe'" get Caption, CommandLine, ParentProcessId, ProcessId
2>NUL reg query "HKLM\Software\Microsoft\Command Processor" /V AutoRun
2>NUL reg query "HKCU\Software\Microsoft\Command Processor" /V AutoRun
In above output we are seeking for any commands which could be a source of The specified path is not valid error message.
wmic seems to be self-explaining;
both reg query show AutoRun registry values (if present), see cmd /?.

Getting error while installing "azure-powershell.0.8.7.msi" through .cmd file

I am trying to install “azure-powershell.0.8.7.msi” through a .cmd file using command
msiexec.exe /i ".\azure-powershell.0.8.7.MSI" /passive
This msi file is part of solution explorer(part of project, I have to do it in this way only).
Although I am able to install/uninstall when this msi file when it’s on local disk ( i.e. on some drive)
I tried to log the error it is:
“This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.”
It is a known error of Microsoft. I tried each and every proposed solution on internet but it doesn’t work.
Note: The current user/admin of the system have all the access(read,write,modify).
if your MSI-file is in the same directory like the cmd-file you have to us the following command
msiexec /i "%~dp0azure-powershell.0.8.7.MSI" /qb
%~dp0 is refering to cmd-file directory and in this case to the MSI-file.
If you want to create a log-file use the /l and the logfilepath plus name after /qb.
For example:
msiexec /i "%~dp0azure-powershell.0.8.7.MSI" /qb /l*v %temp%\azure-powershell.log