Adding a custom "new folder" to windows explorer context menu - windows

I often use the current date and time to name new folders, and I have made a program that does this (i.e. it takes one argument and then creates a new folder based on the current date and time and the argument).
I was wondering how I can make it so that I get a "New DateTime Folder" displayed in my context menu in windows explorer (just below "New Folder") and that it automatically adds the date and time in-front and allows the user to enter the name. It's actually a lot like the standard "New Folder" except instead of the default name being "New Folder" it should be "DateTime" and the text shouldn't by default be marked.
Any ideas? Thanks.

After playing around a bit I figured out a way to add a basic version of this just by editing the registry. It does not prompt for a name (It just uses a basic DD.MM.YYYY HH;MM;SS format) and does not enter explorer rename mode:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\.NewDirectoryBasedOnDate]
#="NewDirectoryBasedOnDate"
[HKEY_CURRENT_USER\Software\Classes\.NewDirectoryBasedOnDate\ShellNew]
"Command"="\"CMD\" /D /E:ON /c for /F \"tokens=1-9 delims=.,\\:/\" %%A IN (\"%%date%%.%%time%%\") DO for /F \"tokens=*\" %%a IN (\"%1\") do md \"%%~dpa\\%%A.%%B.%%C %%D;%%E;%%F\""
"nullfile"=hex:
[HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate]
"FriendlyTypeName"="Directory Based On Date"
[HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate\DefaultIcon]
#="shell32.dll,3"
[HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate\Shell\open]
"LegacyDisable"=hex:
[HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate\Shell\open\command]
#="."
I only tested this on WinXP and it is a bit of a hack (I had to add the fake Shell\open\command key for the new menu entry to show up)
By changing the command to wscript.exe //nologo "C:\path\to\NewDateDir.wsf" "%1" and saving the following code in NewDateDir.wsf you end up with this:
<?xml version="1.0" ?><job><script language="VBScript"><![CDATA[
if WScript.Arguments.Count < 1 then
MsgBox("Bad parameter!")
WScript.Quit(1)
end if
Set FSO=CreateObject("Scripting.FileSystemObject")
Function StrFilter(s,ch,rep)
StrFilter=Join(Split(s,ch,-1),rep)
End Function
basedir=FSO.GetParentFolderName(WScript.Arguments(0))
defname=Date&" "&Time
defname=StrFilter(defname,"/",".")
defname=StrFilter(defname,":",";")
name=InputBox("New folder in "&basedir,"New folder",defname)
if not IsEmpty(name) and Len(name) > 0 then
FSO.CreateFolder(FSO.BuildPath(basedir,name))
end if
]]></script></job>
Even if you decide to write a shell extension I think activating explorers rename mode is going to be hard, especially if you want partial selection. You also have to remember that other programs might implement shell context menus so you can't use all kinds of undocumented explorer stuff.

You have to implement a shell extension, in particular a context menu. Here is a pretty good walk-through on how to do it. There is also some lower-level documentation on MSDN here (for context menus in particular) and here (for shell extensions in general). For your particular case I think you would register you shell extension under the "Directory\Background" key.

Related

Windows 10 keyboard shortcut for inserting current UNIX timestamp at cursor

