If condition in windows registry file - windows

I want to check if a key exists in the registry, and, if so, add a new entry. As an example:
IF [HKEY_LOCAL_MACHINE\SOFTWARE\MySoftware]
[HKEY_LOCAL_MACHINE\SOFTWARE\MySoftware\]
"name"="my name"
ENDIF
I don't want to use *.bat files or any other scripting. Is there a way to do this using only a *.reg file?

Sorry, but .REG files don't support conditional operations such as "IF".
All it supports is adding and deleting keys
Microsoft Documentation on the humble reg file
https://support.microsoft.com/en-us/kb/310516

Related

Easiest Way to Create SourceFile of Any Kind

I'm used to create source code via 'make new .txt' and modify its extension. And this is not great and kinda annoying for using both keyboard and mouse...
Q. so, Is there any way to create source file than that?
Yes, you can write a program that creates and opens an empty file, like this:
cd yourpath
type nul > new.c
Notepad "main.c"
Replace yourpath with the path where you intend to store your file to.
Save this file named to something like createfile.bat. Drag & Drop it to your favored place and then you can double-click it to create your file and open it. The problem you will face at the second use is that the file's name is unchanged. So, you will need to somehow make your filename unique, like adding a timestamp to its end or the like.
Extending the New Submenu.
Assuming you already have .c files associated with a text editor you can just import this .reg file into the registry:
REGEDIT4
[HKEY_CURRENT_USER\Software\Classes\.c\ShellNew]
"NullFile"=""
I found my way to make source code! by using shellscript..
open file manager
right click at dir to open terminal
use 'ni commands' of shell
It's a easy way to create and modify any file!

I want to know how to change "Folder Options" using a batch file

How to enable hiding and viewing system files "in general" using a batch file?
I have researched on the net and found these results such as: ATTRIB -S -H RECORD.TXT
But this is "specific" to a file... I want to know how to do this for the explorer. Basically how to manipulate these options in "Folder Options" using a batch file.
As described in this question Configure Windows Explorer Folder Options through Powershell
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
There are various values in this key that control the options. You can manipulate them through a batch file (rather than powershell) using reg.exe.
Easiest way would be to set the options you want in the GUI, export the key to a .reg file, then use reg.exe IMPORT settings.reg

How to suppress 'Open with' window

When running a file which has an unknown extension (lets say test.nope) from the command line or a batch file - using test.nope, call test.nope or start test.nope - you are presented with a window asking you to "Choose the program you want to use to open this file" (in Windows 7, presumably in most Windows OS's).
Is it possible to suppress this window?
My initial thought was to check if the extension exists in the %PATHEXT% variable before attempting to open the file. However, this does not contain all known file extensions. For example, though the .py extension is not in my %PATHEXT% variable, Python scripts are still opened correctly.
An alternative to a direct registry query (as suggested by #Mitch) is to use the command line utility assoc
assoc .nope
If there is no application registered for the file extension it produces
C:\>assoc .nope
File association not found for extension .nope
If an association is found (for instance, for the .docx extension), it produces
C:\>assoc .docx
.docx=Word.Document.12
You might also find ftype useful. It returns the command line for the file type returned by assoc (I have Office installed in a non-default location, as you can see):
C:\>ftype Word.Document.12
Word.Document.12="D:\Microsoft Office\Office12\WINWORD.EXE" /n /dde
File types are registered in HKCR\ (full documentation available from MSDN). You can find out if a type is registered by checking for the existence of the key. In a batch file, you could use the reg command to do so.
reg query HKCR\.txt || echo This will never print
reg query HKCR\.foobartxt || echo Could not find foobartxt
That being said, file types can be defined and named without having a default handler. Further, those which have default handlers may not have command lines - the file may be launched via DDE or COM.

Windows Shell Context Menu option

I need to create an option for all files that would run a batch file located in Windows directory or any other directory.
The batch file will basically delete the files and will also delete it from another server.
I have the batch file working just need the context menu option.
You have to create the following registry entries:
HKLM\Software\Classes\*\shell\yourappname
HKLM\Software\Classes\*\shell\yourappname\command
the first registry entry is a key, the second a string value. Set the value of the command entry to the path of your batch file, e.g. "c:\batch.bat %1"
The '%1' will get replaced by the path the context menu was shown for.
The '*' entry is for all files. If you want your menu to show up for folders/drives/whatever, you have to also add the same registry keys/values for those too, e.g.,
HKLM\Software\Classes\Folder\shell\yourappname
HKLM\Software\Classes\Folder\shell\yourappname\command
HKLM\Software\Classes\Directory\shell\yourappname
HKLM\Software\Classes\Directory\shell\yourappname\command
HKLM\Software\Classes\Drive\shell\yourappname
HKLM\Software\Classes\Drive\shell\yourappname\command

Only Name File with Extension in Windows

I am trying to create a file in Windows XP that is only the extension (".classpath" and ".project"). While my Linux box handles this appropriately, Windows gives me the error, "You must type a file name."
Any suggestions how to do this? I am attempting to setup an Eclipse project where I can bring in the classpath and project files from someone else's setup and I keep getting the above error.
Just name your file with additional dot at the end: ".ext."
explorer will remove additional dot and you'll get .ext file.
use the commandline to do this, windows explorer doesn’t allow renamed files to start with a period. first create the file/directory with a dummy name x.ext, then fire up cmd.exe and rename it:
ren x.ext .ext
this way you can also create directories which names start with a period (like .git or .meta)
From the command line:
echo some text > .classpath
Windows seems not to be in control of how Save dialogs handle forbidden characters
Quoting the filename should do the job.
I have no Windows machine to try it out but I was able to save a ".htaccess" file in Notepad this way.

Resources