cmd: regedit from cmd - cmd

how can i run to a specify path in regedit from cmd? I would like to add a new key to a specific service. Can someone help me? I would like to do this from a c# code, but first i am trying to do it from cmd. Thx
i would like to navigate from cmd to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Service and add in the Service service a new key with a value. i did write in cmd: regedit "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Service" add /v KeyName Parameters but i have an error saying that it can't load the file. why?

you can use
reg add "HKLM\SYSTEM\CurrentControlSet\services\Service" /v "KeyName" /d "Parameters" /f
Which would create a value (/v) named KeyName with data containing Parameters. the /f switch is used to override any confirmations and interruptions so the command can be executed without user input,omit for testing. additionaly,you can replace /v with /ve (value empty) and not specify a value name at all. this allows writting data (/d) to the default key value. also,if the path you intent to write to doesn't exist,the keys will be created without any warning.
for more information type reg /? in the command line

To add a Registry Entry from cmd using regedit, create a *.reg file containing the data you want to add. Simple example:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\TestKey]
"TestDWORD"=dword:00000123
and then execute this: regedit /s myreg.reg
This adds a Key (displayed like a folder in the regedit browser) named TestKey to HKEY_CURRENT_USER\Software. The TestKey Key contains a DWORD entry named "TestDWORD" that contains 123 in hex (291 in decimal)
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\TestKey]
"TestDWORD"=dword:00000123
[HKEY_CURRENT_USER\Software\TestKey\SubKey]
"StringEntry"="StringValue"
This creates TestKey # HKEY_CURRENT_USER\Software plus a sub-key "SubKey" of TestKey with a String Entry (named "StringEntry") and value of "StringValue"
There's a simple way to find out how to create different kinds of entries: Use the regedit gui to create the desired entries, then mark the key and use the Menu File -> Export. The generated file will contain the key(s) and it's entries.
To create a Registry Entry in C#: http://msdn.microsoft.com/en-us/library/h5e7chcf.aspx

I don't know what "run to a specify path in regedit from cmd" means.
However, if you want set a registry key from a batch file, just create a .reg file by exporting it from Regedit, then run reg import [filename.reg] (where [filename.reg] is the name of the file you exported).
If you want to open up Regedit to show a certain key, see How to launch Windows' RegEdit with certain path?.

Related

How to Open Desktop Properties from CMD?

First post here..
I'm writing a program and I need to change the location of the Desktop from Java, (or CMD).
Is there a CMD command that will open the Desktop properties? (where you can modify the location of the desktop)
Thanks,
You can change the location in the registry.
The following batch file example should set the location to %USERPROFILE%\Desktop, (which is the default).
#Echo Off
Reg Add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Desktop" /V "Path" /T REG_EXPAND_SZ /D "%%USERPROFILE%%\Desktop" /F >Nul
I'll leave it to you to change it to a single cmd.exe command if you'd prefer to do it at the Command prompt or if you think changing the registry another way would be easier for you.
You can enter any valid UNC name or mapped drive in the value of this entry. Just remember that as this is an EXPAND string, you should double up the percent characters if using variables you want to expand when accessed.

Trying to remove Startup reg key

I want to run a batch to remove a reg key from the start up.
I created a test key and I'm running the command below
Reg Delete "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run\Test" /F
But when I run the batch as Administrator I get the following error
"ERROR: The system was unable to find the specified registry key or value.
The key does exist in the reg but it will not appear in the command prompt.
Can any see what is going wrong here? or what command do I need to do to remove this reg key?
Replace HKEY_LOCAL_MACHINE with HKLM
Type reg /? at the command line for proper syntax.

Need help adding registry key via batch file

I am trying to add the following registry key through cmd. I am not able to get other users to be able to add this registry key using regedit.exe /s "Location\Project.reg".
[HKEY_CURRENT_USER\Software\Autodesk\Fabrication 2014\Configuration\1011-Shady-Grove]
"Path"="C:/Autodesk/Profiles/05MA/1011-Shady-Grove"
You are using the wrong tool. Regedit is a GUI tool. Yes you can use the /s switch, but fundamentally this is the wrong tool. Plus it is built with the highestAvailable option in the UAC manifest.
What you need is reg. Use it like this:
reg add "HKCU\Software\Autodesk\Fabrication 2014\Configuration\1011-Shady-Grove" /v Path /d C:/Autodesk/Profiles/05MA/1011-Shady-Grove
AFAIK, regedit will refuse to do anything if the user doesn't have administrative access, even if he has access to the registry keys.
Try the reg add command.

launch VBS script after PC startup

