Block .EXE in Windows Firewall with context menu - regex

I got the following bit of code for a .REG file that adds "Add to Firewall" to the context menu on right clicking on a .EXE file. It simply creates an Outbound Rule in the windows firewall for that specific file you had selected instead of doing it manually.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\exefile\shell]
[HKEY_CLASSES_ROOT\exefile\shell\Add To Firewall]
[HKEY_CLASSES_ROOT\exefile\shell\Add To Firewall\command]
#="netsh advfirewall firewall add rule name=\"%1\" dir=out action=block program=\"%1\""
http://oi46.tinypic.com/2rgnxaf.jpg
My problem is that the following syntax name=\"%1\" gives the full directory (C:\New folder\test.exe) as name in the windows firewall instead of just a simple test.exe
Another feature i´m seeking is adding it all to a shift right mouse-click instead of a normal right click, cause i really don't use the feature that often so i wana see it everytime i right click on a .EXE
PS. Run the following to remove it from the context menu again.
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\exefile\shell\Add To Firewall]
Hope to hear from someone, and in advance a big thanks from here ;)

The following will do exactly what you're asking, but it requires that you have UAC disabled. Without creating a script file or using third party tools, or alternatively overwriting the runas key, I don't think you would be able to create a UAC prompt.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\exefile\shell\firewallblock]
#="Add to Firewall" ; String to be displayed in context menu
"HasLUAShield"="" ; Adds UAC shield icon to the left of the command
"Extended"="" ; Requires shift to be held when right-clicking
[HKEY_CLASSES_ROOT\exefile\shell\firewallblock\command]
#="cmd.exe /s /c for %%a in (\"%1\") do netsh advfirewall firewall add rule name=\"%%~na\" dir=out action=block program=\"%%~nxa\""
To elaborate, I use the FOR command not because of its looping functionality but because it gives me access to parameter extensions. I modify %%a (which we'll say has a value of x:\fully\qualified\path\filename.exe) with %%~nxa to use filename.exe and %%~na to use filename.
As for the UAC stuff, I'd just use one of those third party tools I mentioned above and change the command accordingly, e.g.:
#="elevate.exe -c for %%a in (\"%1\") do netsh advfirewall firewall add rule name=\"%%~na\" dir=out action=block program=\"%%~nxa\""
Hope it helps!

Related

Modifying the Windows Explorer Toolbar with WinApi / c++

My task is to program change sorting parameter of files and folders in my operating system.
In the article on the MSDN:
under
Modifying the Windows Explorer Toolbar
indicated
In addition to modifying the Windows Explorer menu bar, you can also add buttons to the toolbar. And an example code.
But example of this modifying the Windows Explorer menu bar is not there, the only thing is there it's button adding example.
An alternative article has an example of opening it, so my question is: is it even possible, and if it is, how to do it?
The folder sort settings are saved to:
HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\
HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU
The entries look like:
You would need to loop through all of these registry entries and change the 'Sort' key. This would only affect folders which have already been accessed.
If you want to see how these lists are parsed, run ShellBagsView while running ProcMon and log all the interactions with the registry.
To do it, not programatically you can follow these instructions:
https://superuser.com/a/1481763/1043059

How to prevent "How do you want to open this file" dialog?

In my app I open a report using HTML file as such:
//pStrPath is file:///C:/Users/appts/AppData/Local/Temp/Report_View.htm
ShellExecute(hParentWnd, L"", pStrPath, NULL, NULL, SW_SHOW);
On my development machine it opens up in a web browser, but when I just tested it on a new installation of Windows 10, it showed this dialog instead:
So how can I prevent it from being shown and go with "keep using this app" option from the get-go? Otherwise it may be very confusing for my users.
PS. Note that Edge is installed and can open .htm files if I double-click them.
Referring to Launching Applications (ShellExecute, ShellExecuteEx, SHELLEXECUTEINFO) we note the text
Object Verbs
The verbs available for an object are essentially the items that you find on an object's shortcut menu. To find which verbs are available, look in the registry under HKEY_CLASSES_ROOT\CLSID{object_clsid}\Shell\verb
Commonly available verbs include:
edit - Launches an editor and opens the document for editing.
find - Initiates a search starting from the specified directory.
open - Launches an application. If this file is not an executable
file, its associated application is launched.
print - Prints the document file.
properties - Displays the object's properties.
Given that a double-click is the generally equivalent to selecting "open" in the object's shortcut menu, if we supply the function with the open verb, we can expect the behaviour to mirror that of a user's double-click. - Please see Ken's comment below
As such, we can expect the following code to achieve the desired result.
//pStrPath is file:///C:/Users/appts/AppData/Local/Temp/Report_View.htm
ShellExecute(hParentWnd, L"open", pStrPath, NULL, NULL, SW_SHOW);
If you are trying to open the default program FROM a 32 bit program in 64 bit Windows the ShellExecute and ShellExecuteEX may display the "How do you want to open this file?" dialog box each time. This is due to the way that the default program registered itself in Windows I think.
I could reproduce this error on Windows 11 fresh install where the Photos is set to the Default Program for .jpg files.
In my case, I found that if I use the ShellExecuteExW function and pass the extension into the .lpClass of SHELLEXECUTEINFOW Type that it works.
It should also work with the ShellExecuteExA function
Make sure it's not an exe, reg, bat file, or a URL you are trying to open. It has to be a document type of file.
Use the .lpClass to pass the extension like ".jpg"
Add the SEE_MASK_CLASSNAME As Long = &H1 to the .fMask parameter you are passing in like .fMask = YourMaskValue Or SEE_MASK_CLASSNAME
The reason I think this works is it bypasses any redirection and reads directly from the HKEY_CLASSES_ROOT.jpg

Shortcut of watch window in VS2012

I'm C++ user, and I like to use watch window.
Everytime I want to investigate variables
I do it in watch window pannel..
Before vs2008 the shortcut was ALT+3.
really easy to press.
But with vs2012,
I must press CTRL+ALT+W, 1
I think this is really ugly.
hard to press, multiple step...
But I don't want to change default setting,
because I have many environment and
I don't want to configure the key setting
every time I move or change computer.
Is there any good way or
easy way to debug with out pressing that CTRL+ALT+W, 1 commend?
You could make the change to the shortcut key/keys, then you could export the settings.
Tools > Import and Export Settings Wizard. Exports into a file you can send to yourself etc.
Then you could import the settings you like into other visual studio environments you have ;).
To change it back to Alt+3
Select Tools/Options
Goto Environment/Keyboard
In the list of commands, scroll down to Debug.Watch1
It will tell you that the shortcut is Ctrl+Alt+W,1
In Press Shortcut keys box, press Alt+3

