I am testing a windows driver software. When the test fails, I have to attach registry data to the bug.
I get
"ERROR: Unable to write to the file. There may be a disk or file system error."
when I run the following command
REG EXPORT HKLM\System\CurrentControlSet .\Reg-data\CCS.reg
(I am running the command in Administrator mode).
This happens very infreqently. Can this be caused by driver software? or could this be a generic OS issue?
You are not providing a destination filename to tell REG where to write the exported data to.
C:\>reg export /?
REG EXPORT KeyName **FileName** [/y]
Keyname ROOTKEY[\SubKey] (local machine only).
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY.
FileName The name of the disk file to export.
/y Force overwriting the existing file without prompt.
Examples:
REG EXPORT HKLM\Software\MyCo\MyApp AppBkUp.reg
Exports all subkeys and values of the key MyApp to the file AppBkUp.reg
I ran into the same problem when calling "reg export" (followed by a registry key and a path to write to) from a CMD file. The exact same command consistently worked when pasted to the same CMD prompt where the cmd script was run from, and consistently did not work from within the script.
I couldn't find the reason, but I worked around the problem by replacing "reg export" with "regedit /e", beware that you need to switch the position of the file path and registry key. This command works both inside and outside a cmd script.
So, here is before and after:
::reg export /y HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318} "%temp%\myfilename"
regedit /e /y "%temp%\myfilename" HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}
PS. Both commands will create a file in UTF16 format.
To make it short, it should be:
Reg Export "HKCU\SOFTWARE\Microsoft\Windows\Shell\Bags" "G:\reg\Shell_Bags.reg"
Related
I need to verify if a chrome extension is installed or not installed on remote computers.
Extension id is unique value like that "234aljksdfklja3idffklsasf".
I need to search "HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings"
direction for extension id "234aljksdfklja3idffklsasf"
How to do that?
i think i will use code below but i need some help
WMIC /NameSpace:\root\default Class StdRegProv ....
Instead of WMIC, you should use the REG cmd, it's made to do this.
The HKCU is whatever the user running the command's registry key is.
Reg allows you to load and check the registry keys of any users not just the one running the command, even users who have not logged in since the last reboot.
Since this is a chrome extension you may need to check every used on the system to see if each has it enabled individually.
Alternatively there is probably an HKLM key that corresponds to the extension being installed, if all you want to know is if it's present at all so it can be removed.
Reg also allows you to query your computers through the network.
One issue you will have if you need to check every user's registry for the key is you need to know what the user's SIDs present on the systen are.
This is findable by querying HKLM, but I am on mobile and can't recall how without getting on my computer later to do this.
Alternatively you can also just load the reg hive file by looping the fire tory structure of the remote machine and loading each user.dat file through the reg command which is much simpler but then the code must execute on each remote machine through a login script or GPO script push.
Basically you can use reg in this manner on a local machine to check the reg of the user you are running as (HKCU)
(reg query "HKCU\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings" /s | FIND /I "234aljksdfklja3idffklsasf") && Echo.FOUND 234aljksdfklja3idffklsasf
Of course to run on another computer it's fairly simple to do, but HKCU will be the reg of the admin user you ran the command as with access to that other system, or you can try HKLM to see if that setting exists on the local machine key, which the following checks HKLM instead.
(reg query \\[Computer_Name_or_IP_Address]\hklm\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings /s | FIND /I "234aljksdfklja3idffklsasf") && Echo.FOUND 234aljksdfklja3idffklsasf
You could loop a set of computer names/IPs and check each using the above command inside the loop like so:
FOR %A IN (
Computer_A
192.168.12.13
192.168.12.31
Computer_C
) DO (
(
reg query \\%~A\hklm\SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings /s | FIND /I "234aljksdfklja3idffklsasf"
) && Echo.%~A -- FOUND 234aljksdfklja3idffklsasf || ECHO.%~A -- Key Not Found!
)
If you need to check the actual HKCU of every used on the system then you need to load each reg hive on the system and check it, this is true if you use WMIC as well, and Reg is faster.
From the MS reg page:
reg query <KeyName> [{/v <ValueName> | /ve}] [/s] [/se <Separator>] [/f <Data>] [{/k | /d}] [/c] [/e] [/t <Type>] [/z]
i got one more solution to this situation. But only works if extension is packed. Btw this solution also doesnt solve my problem because my extension is unpacked.
Packeted extensions are stored "AppData\Local\Google\Chrome\User Data\Default\Extensions".
wmic /node:remoteip datafile where "name='C:\Users\username\AppData\Local\Google\Chrome\User Data\Default\Extensions\extensionid\1.0.4_0\manifest.json'"
if extension installed command returns manifest.json file specs.
I got the solution;
wmic /node:ipaddr /NAMESPACE:"\\root\DEFAULT" class stdregprov call GetStringValue ^&H80000001,"SOFTWARE\Google\Chrome\PreferenceMACs\Default\extensions.settings","extensionid"
On localhost, it works but on remote computers access denied.
I am trying to search a file on remote PC using PSEXEC, however I am getting the above mentioned error.
Can any please suggest any change in the command or some thing else, that can assist in making it work.
Online search suggests that this isn't the issue of PSEXEC, instead is caused by explorer.exe on remote host.
I have added picture of my result. I have tried the command with quotes on file name and without. both have same error.
This command dir exists with code 1 and message "File Not Found".
Because you run cmd with param /c than it return same error code like dir and it is equal 1.
It is correct behaviour.
If you want to find a file, than use command where /r c:\ d.txt. This command was added in Windows 7.
Or use dir /S /P "d.txt" for older OS
Open Registry Editor by pressing windows+r
then type regedit and press enter
now in the search bar paste the below line
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\
If you can see in the picture using the link
Underlined mark is important don't insert any other value in the data of that particular registry.
Here if you filed many registry values then delete all of them except the default one as they are the main reason for the error code 1 shown by the command prompt.
So after removing all of them.
Edit the default registry value and in 'data' insert cmd and save it
Your problem is solved!!
if not then clear the data of the default registry.
It is also easy to use PowerShell and not need psexec.
Invoke-Command HOST01 { & cmd.exe /C dir D:\Users\lit\d.txt }
It should be written in .ps1 scripts with parameter names specified.
Invoke-Command -ComputerName HOST01 -ScriptBlock { & cmd.exe /C dir D:\Users\lit\d.txt }
See also:
help Enable-PSRemoting
help about_Remote
help about_Remote_FAQ
It seems very simple but I couldn't fine a solution for this.
If I open command prompt in Window, It shows directory root like C:\Users\username very first. I wanted to change this because it is not convenient that I need to move to a directory I work every time when I open cmd.
Well,
I tried SET HOMEPATH \Users\username\what I want to go. It kept showing HOMEPATH=\Users\username on cmd screen. I twisted it like opening cmd as administrator and typing SETX HOMEPATH, HOME... trying other stuffs I searched.
but still, I couldn't find way to set a directory root I want to see very first in cmd.
Thank you.
You can
For a concrete change, create a shortcut to open cmd with the desired folder as the default active directory.
For a general change, include in the registry, under HKEY_CURRENT_USER\Software\Microsoft\Command Processor a new REG_SZ value called AutoRun and set its value to cd /d "c:\folder\where\I\work". Any cmd instance created without the /D switch will execute this code.
Or you can create the same value under the registry, but with a REG_EXPAND_SZ type and use as value something like cd /D "%MY_HOME_PATH%", and, of course, ensure the MY_HOME_PATH variable is properly defined before starting the cmd instance.
I'm wondering is there any option via command line to search for a string and export all found keys in Windows registry?
Ex:: If you want to check whether "HKLM\software\etc" key exists.
reg.exe query "HKLM\Software\etc" will return all the subkeys and values in command prompt if found or an error if not found.
ALso, you can directly do
reg.exe export "HKLM\software\etc" "C:\etc.reg"
This will export the registry key and subkeys if found otherwise error if not found.
Powershell has registry iteration capabilities. Start here: http://technet.microsoft.com/en-us/library/ee176841.aspx
export key (with all sub-keys), from CMD (or RUN) i.e.:
regedit /e c:\output.reg "HKEY_LOCAL_MACHINE\System\YourLocation"
p.s. you should run this in CMD with ADMIN PRIVILEGES. for that, right click on START>Run CMD (as Admin)
I did google couple of tutorials on google.
I am able to add right-click menu item to a FOLDER by doing this:
[HKEY_CLASSES_ROOT\Directory\shell\Command]
#="TestRightClick:"
[HKEY_CLASSES_ROOT\Directory\shell\Command\Command]
#="myExecutable.exe %L"
I need to add this to a FILE as well.
1) Where do I add it in the registry?
2) And how do I pass parameters to my executable in case if I am selecting multiple files?
Related:
How to pass in multiple file/folder paths via a rigth-click event(verb) to an executable?
You can do it with my program singleinstance.
No shell extensions involved.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\Shell\p4merge]
"MultiSelectModel"="Player"
[HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\Shell\p4merge\Command]
#="\"d:\\singleinstance.exe\" %1 \"C:\\Program Files\\Perforce\\p4merge.exe\" $files --si-timeout 400"
The key word you're looking for is 'verbs' or 'handlers' not 'events'.
Context menu verbs for particular file extensions can be placed under the ProgID for the file type, the Perceived Type key (if the file type has a perceived type), the AllFileSystemObjects key, or the Base Class Key (*).
Note that writing to these keys in the HKEY_CLASSES_ROOT hive will redirect the writes to HKEY_LOCAL_MACHINE\Software\Classes, and will require elevated privileges. If you write to the HKEY_CURRENT_USER\Software\Classes tree, you can do this with standard user rights.
It's up to you to handle a scenario where multiple files are selected. One instance of your application will be launched per file you have selected. You can solve this by checking if another instance of your application is running, and using Inter-Process Communication to notify the existing instance that other extensions have been selected.
On MSDN, be sure to read
Overview of Verbs and File
Associations
Creating Context Menu Handlers
Files have context menus by extension. Add your Command registry keys to the appropriate extension or HKEY_CLASSES_ROOT\* to affect all files.
You can use %1 to pass the filename to the application (much like you've indicated with %L above). If you select multiple files, each will be called separately, as if you right-clicked each one individually.
I'm not aware of any easy way to pass multiple items from a right-click context menu to one executable instance.
See GitHub SingleInstanceAccumulator for a C# implementation of the well worn Mutex + COPYDATA approach to this.
other stack-o's expressing the need.
Explorer Context Menu config
::creates the entry
:: and crucial multi-file handling property
reg add "HKEY_CLASSES_ROOT\FileType\shell\YourNewContextMenu" /f /v "MultiSelectModel" /d "Player"
::your desired command line
reg add "HKEY_CLASSES_ROOT\FileType\shell\YourNewContextMenu\command" /f /ve /t REG_EXPAND_SZ /d "***see command line examples***"
e.g. On my system, for ".mov" files, I would replace FileType above with VLC.mov
Complex REG ADD example
Replace "* see command line examples *" above with your desired command line.
Note: quotes & environment variables must be escaped and escaping work slightly differently for the initial command versus later in the string!?!
λ reg add "HKEY_CLASSES_ROOT\VLC.mov\shell\Transcode\command" /f /ve /t REG_EXPAND_SZ /d "\"^%bin^%\SingleInstanceAccumulator\" -f \"-c:powershell -ExecutionPolicy bypass "\"^%bin^%\test.ps1\"" -list '$files'\" \"%1\""
SingleInstanceAccumulator.exe Usage
"-c:command line" (default: cmd /c echo $files && pause)
$files will be replace with aggregated list
-f = output each item on separate line to new tempfile
$files will be replaced by the tempfile path
quote will default to nothing
-d:delimiter (default: ,)
-q:quote (default: ")
-t:timeout millisecs (default: 200)
-w = hidden launch
-v = debug output
Command Line Examples
note: initial command must have path for shell > command to work
PowerShell & temp file
note: -f usage
"%bin%\SingleInstanceAccumulator" -f "-c:powershell -ExecutionPolicy bypass "%bin%\test.ps1" -list '$files'" "%1"
PowerShell & inline files list
note: -q usage
"%bin%\SingleInstanceAccumulator" -q:' "-c:powershell -ExecutionPolicy bypass "%bin%\test.ps1" -list $files" "%1"
test.ps1 (with temp file)
powershell
param(
[String]$listFilePath
)
gc $listFilePath | % { $_ }
pause
erase $listFilePath
pause
test.ps1 (with files array parm)
param(
[String[]]$filesList
)
$filesList | % { $_ }
pause