I want launch my simple VBS script after PC startup (Win XP). I don't want put this script in C:\Documents and Settings\%UserName%\Start Menu\Programs\Startup
I want do it in script, it is possible?
Script:<br>
Dim oShell<br>
Set oShell = WScript.CreateObject ("WScript.Shell")<br>
oShell.run "notepad.exe c:\text.txt"
You will either have to put it in the Startup folder or run it from the registry.
For all users, use registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run.
For the current user, use registry key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
In-depth
How to Automate VBScripts to run at startup.
Step 1
Click Start -> Run -> cmd or Click search and type cmd
Press enter
Type assoc .vbs in command prompt
Which should print .vbs=VBSFile
Type ftype VBSFile in command prompt
which should print:
vbsfile="%SystemRoot%\System32\WScript.exe" "%1" %*
So, now you know that your vbscript files open with WScript by default.
In command-prompt, type:
reg query HKEY_CLASSES_ROOT\Applications\WScript.exe /s
If you do not see this:
HKEY_CLASSES_ROOT\Applications\WScript.exe
(Standard) REG_SZ "%SystemRoot%\System32\WScript.exe" "%1" %*
Then you need to do the following, if the above is what you see, then you can skip and go to step 3:
Step 2
Go to:
Start
Run
Type in:
regedit
Select regedit press enter (or double-click regedit) and allow the
program to make changes to your computer
Navigate to:
HKEY_CLASSES_ROOT\Applications\WScript.exe (If WScript.exe key does not exist, right-click Applications and create new key, rename it to WScript.exe)
In the empty space on the right, where there are values, right-click
and
Choose new
Select String Value
Under Name where New Value #1 is highlighted, rename by typing
(Standard)
Under Data, double click the empty value and enter the value you got
from the previous step
"%SystemRoot%\System32\WScript.exe" "%1" %*
Step 3
If you do not have regedit open,
Go to:
Start
Run
Type in:
regedit
Select app, press enter and allow the program to make changes to your computer
Else, if regedit is open, then:
Navigate to:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Right click the run folder
in the empty space on the right, where there are values, right-click
and choose new
Select Expandable String Value
Under Name where New Value #1 is highlighted, rename by typing your
own name e.g. myscript
under Data, double click the empty value and enter this
Make sure its type is REG_EXPAND_SZ, i.e. an expanded string
"%SystemRoot%\System32\WScript.exe" "C:\Users\me\myFolder\mySub-folder\myFile.vbs" "%1" %*
Restart your machine. Your vbs should run automatically
Notes:
make sure .VBS is added to the Path environment variable
if you want to use cscript instead, In step 2 type:
reg query HKEY_CLASSES_ROOT\Applications\cscript.exe /s
...instead and proceed, taking note to replace WScript with cscript where relevant
i.e. this query:
reg query HKEY_CLASSES_ROOT\Applications\cscript.exe /s
Should produce this result:
(Standard) REG_SZ "C:\Windows\System32\cscript.exe" "%1" %*
If your key and/or value is messed up you can always right-click the
messed up item and delete it. If you however want to use the
terminal, you can always follow: http://ss64.com/nt/reg.html
To check if WScript is one of the startup apps, press ctrl+alt+delete, choose the Task Manager, click on Startup. You should see Microsoft Windows Based Script Host listed.
Easy Way :
Make a bat file
WScript.exe "Path\to\your\script.vbs"
add it to startup from gpedit.msc
Just an appoinment, everybody probalby just know already.
HKLM is for any user on the machine, because means Local Machine
HKCU is just for the current user.
Add this code to the start of your vbs script
Change the end of myKey to whatever you want to call the registry key
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\MyVbsScript"
WshShell.RegWrite myKey,WScript.ScriptFullName,"REG_SZ"
Task Scheduler Alternative
No script is needed, create a new task (Task Scheduler 1.0 (learn.microsoft.com) for instruction). Then "Create a task" and populate at least these details:
New Trigger: At Login
New Action -> Action: Start A Program
Program/Script: notepad.exe
Arguments: text.txt
Start in: c:\
Software: Windows 10, Task Scheduler 1.0
you can fire a vbscipt from registry or startup by
WScript C:\somefloder\somefolder2\yourscript.vbs
you can put this line in a value on
For all the users on the machine HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
for the current user HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

How to associate a file extension to a program without making it the default program

I'm deploying a small conversion tool on some systems, and want the users to be able to run it from the right click Open with menu. But I don't want to change the default program users have associated to this file type.
It is easy to associate a file extension/type to a program, but how to do it (programatically of course) without changing the default program?
Setting the following keys worked for me:
key HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/App Paths/<progname>: "" = <appPath>
key HKCR/Applications/<progname>/SupportedTypes: <fileExt> = ""
key HKCR/<fileExt>: "" = <progID>
key HKCR/<progID>/OpenWithList/<progName>
key HKCR/<fileExt>/OpenWithList/<progName>
key HKCR/SystemFileAssociations/<fileExt>/OpenWithList/<progName>
delete key and subkey at HKCU/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/fileExts/<fileExt>
You can add scripts to the context menu (below Open with) by adding it in the windows registry:
Open regedit
Goto HKEY_CLASSES_ROOT\your_class\Shell
Add a new key and give it a name
Edit the (Default) value of this key and insert the text you want to show in the context menu
Add a new key named Command under your newly created key
Edit the (Default) value of this key and insert the command you want to execute
Enjoy!
In the "File Types" Windows Dialog you can click "Advanced" on your file type and there create a custom action tied to your application.
Possibly you can also find a way to do this in a programmatic manner, or at least create a .REG file with the equivalent registry options.
I have achieved the correct FILE ASSOCIATION using these cmd commands.
(just an example):
REG ADD "HKEY_CLASSES_ROOT\Applications\notepad++.exe\shell\open\command" /v # /t REG_SZ /d "\"C:\\Program Files\\Noteepad++\\notepad++.exe\" \"%1\"" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt" /v "Application" /t REG_SZ /d "notepad++.exe" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithList" /v "g" /t REG_SZ /d "notepad++.exe" /f
assoc .txt=MyCustomType
ftype MyCustomType="C:\Program Files\Noteepad++\notepad++.exe" "%1"
(it's better to put them in .bat file)
here's a worked example for XP adding a command prompt option to folders. Create a .reg file
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt]
[HKEY_CLASSES_ROOT\Directory\shell\Command Prompt\command]
#="cmd.exe /k cd \"%1\""

Resources