Is it possible to convert the epsilon or UltraEdit macro to exe? - macros

If anyone know about how to convert the epsilon and UltraEdit macros to exe.
Could you please?

An UltraEdit macro can't be converted into an executable. The UltraEdit macro commands can be executed only by UltraEdit.
But it is possible to run an UltraEdit macro from within a batch file using UltraEdit to automate file reformatting tasks using an UE macro.
Here is a commented example for such a batch file:
#echo off
rem Get name of UltraEdit executable with full path from Windows registry.
set "UltraEditEXE="
call :GetFileNameUE "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\uedit32.exe"
if not "%UltraEditEXE%" == "" goto RunMacro
call :GetFileNameUE "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\uedit64.exe"
if not "%UltraEditEXE%" == "" goto RunMacro
call :GetFileNameUE "HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\uedit32.exe"
if not "%UltraEditEXE%" == "" goto RunMacro
call :GetFileNameUE "HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\uedit64.exe"
if not "%UltraEditEXE%" == "" goto RunMacro
echo UltraEdit is not installed most likely as no uedit*.exe found.
echo.
pause
goto :EOF
rem Run UltraEdit using Windows command start to run UE minimized with forcing
rem always an new instance of UltraEdit, opening a file and processing this
rem file with an UltraEdit macro. This instance of UltraEdit is automatically
rem exited after macro executed once on the opened file. The macro must save
rem the file before exiting. While UltraEdit is running the batch procssing
rem is continued with deleting the environment variable and then exiting
rem batch processing. See in help of UltraEdit the page with title "Command
rem Line Parameters" for details on the used UE command line parameters.
:RunMacro
start "Run UE macro" /min "%UltraEditEXE%" /fni "Path\Name of file to modify.txt" /M,E,1="Macro file with full path/Macro Name"
set "UltraEditEXE="
goto :EOF
rem This is a subroutine called up to 4 times to determine name of UltraEdit
rem executable with full path from Windows registry if UltraEdit is installed
rem at all. It assigns file name of UltraEdit with full path and with file
rem extension to environment variable UltraEditEXE on success finding the
rem registry value in registry key passed as parameter to this subroutine.
:GetFileNameUE
for /F "skip=2 tokens=3*" %%A in ('%SystemRoot%\System32\reg.exe QUERY %1 /ve 2^>nul') do (
if "%%A" == "REG_SZ" set "UltraEditEXE=%%B" & goto :EOF
)
goto :EOF
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
echo /?
for /?
goto /?
if /?
pause /?
reg query /?
rem /?
set /?
start /?

Related

Why is my GOTO statement not working (batch)