How to make SAS to open with maximized window?

How to make SAS to open with the main window and the editor window automatically maximized?
One way to do this is to push the command AWSMAXIMIZE at startup. You could place this statement in your autoexec.sas
dm "awsmaximize";
I was also able to do this by editing the start menu entry and adding to the end of the SAS command: -initstmt "dm 'awsmaximize';"
More here: http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#a000115355.htm#win-af-wincmds
Not sure if you can do this automatically at startup, but you can set a hotkey to do it.
Tools -> Options -> Keys
Choose a key and type this into the command:
AWSMAXIMIZE ON; WPGM; ZOOM
"AWSMAXIMIZE ON" is the SAS for Windows command to maximize itself.
"WPGM" is the command to bring focus to the Enhanced Program Manager
"ZOOM" is the command to maximize the in-focus window.

Is there a way to know if the user has enabled "single click to open an item" in the control panel?

My program needs to know when the user has enabled "Single-click to open an item (point to select)" in the folder options window in file explorer. I have a mouse aid program and I need to know what this setting is set to programmatically? Is this available in the registry or something?
I think it's SHGetSettings when fDoubleClickInWebView is false
I found this on Kelly's Korner
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"ShellState"=hex:24,00,00,00,13,a8,01,00,00,00,00,00,00,00,00,00,00,00,00,00,\
01,00,00,00,0d,00,00,00,00,00,00,00,02,00,00,00
I don't know which value sets the single click mode, so you'll have to disable it and compare the registry with this string to see which it is.
The same information is on a Microsoft support page, but as it's referring to IE 4 and IE 5 I was worried it was outdated.
There's a reg file you can download, but it appears to be missing the initial open double quote.