I would love to be able to use a custom keyboard shortcut for inserting current unix timestamp (in seconds) at cursor. While it's quite easy to accomplish for browsers using custom JS plugins, it's still not the clean solution I'm looking for and obviously wouldn't work outside of the browser.
I imagine it would basically require me to create a shortcut that runs a custom script (returning the current unix timestamp value) and inserts this scripts' output at the cursor. But while writing the script seems trival, I don't even know where to start with all the remaining of this task.
This approach requires you to execute a shortcut key combination and then Ctrl + V. It isn't exactly what you're looking for, but should be pretty close. It uses Set-Clipboard to place the Unix timestamp on the clipboard so it can be pasted to a desired location.
Open File Explorer and navigate to a location where you'll create
the shortcut
Right-click > New > Shortcut
In the Type the location of the item field, input (all on one line):
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "&{Set-Clipboard -Value ([string](Get-Date -UFormat %s -Millisecond 0))}" -WindowStyle Hidden -NonInteractive -NoLogo -NoProfile -ExecutionPolicy Bypass
Input a Name for the shortcut and click Finish
Right-click the newly created shortcut and select Properties
Change Run to Minimized
Click inside the Shortcut key field and execute your desired shortcut key combination to capture it; e.g., Ctrl + Alt + [
Click OK
To run the shortcut, execute the earlier-captured shortcut key combination (which places the Unix timestamp on the clipboard), and then Ctrl + V.
PowerShell 5.1+ has the native module called PSReadline. This module has the Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler and Remove-PSReadlineKeyHandler.
Using these cmdlets you could create your own KeyHandler for this custom unixdate output. Below I bound the key combination Ctrl+Alt+u to this, but it could be any key combination.
note: the ` below are in case you want to paste the example directly into PowerShell
Set-PSReadLineKeyHandler -Chord Ctrl+Alt+u `
-ScriptBlock {
$unixDate = $([uint64](New-TimeSpan -Start "01/01/1970" -End (Get-Date)).TotalSeconds)
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("$unixDate")
} -BriefDescription "Unix TimeStamp" `
-Description "Returns the current Unix TimeStamp"
If you also want it to copy to your clipboard for pasting in another program then you may add [Microsoft.PowerShell.PSConsoleReadLine]::Copy() after the insert.
The KeyHandler is only active during your current session, so If you want to make this a semi permanent key combo for every new PowerShell Session you should add this to your PowerShell profile. Your profile can be edited by running notepad $PROFILE and just dropping the snippet above into that file. If the file doesn't exist it will be created.
You can read more about the PSReadLine cmdlets on the [learn.microsoft.com] page, and more about the [Microsoft.PowerShell.PSConsoleReadLine] class here
Go here, click download (please do not use wget.exe if you have it), then follow these steps: Right click on downloaded file > Properties > Shortcut then you will find something that says None (exact), click that, then press Ctrl + Alt + [whatever key] or just press [whatever key] (you are required to use Ctrl + Alt and change [whatever key] to any character and remove the brackets). Restart the computer, it should open this link in your default browser that was set in settings (to open settings app press Win key + I). Sorry, I do not know or can research about putting it in the cursor so here is what I know...

Type a pre defined text when a shortcut key is pressed in Windows 7

I work on mainframes and don't have much knowledge about windows other than playing warcraft :-) hence pardon me if I ask something nooby/silly.
I have a requirement to enter a particular long-text in the current position of a cursor whenever a shortcut key is pressed.
I am thinking of creating a bat file and assigning a windows keyboard shortcut to the bat file and whenever I have requirement to enter the long text, I press the windows shortcut key
and the long text gets typed in the current position of the cursor.
The current position of the cursor can be in any application, like Excel, Word or notepad or Windows dialog prompts.
Could you please let me know if this is possible and point me where I could get some information about this "technique".
Thanks & Regards,
Vasanth.S
To make a single key combo do what you are asking, you may need another program. You can make a link to a batch file, hook up a shortcut and then use the clip command to copy text from a file onto the clipboard. That would require the shortcut and then a Ctrl+V to paste. The batch file would look like this:
clip < c:\SomeDir\sometext.txt
You might like to look at using a clipboard manager - which saves a history of clipboard entries, can search for an entry, and paste it at the cursor.
Ditto and CLCL are both useful and free - which one you use depends on your windows version.
They are hotkey driven for ease of use, but mouse can be used.

DOS batch file - Display popup message with two choices

Using a DOS batch file I'd like to display a popup window in XP and Windows 7 where I display a message and give the user the choice to press one of two buttons - one would stop the DOS batch file, while the other button would allow it to continue.
Any hint on what dos batch command/pgm I may use?
The following WSH/VBscript snippet prompts the user to click yes/no, after which you can base logic on the response:
'enter this text into ask.vbs
dim input
input = MsgBox ("Do you want to continue?", 4)
'wscript.echo input
If input = 7 Then
'answer was no
End If
If input = 6 Then
'answer was yes
End If
Then in your batch file, call wscript ask.vbs.
However, I recommend staying in pure console for this task if you can, as choice and set can handle this nicely as Anders suggests. pause works very well too, and that's usually what I use for a binary choice like yours because it's the simplest approach.
To display an actual window you would have to call something external, a .exe or a Windows Scripting Host script.
If you want to stay in pure batch, echo the choices and use SET /P to wait for input from the user. (To support DOS and Win9x you would have to use choice and not set on those systems)

Adding new filetypes to Windows 7's New context menu

I'm trying to add CSS, PHP, JS and HTML file types to the "New" right click menu in Windows 7. I know how to add the file types to the menu with ShellNew entries in the registry. But Windows doesn't give you any control over the display names of the new items - according to this the name's always taken from whatever application you've assigned to open the doc. I've set Notepad++ to open all of these file types, so I'm going to end up with several identical "Notepad++ document" entries in the menu, like this:
Does anybody know if there's a way out of this stupid situation without installing any tweak utilities?
Thanks all!
Fred
To rename a context menu > new's item (in Windows 7, at least):
Open regedit.
Go to HKEY_CLASSES_ROOT\.%ext% and note the (Default) value. This is the file extension's ProdID.
Go to HKEY_CLASSES_ROOT\%ProdID% (usually %ext%file) using the value obtained from step two. Set the (Default) value to whatever you would like the context menu new item to display as.
Under HKEY_CLASSES_ROOT\%ProdID%, if there is a FriendlyTypeName value, rename it to FriendlyTypeName.old, as the (Default) value "is deprecated by the FriendlyTypeName entry"
I don't believe there is even a need to log out / restart, but if the changes don't take effect, log out and/or restart.
You could change the file type description for each file class manually.
Look up the prog id under HKEY_CLASSES_ROOT\.%ext% (The default value)
Under HKEY_CLASSES_ROOT\%progid%, set the default value and/or the "FriendlyTypeName" string to the string you want.
You might have to log off for it to take effect.
You should probably stay away from the Chrome and Notepad++ file type/association dialogs so they don't overwrite your strings.
Both Chrome and Notepad++ are open source, you can create a patch for them that use better names for the file types. (What is a "Chrome HTML Document" anyway, HTML5 + extra chrome juice? =) )
I was able to derive a solution from the answers above.
I replicated the particular application (JetBrains PHPStorm in my case) registry entry.
PHPStorm2019.1 -> PHPStorm2019.1.scss, PHPStorm2019.1.js.
Now I changed the Default REG_SZ of PHPStorm2019.1.scss to SCSS File and PHPStorm2019.1.js to JavaScript file.
Mapped .scss and .js to PHPStorm2019.1.scss and PHPStorm2019.1.js respectively.

Changing CMD window properties programmatically

How can I change the appearance of my current CMD window?
I know there is a 'mode' and 'color' commands that give you some control, but it's not enough...
Is it possible to change Screen Buffer Size separately? To turn QuickEdit mode on/off?
Is there an API for this?
Search engines are amazing things :).
Search for Windows Console API and the 2nd link is: this. Digging in a tiny bit more and you find the interestingly named "SetConsoleMode" and "SetConsoleScreenBufferSize" APIs which appear to set the console mode (which includes quick edit mode) and screen buffer size.
I've not used the APIs so I don't know if there are any caveats, but from the documentation, these seem to be what you're looking for.
another way: use reg /? to query your registry for reg query HKEY_CURRENT_USER\Console. There you can see keys like ScreenBufferSize etc. Use reg to delete the key and add it back with new values. Type reg /? on the command line to see its help usage. make sure you backup registry before trying.

Resources