It always goes to the first lapel no matter what is the input
I saw other posts with the same issue but none of the syntax mistakes they made were present in my script.
Here is the script :
#echo off
cls
cd /d %~dp0
echo "Include files? [Y/N]"
set /p option=
if %option%=="Y" GOTO yes
if %option%=="y" GOTO yes
if %option%=="N" GOTO no
if %option%=="n" GOTO no
:yes
cls
powershell -command "iex \"tree /f\" > \"tree-filed.txt\""
GOTO end
:no
cls
powershell -command "iex \"tree\" > \"tree-folders.txt\""
GOTO end
:end
cls
echo the tree list was created.
pause
What am I missing?
rifteyy's solution is effective, but some background information may be helpful:
As Squashman notes, an if conditional either requires both sides to be either (double-)quoted or unquoted; that is, both if %option%==y ... and if "%option%"=="y" ... work:
The double-quoted form is more robust, as it also handles values with metacharacters such as & correctly, but the match must be exact with respect to presence or absence of spaces.
Conversely, only the unquoted form is forgiving of leading and trailing spaces; e.g. if %option%==y ... still works if the user entered y rather than just y.
You can use if's /I option to make the comparison case-insensitive, which obviates the need to check for y and Y separately, for instance. help if shows more information.
tree.com is a stand-alone executable that can be called from any (Windows) shell, so there is generally no good reason to call PowerShell (powershell.exe, which is expensive), given that you can invoke tree directly from your batch file - though you may need PowerShell to control the character encoding of the output files.[1]
As an aside: Inside PowerShell there is no need for Invoke-Expression (iex), which should generally be avoided; the best way to invoke an external executable such as tree.com fundamentally works the same as from cmd.exe (see below).
If you do need PowerShell, call it as follows, for instance:
powershell -command "tree > tree-folders.txt"
Therefore, a streamlined version of your batch file would look like this (cls commands omitted):
#echo off
cd /d "%~dp0"
:prompt
echo "Include files? [Y/N/Q]"
set /p option=
if /I "%option%"=="y" GOTO yes
if /I "%option%"=="n" GOTO no
if /I "%option%"=="q" GOTO :eof
goto prompt
:yes
tree /f > tree-files.txt
GOTO end
:no
tree > tree-folders.txt
GOTO end
:end
echo the tree list was created.
pause
As Stephan points out, the standard choice.exe utility offers a simpler prompting solution:
choice /c ynq /m "Include files?"
if %ERRORLEVEL% EQU 1 goto yes
if %ERRORLEVEL% EQU 2 goto no
goto :eof
choice.exe:
is case-insensitive by default (use /CS for case-sensitivity)
accepts only a single input character from the user, which instantly exits the prompt (no Enter keypress required), with the %ERRORLEVEL% variable set to the 1-based position of the character in the list of permitted characters passed to /C
Note: The above deliberately uses, e.g., if %ERRORLEVEL% EQU 1 rather than if ERRORLEVEL 1, because the latter uses equal-or-greater logic, which would require you to reverse the order of the branching statements.
automatically validates the input (beeps if an invalid character is typed)
See choice /? for more information.
[1] However, you do need PowerShell if the command's output contains non-ASCII characters and you want the output redirection (>) to create UTF-16LE ("Unicode") files (Windows PowerShell) or (BOM-less) UTF-8 files (PowerShell (Core) v6+). Using > from cmd.exe results in OEM-encoded files, based on the console's code page, reported via chcp. Alternatively, you could switch the console code page to (BOM-less) UTF-8, via chcp 65001, but that wouldn't work with tree.com, because it is too old to support this code page. By contrast, it would work with the output from dir, for instance.
You must use brackets in IF statement also, if you did not, it will automatically do the actions under the IF statements.
#echo off
cls
cd /d %~dp0
echo "Include files? [Y/N]"
set /p option=
if "%option%"=="Y" GOTO yes
if "%option%"=="y" GOTO yes
if "%option%"=="N" GOTO no
if "%option%"=="n" GOTO no
:yes
cls
powershell -command "iex \"tree /f\" > \"tree-filed.txt\""
GOTO end
:no
cls
powershell -command "iex \"tree\" > \"tree-folders.txt\""
GOTO end
:end
cls
echo the tree list was created.
pause

Automating the process of importing project into eclipse workspace using command line interface not working as expected

I have command line argument for importing existing project into eclipse work space. But as soon as I try to execute it using windows batch file eclipse opens and starts loading and closes immediately. Here is the code that I am trying to run.
ECHO on
PUSHD
SET ECLPSE=%cd%
SET WORKSPACE=%~dp0
POPD
SET PATH=%PATH%;%ECLPSE%\bin;
RD /s /q %ECLPSE%\configuration\org.eclipse.equinox.app > Nul
RD /s /q %ECLPSE%\configuration\org.eclipse.osgi > Nul
RD /s /q %ECLPSE%\configuration\org.eclipse.update > Nul
START /B %ECLPSE%\bin\tresos_gui.exe -Dmsg1085=false -data %WORKSPACE% %*
START /B %ECLPSE%\bin\tresos_gui.exe importProject -c C:\Jenkins\jobs
This is the syntax for importing a project into the workspace.
tresos_cmd.bat [<system_property>...] [-data <workspace>]
importProject [-c] <project path>...
Can someone please help me with this. I would really appreciate it. I have even combined last two statements in one line and tried executing it but it is of no use. My main aim is to automate the process of importing project into eclipse workspace so that software can be built using jenkins.
All folder paths containing %ECLPSE% or %WORKSPACE% should be enclosed in double quotes in case of %cd% and/or %~dp0 expand to a folder path with a space character or one of the characters &()[]{}^=;!'+,`~.
I did not really understand what is the goal of the batch file and what tresos_gui.exe is for.
However, here is an improved and commented batch file.
#echo off
setlocal EnableExtensions
rem Path of current directory hold in environment variable CD usually does
rem not end with a backslash (directory separator on Windows). But if the
rem current directory is the root directory of a drive, the directory path
rem ends with a backslash. Assign current directory path to environment
rem variable ECLPSE (strange name) always without a trailing backslash.
if not "%CD:~-1%" == "\" ( set "ECLPSE=%CD%" ) else ( set "ECLPSE=%CD:~0,-1%" )
rem Path of batch file always ends with a backslash, but should be assigned
rem to environment variable WORKSPACE always without a trailing backslash.
set "WORKSPACE=%~dp0"
set "WORKSPACE=%WORKSPACE:~0,-1%"
rem The environment variable PATH can end with a folder path or with a
rem semicolon after last folder path. The subdirectory BIN in current
rem directory should be appended with an additional semicolon only if
rem environment variable PATH does not already end with a semicolon.
if "%PATH:~-1%" == ";" ( set "PATH=%PATH%%ECLPSE%\bin" ) else ( set "PATH=%PATH%;%ECLPSE%\bin" )
rem Command RD does not print any message on success. It prints only an error
rem message to handle STDERR if the directory tree could not be removed.
rd /Q /S "%ECLPSE%\configuration\org.eclipse.equinox.app" 2>nul
rd /Q /S "%ECLPSE%\configuration\org.eclipse.osgi" 2>nul
rd /Q /S "%ECLPSE%\configuration\org.eclipse.update" 2>nul
rem Command START interprets first double quoted string as title for the
rem command process window. Therefore specify as first parameter just ""
rem which is an empty title string.
rem The start of tresos_gui.exe is done for some unknown reason in a separate
rem process in background. Hold execution of batch file until this separate
rem process terminated itself before running tresos_gui.exe a second time
rem to import the project and best wait again until this process terminated.
start "" /WAIT /B "%ECLPSE%\bin\tresos_gui.exe" -Dmsg1085=false -data "%WORKSPACE%" %*
start "" /WAIT /B "%ECLPSE%\bin\tresos_gui.exe" importProject -c C:\Jenkins\jobs
endlocal
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /? ... explains %*
cmd /? ... explains with last paragraph on last help page when double quotes are required.
echo /?
endlocal /?
if /?
rd /?
rem /?
setlocal /?
start /?
And read also the Microsoft TechNet article Using command redirection operators for an explanation of 2>nul.

How to launch html report from cake (build)

I'm using cake in my projects to build, run unit tests, check code coverage and then generate an HTML report (using ReportGenerator). This is all working correctly, and I can open the generated report in my browser.
However, when I was previously using a dos batch file to do this, it would also launch my default browser and load the report after it was generated, but I can't find a way to do that with cake.
Here are the contents of the batch file I've been using:
#ECHO OFF
SET SearchDirectory=%~dp0Grapevine.Tests\bin\Debug
SET DllContainingTests=%~dp0Grapevine.Tests\bin\Debug\Grapevine.Tests.dll
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="xunit.console.exe" SET TestRunnerExe=%%~dpnxa
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="OpenCover.Console.exe" SET OpenCoverExe=%%~dpnxa
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="ReportGenerator.exe" SET ReportGeneratorExe=%%~dpnxa
if not exist "%~dp0GeneratedReports" mkdir "%~dp0GeneratedReports"
call :RunOpenCoverUnitTestMetrics
if %errorlevel% equ 0 (
call :RunReportGeneratorOutput
)
if %errorlevel% equ 0 (
call :RunLaunchReport
)
exit /b %errorlevel%
:RunOpenCoverUnitTestMetrics
"%OpenCoverExe%" ^
-target:"%TestRunnerExe%" ^
-targetargs:"\"%DllContainingTests%\"" ^
-filter:"+[*]* -[*.Tests*]* -[*]*.*Config -[xunit*]* -[*]Grapevine.Interfaces.*" ^
-mergebyhash ^
-skipautoprops ^
-register:user ^
-output:"%~dp0GeneratedReports\CoverageReport.xml"^
-searchdirs:"%SearchDirectory%"
exit /b %errorlevel%
:RunReportGeneratorOutput
"%ReportGeneratorExe%" ^
-reports:"%~dp0\GeneratedReports\CoverageReport.xml" ^
-targetdir:"%~dp0\GeneratedReports\ReportGeneratorOutput"
exit /b %errorlevel%
:RunLaunchReport
start "report" "%~dp0\GeneratedReports\ReportGeneratorOutput\index.htm"
exit /b %errorlevel%
I have tried using the following:
StartProcess(new FilePath("./GeneratedReports/ReportGeneratorOutput/index.htm"));
To which I receive the following error:
An error occured when executing task 'generate-report'.
Error: The specified executable is not a valid application for this OS platform.
I have verified that the path is correct and the file exists, and that copy/pasting the file path on the command line indeed opens the file in my default browser.
I couldn't figure out a way to do this with just Cake, so I resorted to calling CMD with StartProcess:
if (IsRunningOnWindows()) {
StartProcess("cmd", new ProcessSettings {
Arguments = $"/C start \"\" {testCoverageReportPath}index.htm"
});
}
This works great for my needs.
You can do this using the StartProcess alias example:
FilePath reportpath = File("./GeneratedReports/ReportGeneratorOutput/index.htm");
StartProcess(reportpath);
What finally worked for me was this:
if (IsRunningOnWindows())
{
StartProcess("explorer.exe", reportPath);
}
Obviously, this won't work on non-windows environments, but that's outside the scope of my needs. Everything else I tried produced an error either that the file could not be found or that the executable was invalid for the OS.

Loop through each line of text file and run command against each

I am trying to adjust some code which is shown below and hitting walls.
The commandline appears as:
cmd.exe /U /C "C:\Program Files\StorageCraft\ShadowProtect\VerifyImages.cmd <PathOfDirectoryWhichContainsImageFiles> <PathToOutputLogFile>
The code basically runs an image verify command against all md5 files in a directory. The problem is that some directories have >200 md5 files and I only want to verify the files created in the last 24 hrs.
I have been able to create a list of the files created in the last 24hrs and output to a text file using a powershell command.
Is it possible to adjust the script below so that it reads the text file line by line and runs the VERIFY_SUB against each? I have tried using the FOR /F command with little luck to this point.
Thanks in advance.
REM *** START OF MAIN ROUTINE ***
SETLOCAL
PUSHD
CD /D %~dp0
REM Strip the outer quotes off of the directory parameter
SET PARAM_DIR=%1
SET PARAM_DIR=###%PARAM_DIR%###
SET PARAM_DIR=%PARAM_DIR:"###=%
SET PARAM_DIR=%PARAM_DIR:###"=%
SET PARAM_DIR=%PARAM_DIR:###=%
REM Strip the outer quotes off of the output log file parameter
SET PARAM_OUTPUT_FILE=%2
SET PARAM_OUTPUT_FILE=###%PARAM_OUTPUT_FILE%###
SET PARAM_OUTPUT_FILE=%PARAM_OUTPUT_FILE:"###=%
SET PARAM_OUTPUT_FILE=%PARAM_OUTPUT_FILE:###"=%
SET PARAM_OUTPUT_FILE=%PARAM_OUTPUT_FILE:###=%
FOR %%A IN ("%PARAM_DIR%\*.md5") DO (call :VERIFY_SUB "%%A" "%PARAM_OUTPUT_FILE%")
POPD
ENDLOCAL
GOTO :EOF
REM *** END OF MAIN ROUTINE ***
:VERIFY_SUB
#ECHO VERIFYING MD5 FILE %1
#ECHO VERIFYING MD5 FILE %1 >> %2
image.exe v %1 >> %2
#ECHO. >> %2
#ECHO. >> %2
#ECHO. >> %2
GOTO :EOF

How to launch Windows' RegEdit with certain path?

How do I launch Windows' RegEdit with certain path located, like "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0", so I don't have to do the clicking?
What's the command line argument to do this? Or is there a place to find the explanation of RegEdit's switches?
Use the following batch file (add to filename.bat):
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_SZ /d Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Veritas\NetBackup\CurrentVersion\Config /f
START regedit
to replace:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Veritas\NetBackup\CurrentVersion\Config
with your registry path.
There's a program called RegJump, by Mark Russinovich, that does just what you want. It'll launch regedit and move it to the key you want from the command line.
RegJump uses (or at least used to) use the same regedit window on each invoke, so if you want multiple regedit sessions open, you'll still have to do things the old fashioned way for all but the one RegJump has adopted. A minor caveat, but one to keep note of, anyway.
From http://windowsxp.mvps.org/jumpreg.htm (I have not tried any of these):
When you start Regedit, it automatically opens the last key that was viewed. (Registry Editor in Windows XP saves the last viewed registry key in a separate location). If you wish to jump to a particular registry key directly without navigating the paths manually, you may use any of these methods / tools.
Option 1
Using a VBScript: Copy these lines to a Notepad document as save as registry.vbs
'Launches Registry Editor with the chosen branch open automatically
'Author : Ramesh Srinivasan
'Website: http://windowsxp.mvps.org
Set WshShell = CreateObject("WScript.Shell")
Dim MyKey
MyKey = Inputbox("Type the Registry path")
MyKey = "My Computer\" & MyKey
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Lastkey",MyKey,"REG_SZ"
WshShell.Run "regedit", 1,True
Set WshShell = Nothing
Double-click Registry.vbs and then type the full registry path which you want to open.
Example: HKEY_CLASSES_ROOT\.MP3
Limitation: The above method does not help if Regedit is already open.
Note: For Windows 7, you need to replace the line MyKey = "My Computer\" & MyKey with MyKey = "Computer\" & MyKey (remove the string My). For a German Windows XP the string "My Computer\" must be replaced by "Arbeitsplatz\".
Option 2
Regjump from Sysinternals.com
This little command-line applet takes a registry path and makes Regedit open to that path. It accepts root keys in standard (e.g. HKEY_LOCAL_MACHINE) and abbreviated form (e.g. HKLM).
Usage: regjump [path]
Example: C:\Regjump HKEY_CLASSES_ROOT\.mp3
Option 3
12Ghosts JumpReg from 12ghosts.com
Jump to registry keys from a tray icon! This is a surprisingly useful tool. You can manage and directly jump to frequently accessed registry keys. Unlimited list size, jump to keys and values, get current key with one click, jump to key in clipboard, jump to same in key in HKCU or HKLM. Manage and sort keys with comments in an easy-to-use tray icon menu. Create shortcuts for registry keys.
I'd also like to note that you can view and edit the registry from within PowerShell. Launch it, and use set-location to open the registry location of your choice. The short name of an HKEY is used like a drive letter in the file system (so to go to HKEY_LOCAL_MACHINE\Software, you'd say: set-location hklm:\Software).
More details about managing the registry in PowerShell can be found by typing get-help Registry at the PowerShell command prompt.
Here is one more batch file solution with several enhancements in comparison to the other batch solutions posted here.
It sets also string value LastKey updated by Regedit itself on every exit to show after start the same key as on last exit.
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "RootName=Computer"
set "RegKey=%~1"
if defined RegKey goto PrepareKey
echo/
echo Please enter the path of the registry key to open.
echo/
set "RegKey="
set /P "RegKey=Key path: "
rem Exit batch file without starting Regedit if nothing entered by user.
if not defined RegKey goto EndBatch
:PrepareKey
rem Remove double quotes and square brackets from entered key path.
set "RegKey=%RegKey:"=%"
if not defined RegKey goto EndBatch
set "RegKey=%RegKey:[=%"
if not defined RegKey goto EndBatch
set "RegKey=%RegKey:]=%"
if not defined RegKey goto EndBatch
rem Replace hive name abbreviation by appropriate long name.
set "Abbreviation=%RegKey:~0,4%"
if /I "%Abbreviation%" == "HKCC" set "RegKey=HKEY_CURRENT_CONFIG%RegKey:~4%" & goto GetRootName
if /I "%Abbreviation%" == "HKCR" set "RegKey=HKEY_CLASSES_ROOT%RegKey:~4%" & goto GetRootName
if /I "%Abbreviation%" == "HKCU" set "RegKey=HKEY_CURRENT_USER%RegKey:~4%" & goto GetRootName
if /I "%Abbreviation%" == "HKLM" set "RegKey=HKEY_LOCAL_MACHINE%RegKey:~4%" & goto GetRootName
if /I "%RegKey:~0,3%" == "HKU" set "RegKey=HKEY_USERS%RegKey:~3%"
:GetRootName
rem Try to determine automatically name of registry root.
if not exist %SystemRoot%\Sysnative\reg.exe (set "RegEXE=%SystemRoot%\System32\reg.exe") else set "RegEXE=%SystemRoot%\Sysnative\reg.exe"
for /F "skip=2 tokens=1,2*" %%K in ('%RegEXE% QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey"') do if /I "%%K" == "LastKey" for /F "delims=\" %%N in ("%%M") do set "RootName=%%N"
rem Is Regedit already running?
%SystemRoot%\System32\tasklist.exe /NH /FI "IMAGENAME eq regedit.exe" | %SystemRoot%\System32\findstr.exe /B /I /L regedit.exe >nul || goto SetRegPath
echo/
echo Regedit is already running. Path can be set only when Regedit is not running.
echo/
set "UserChoice=N"
set /P "UserChoice=Terminate Regedit (y/N): "
if /I "%UserChoice:"=%" == "y" %SystemRoot%\System32\taskkill.exe /IM regedit.exe >nul 2>nul & goto SetRegPath
echo Switch to running instance of Regedit without setting entered path.
goto StartRegedit
:SetRegPath
rem Add this key as last key to registry for Regedit.
%RegEXE% ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /d "%RootName%\%RegKey%" /f >nul 2>nul
:StartRegedit
if not exist %SystemRoot%\Sysnative\cmd.exe (start %SystemRoot%\regedit.exe) else %SystemRoot%\Sysnative\cmd.exe /D /C start %SystemRoot%\regedit.exe
:EndBatch
endlocal
The enhancements are:
Registry path can be passed also as command line parameter to the batch script.
Registry path can be entered or pasted with or without surrounding double quotes.
Registry path can be entered or pasted or passed as parameter with or without surrounding square brackets.
Registry path can be entered or pasted or passed as parameter also with an abbreviated hive name (HKCC, HKCU, HKCR, HKLM, HKU).
Batch script checks for already running Regedit as registry key is not shown when starting Regedit while Regedit is already running. The batch user is asked if running instance should be terminated to restart it for showing entered registry path. If the batch user chooses not to terminate all instances of Regedit, Regedit is started without setting entered path resulting (usually) in just getting Regedit window to foreground.
The batch file tries to automatically get name of registry root which is on English Windows XP My Computer, on German Windows XP, Arbeitsplatz, and on Windows 7 and newer Windows just Computer. This could fail if the value LastKey of Regedit is missing or empty in registry. Please set the right root name in third line of the batch code for this case.
The batch file runs on 64-bit Windows always Regedit in 64-bit execution environment even on batch file being processed by 32-bit %SystemRoot%\SysWOW64\cmd.exe on 64-bit Windows which is important for registry keys affected by WOW64.
Copy the below text and save it as a batch file and run
#ECHO OFF
SET /P "showkey=Please enter the path of the registry key: "
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" /v "LastKey" /d "%showkey%" /f
start "" regedit
Input the path of the registry key you wish to open when the batch file prompts for it, and press Enter. Regedit opens to the key defined in that value.
I thought this C# solution might help:
By making use of an earlier suggestion, we can trick RegEdit into opening the key we want even though we can't pass the key as a parameter.
In this example, a menu option of "Registry Settings" opens RegEdit to the node for the program that called it.
Program's form:
private void registrySettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = string.Format(#"Computer\HKEY_CURRENT_USER\Software\{0}\{1}\",
Application.CompanyName, Application.ProductName);
MyCommonFunctions.Registry.OpenToKey(path);
}
MyCommonFunctions.Registry
/// <summary>Opens RegEdit to the provided key
/// <para><example>#"Computer\HKEY_CURRENT_USER\Software\MyCompanyName\MyProgramName\"</example></para>
/// </summary>
/// <param name="FullKeyPath"></param>
public static void OpenToKey(string FullKeyPath)
{
RegistryKey rKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(#"SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Regedit", true);
rKey.SetValue("LastKey",FullKeyPath);
Process.Start("regedit.exe");
}
Of course, you could put it all in one method of the form, but I like reusablity.
Here is a simple PowerShell function based off of this answer above https://stackoverflow.com/a/12516008/1179573
function jumpReg ($registryPath)
{
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" `
-Name "LastKey" `
-Value $registryPath `
-PropertyType String `
-Force
regedit
}
jumpReg ("Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run") | Out-Null
The answer above doesn't actually explain very well what it does. When you close RegEdit, it saves your last known position in HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit, so this merely replaces the last known position with where you want to jump, then opens it.
Create a BAT file using clipboard.exe and regjump.exe
to jump to the key in the clipboard:
clipboard.exe > "%~dp0clipdata.txt"
set /p clipdata=input < "%~dp0clipdata.txt"
regjump.exe %clipdata%
( %~dp0 means "the path to the BAT file" )
Building on lionkingrafiki's answer, here's a more robust solution that will accept a reg key path as an argument and will automatically translate HKLM to HKEY_LOCAL_MACHINE or similar as needed. If no argument, the script checks the clipboard using the htmlfile COM object invoked by a JScript hybrid chimera. The copied data will be split and tokenized, so it doesn't matter if it's not trimmed or even among an entire paragraph of copied dirt. And finally, the key's existence is verified before LastKey is modified. Key paths containing spaces must be within double quotes.
#if (#CodeSection == #Batch) #then
:: regjump.bat
#echo off & setlocal & goto main
:usage
echo Usage:
echo * %~nx0 regkey
echo * %~nx0 with no args will search the clipboard for a reg key
goto :EOF
:main
rem // ensure variables are unset
for %%I in (hive query regpath) do set "%%I="
rem // if argument, try navigating to argument. Else find key in clipboard.
if not "%~1"=="" (set "query=%~1") else (
for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0"') do (
set "query=%%~I"
)
)
if not defined query (
echo No registry key was found in the clipboard.
goto usage
)
rem // convert HKLM to HKEY_LOCAL_MACHINE, etc. while checking key exists
for /f "delims=\" %%I in ('reg query "%query%" 2^>NUL') do (
set "hive=%%~I" & goto next
)
:next
if not defined hive (
echo %query% not found in the registry
goto usage
)
rem // normalize query, expanding HKLM, HKCU, etc.
for /f "tokens=1* delims=\" %%I in ("%query%") do set "regpath=%hive%\%%~J"
if "%regpath:~-1%"=="\" set "regpath=%regpath:~0,-1%"
rem // https://stackoverflow.com/a/22697203/1683264
>NUL 2>NUL (
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit"^
/v "LastKey" /d "%regpath%" /f
)
echo %regpath%
start "" regedit
goto :EOF
#end // begin JScript hybrid chimera
// https://stackoverflow.com/a/15747067/1683264
var clip = WSH.CreateObject('htmlfile').parentWindow.clipboardData.getData('text');
clip.replace(/"[^"]+"|\S+/g, function($0) {
if (/^\"?(HK[CLU]|HKEY_)/i.test($0)) {
WSH.Echo($0);
WSH.Quit(0);
}
});
This seems horribly out of date, but Registration Info Editor (REGEDIT) Command-Line Switches claims that it doesn't support this.
You can make it appear like regedit does this behaviour by creating a batch file (from the submissions already given) but call it regedit.bat and put it in the C:\WINDOWS\system32 folder. (you may want it to skip editting the lastkey in the registry if no command line args are given, so "regedit" on its own works as regedit always did) Then "regedit HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0" will do what you want.
This uses the fact that the order in PATH is usually C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem; etc
If the main goal is just to avoid "the clicking", then in Windows 10 you can just type or paste the destination path into RegEdit's address bar and hit enter.
The Computer\ prefix here is added automatically. It will also work if you simply type or paste a path starting with e.g. HKEY_CURRENT_USER\....
PowerShell code:
# key you want to open
$regKey = "Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\IntuneManagementExtension\Policies\"
# set starting location for regedit
Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" "LastKey" $regKey
# open regedit (-m allows multiple regedit windows)
regedit.exe -m
This is the best answer overall, as it's quick, simple and there's no need to install any program.
By Byron Persino, improved by Matt Miller. (Many thanks to both of them!)
I'm rewording more correctly and clearly to help other readers like me, as I had a lot of trouble getting it clear and make it working.
Make a .bat file, eg. 'GoToRegEditPath.bat' , write the following code inside and save it:
CODE:
#echo off
set /p regPath="Open regedit at path: "
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_SZ /d "%regPath%" /f
START regedit
exit
:: source:
https://stackoverflow.com/questions/137182/how-to-launch-windows-regedit-with-certain-path?answertab=modifieddesc#tab-top
Maybe this .bat use must "Run as Administrator"
To use it, Just run it and paste (R-Click) in it the copied RegEdit Path.
Tip: if R-click does not work inside command prompt:
R-click on title bar > Properties > check both under "Edit Options"