Error with a custom folder - windows

I've been working on this for days but still cannot figure out how to do this: creating a custom folder.
Here's some information that I used:
Source 1
Source 2
Source 3
The major difference between the goal of these links and me is the fact that I am not trying to pin my folder to somewhere else. The only thing that I want to do is to create a redirect to a folder's subdirectory.
Here's my simple diagram:
So if I open Main Directory(the yellow part), desktop.ini and the system attribute of Main Directory will call up my custom CLSID (Explanation) and redirect my access to Redirect Folder automatically. My custom CLSID will also add an option in the context menu(the list that appears when right-clicked) to execute a .cmd file. The .cmd file will enable the user to access Hidden Folder when the correct password is typed.
So here're my registry keys:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}] #=""
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\DefaultIcon]
#=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,00,68,00,\
65,00,6c,00,6c,00,33,00,32,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,34,00,00,\
00
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\InProcServer32]
#="shell32.dll" "ThreadingModel"="ApartMent"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Instance]
"CLSID"="{0E5AAE11-A475-4c5b-AB00-C66DE400274E}"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Instance\InitPropertyBag]
"TargetFolderPath"="C:\Custom\Location\to\the\Main\Directory"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Shell]
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Shell\Open
Vault]
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Shell\Open
Vault\Command] #="cmd /c Open.cmd"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\ShellFolder]
"Attributes"=dword:00000000
It looked like this would work just as intended, but it had a flaw: my Main Directory did not actually redirect me to Redirect Folder. Here's my evidence:
When I right-clicked, every creating option was gone (Create new folder, text file, etc.)
When I create a file using a 3rd party software that was in the context menu, it did not create the file in Redirect folder but instead in Main Directory
Most importantly, when I Shift + right clicked and opened a command prompt, it showed my current directory as Main Directory instead of Redirect Folder
So what I'm trying to ask is this: how do I completely redirect my Main Directory access to Redirect Folder and keep my Hidden Folder opening option in the context menu?

I do not know how this works, but I found a way around.
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\shellex]
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\shellex{000214EE-0000-0000-C000-000000000046}]
#="{0AFACED1-E828-11D1-9187-B532F1E9575D}"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\shellex{000214F9-0000-0000-C000-000000000046}]
#="{0AFACED1-E828-11D1-9187-B532F1E9575D}"
The first step is to add above lines to the Registry.
After adding these, I created a shortcut file(.lnk) of a random folder(excluding self and some other special folders).
When I moved the .lnk file to the Main folder, I could access to create new option from my context menu.

Related

Why is the folder created on the command line not visible by other programs?

I created a folder on my Desktop within the command line on Windows, by using the command mkdir. I also added some files in there by using the command type nul >> fileName.
The folder is there, but two blue arrays appear on its top.
I want to open it on my IDE now.
I'm using PHP Storm, and I'm trying to open a file inside the folder, but when I do
file > open file or project > Desktop
the folder is not visible.
For it was on read-only mode, I have also tried to change such a setting, but nothing changed, I don't know whether or not this is relevant as regards to the issue explained above.
Why a folder created within the command line is not visible by some other program, and how can I solve and avoid the issue in the future?

0KB PowerPoint file on File Share Server: identify/delete

I'm using Windows 7 with a VPN (Cisco AnyConnect) connection to an academic file share server. I copied a PowerPoint file from a local path to the server, and tried to delete the file on the server after no longer needing it.
It now shows up as a 0KB file, and I can no longer perform any actions on it except opening it as read-only. When I do open it as read-only, I receive the prompt "Unknown is working on \server\share_pathtofile. Do you want to open a read-only copy in the meantime?", and the file is empty (no slides, settings, etc). Here 'server_pathtofile' is the entire path of the problem file. I am positive no other user is accessing the file from another machine.
I have tried to overwrite it by Save As, using the same file name. Once I click Save, the save window closes and reopens without performing any action. This happens indefinitely if I continue to click Save. I can save the file with a different name on the server, and delete the file with a different name without issue.
I tried removing problem file using python through the Anaconda Spyder distro i use on my laptop.
import os
path = r"\\server\share"
file = r"\file.pptx"
#file = r"\test2.txt"
f = path + file
os.remove(f)
When i run it for the trouble file, it produces the error:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '\\\\server\share_pathtofile'
I looked into the shutil function, but don't think that'll be any more useful. I suspect the process handle for the PowerPoint file has been corrupted in some way. I thought to try and use Windows to perform the action directly through Powershell:
Remove-Item 'file.pptx'
But received a similar error:
Remove-Item : Cannot remove item \\server\share_pathtofile: The process cannot access the file '\\server\share_pathtofile' because it is being used by another
process.
At line:1 char:12
+ Remove-Item <<<< 'file.pptx'
+ CategoryInfo : WriteError: (\\server...file.pptx:FileInfo) [Remove-Item], IOException
+ FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
UPDATE 1: I tired postanote's suggestion by deleting through cmd.exe
pushd \\server\share
del /f "file.pptx"
The process cannot access the file because it is being used by another process.
I would've thought my inclusion of the powershell attempt to remove the file would've made this approach an obvious dead end. Shoudln't i be trying to find the so-called process that is telling Windows the file is still open?
Also, I was able to reproduce the same issue with a second ppt file and an excel file. They are not 0KB, but upon opening i get the same sort of prompt: "someone else is working on them and you can read-only".
I was making copies of the file within the same folder directory of the file share. My connection to the server got interrupted somehow, as Windows Explorer prompted me saying the connection to server share was able to be found. Upon closing the prompt, Windows Explorer did an unexpected refresh, the mapped drive was fine (i could navigate it without having to remap it), then suddenly I had two more problem files.
It is certainly not having the Windows Explorer preview pane open, i have never used that Explorer feature. Any ideas? We shouldn't let this file win...
PE will only look at process where it was started. Just like Task Manager, and if you are not accessing the file via some process (PowerPoint.exe), or know that in a shared file scenario, no one else has it locked, then you can take action on it.
This is not a PS specific issue (so not really a PS question) or anything related to process explorer and nothing to do with admin right on a server/workstation. If you have read/write/modify/delete permissions on a system / file share, you can act on that file of course.
It's a Windows proper issue. I've seen (and had this happen) this zero length files (depending on how they were created / copied) more than once, and they appear as impossible to delete.
The deal here, often Windows Explorer for such files won't even let you shorten the name via a rename effort. So, name length, odd characters, etc., are often the culprit(s)
So, you need to use cmd.exe and delete the file using the short DOS name. Just do a dir on the location where file is to get the short name and delete it.
dir /X

Can a Windows batch file determine its "invoked" filename when invoked with shortcut?

Can a Windows batch file determine its invoked filename when invoked through a shortcut?
For example, I create real.bat, and create its shortcut named phony.bat (.lnk?)
And invoke phony by double-click on it.
Can this batch file detect the name phony.bat instead of real.bat?
Of course I can just copy it to another name, but when I edit one of them, I have to manually sync the content to all files.
The question is related to Can a Windows batch file determine its own file name?, but different.
As in your you mentioned that you've created the shortcut I assume you can create the with any properties you want.
So right click on your lnk file and change the the target line to:
C:\Windows\System32\cmd.exe /c "set "lnk_call=1"&"C:\PATH\TO\your.bat" "
This will change the icon of the link so to set back to batch file cog click on change icon and find the bat file icon in :
%SystemRoot%\System32\SHELL32.dll
Finally in your bat put this line:
if defined lnk_call echo triggered from lnk file
the lnk_call now can be used to determine if your file is called from double clicking on a .lnk file. I don't think it is possible to detect this from a shortcut that anyone else created.
Oh yeah, I found hardlink useful in this case:
mklink /h <link-name> <source-file>
I can create many hardlinks with different name, and they all points to the same file, so I can freely edit any one of them without manually sync their content.

"Register" an .exe so you can run it from any command line in Windows

How can you make a .exe file accessible from any location in the Windows command window? Is there some registry entry that has to be entered?
You need to make sure that the exe is in a folder that's on the PATH environment variable.
You can do this by either installing it into a folder that's already on the PATH or by adding your folder to the PATH.
You can have your installer do this - but you may need to restart the machine to make sure it gets picked up.
Windows 10, 8.1, 8
Open start menu,
Type Edit environment variables
Open the option Edit the system environment variables
Click Environment variables... button
There you see two boxes, in System Variables box find path variable
Click Edit
a window pops up, click New
Type the Directory path of your .exe or batch file ( Directory means exclude the file name from path)
Click Ok on all open windows and restart your system restart the command prompt.
You can add the following registry key:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\myexe.exe
In this key, add the default string value containing the path to the exe file.
You have to put your .exe file's path into enviroment variable path. Go to "My computer -> properties -> advanced -> environment variables -> Path" and edit path by adding .exe's directory into path.
Another solution I personally prefer is using RapidEE for a smoother variable editing.
Rather than putting the executable into a directory on the path, you should create a batch file in a directory on the path that launches the program. This way you don't separate the executable from its supporting files, and you don't add other stuff in the same directory to the path unintentionally.
Such batch file can look like this:
#echo off
start "" "C:\Program Files (x86)\Software\software.exe" %*
Let's say my exe is C:\Program Files\AzCopy\azcopy.exe
Command/CMD/Batch
SET "PATH=C:\Program Files\AzCopy;%PATH%"
PowerShell
$env:path = $env:path + ";C:\Program Files\AzCopy"
I can now simply type and use azcopy from any location from any shell inc command prompt, powershell, git bash etc
It is very simple and it won't take more than 30 seconds.
For example the software called abc located in D:/Softwares/vlc/abc.exe
Add the folder path of abc.exe to system environment variables.
My Computer -> Click Properties -> Click Advanced system settings -> Click Environment Variables
Click on Ok.
now you can just open cmd prompt and you can launch the software from anywhere.
to use abc.exe just type abc in the command line.
it's amazing there's no simple solution for such a simple task on windows,
I created this little cmd script that you can use to define aliases on windows (instructions are at the file header itself):
https://gist.github.com/benjamine/5992592
this is pretty much the same approach used by tools like NPM or ruby gems to register global commands.
Simple Bash-like aliases in Windows
To get global bash-like aliases in Windows for applications not added to the path automatically without manually adding each one to the path, here's the cleanest solution I've come up with that does the least amount of changes to the system and has the most flexibility for later customization:
"Install" Your Aliases Path
mkdir c:\aliases
setx PATH "c:\aliases;%PATH%"
Add Your Alias
Open in New Shell Window
To start C:\path to\my program.exe, passing in all arguments, opening it in a new window, create c:\aliases\my program.bat file with the following contents(see NT Start Command for details on the start commmand):
#echo off
start "myprogram" /D "C:\path to\" /W "myprogram.exe" %*
Execute in Current Shell Window
To start C:\path to\my program.exe, passing in all arguments, but running it in the same window (more like how bash operates) create c:\aliases\my program.bat file with the following contents:
#echo off
pushd "C:\path to\"
"my program.exe" %*
popd
Execute in Current Shell Window 2
If you don't need the application to change the current working directory at all in order to operate, you can just add a symlink to the executable inside your aliases folder:
cd c:\aliases\
mklink "my program.exe" "c:\path to\my program.exe"
Add to the PATH, steps below (Windows 10):
Type in search bar "environment..." and choose Edit the system environment variables which opens up the System Properties window
Click the Environment Variables... button
In the Environment Variables tab, double click the Path variable in the System variables section
Add the path to the folder containing the .exe to the Path by double clicking on the empty line and paste the path.
Click ok and exit. Open a new cmd prompt and hit the command from any folder and it should work.
If you want to be able to run it inside cmd.exe or batch files you need to add the directory the .exe is in to the %path% variable (System or User)
If you want to be able to run it in the Run dialog (Win+R) or any application that calls ShellExecute, adding your exe to the app paths key is enough (This is less error prone during install/uninstall and also does not clutter up the path variable)
You may also permanently (after reboots) add to the Path variable this way:
Right click My Computer -> Click Properties -> Click Advanced system settings -> Click Environment Variables
Reference: Change System/User Variables
Put it in the c:\windows directory or add your directory to the "path" in the environment-settings (windows-break - tab advanced)
regards,
//t
In order to make it work
You need to modify the value of the environment variable with the name key Path, you can add as many paths as you want separating them with ;. The paths you give to it can't include the name of the executable file.
If you add a path to the variable Path all the excecutable files inside it can be called from cmd or porweshell by writing their name without .exe and these names are not case sensitive.
Here is how to create a system environment variable from a python script:
It is important to run it with administrator privileges in order to make it work. To better understand the code, just read the comments on it.
Tested on Windows 10
import winreg
# Create environment variable for call the program from shell, only works with compiled version
def environment_var(AppPath):
# Point to the registry key of the system environment variables
key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, r'System\CurrentControlSet\Control\Session Manager\Environment')
def add_var(path):
# Add the variable
winreg.SetValueEx(key, 'Path', 0, winreg.REG_SZ, path)
winreg.CloseKey(key)
try:
# Try to get the value of the Path variable
allPaths = winreg.QueryValueEx(key, 'Path')[0]
except Exception:
# Create the Path variable if it doesn't exist
add_var(path=AppPath)
return
# Get all the values of the existing paths
Path=allPaths.split(';')
# If the Path is empty, add the application path
if Path == ['']:
add_var(path=AppPath)
return
# Check if the application path is in the Path variable
if AppPath not in Path:
# Add the application path to the Path environment variable and add keep the others existing paths
add_var(path=AppPath+';'+allPaths)
# Only run this if the module is not imported by another
if __name__ == "__main__":
# Run the function
environment_var(AppPath=".")
You can find more information in the winreg documentation
You can also move your files to C:\Windows, but you need to use Administrator privileges and pay attention.
What did I mean with pay attention?
You need pay attention because you can also do some messes with Windows system files (Windows may not even work anymore) if you modify, delete, and do some changes incorrectly and accidentally in this folder...
Example: Don't add a file that have the same name of a Windows file
This worked for me:
put a .bat file with the commands you need (I use to run .py script into this) into a FOLDER,
go in the variable environment setting (type var in the search bar and it will show up)
in the global settings
choose path,
then modify,
then add the path to your .bat file (without the .bat file)
close everything: done.
Open the cmd, write the name of the .bat file and it will work
Example
Want to open chrome on a specific link
create a .bat file with this (save it as blog.bat for example)
start "" "https://pythonprogramming.altervista.org/"
go in enviromental variable settings from the search bar in the bottom left of the window desktop
go in enviromental variables (bottom button) then in path (bottom)
add the path, for example G:\myapp_launcher
click apply or ok
Now open cmd and write blog: chrome will open on that page
Do the same to open a file... create a .bat in the folder G:\myapp_launcher (or whatever you called the folder where you put the batch file), call it run.bat or myapp.bat or whatever (write inside of it start filemane.pdf or whatever file you want to open) and after you saved it, you can run that file from cmd with run or myapp or whatever you called your batch file.
Use a 1 line batch file in your install:
SETX PATH "C:\Windows"
run the bat file
Now place your .exe in c:\windows, and you're done.
you may type the 'exename' in command-line and it'll run it.
Another way could be through adding .LNK to your $PATHEX.
Then just create a shortcut to your executable (ie: yourshortcut.lnk) and put it into any of the directories listed within $PATH.
WARNING NOTE:
Know that any .lnk files located in any directories listed in your $PATH are now "PATH'ed" as well. For this reason, I would favor the batch file method mentionned earlier to this method.
I'm not a programmer or anything of the sort, but here's my simple solution:
Create a folder in which you'll be putting SHORTCUTS for all the programs you want to register;
Add that folder to the PATH;
Put all the shortcuts you want in the folder you created in the first step (context menu, New, Shortcut...) The SHORTCUT NAME will have be the be summoned when calling the program or function... NOT THE TARGET FILE NAME.
This will keep you from unintentionally putting files you don't want in the PATH.
Feel free to drop a comment if you think this answer needs to be improved. Cheers 🍻.
P.S. No system or File Explorer restart needed. 😀
Best way is to add the folder path for the .EXE file to Path values in the environment variable.
I'm not sure what versions of Windows this works with, but I put some useful .bat and .exe files into:
%LOCALAPPDATA%\Microsoft\WindowsApps
(equivalent to %USERPROFILE%\AppData\Local\Microsoft\WindowsApps)
which seems to be on my default PATH. I'd be interested to see if this were the general case.
DOSKEY is a Microsoft version of 'alias'. That function is already built into all versions of Windows (and most versions of DOS)
doskey fred=c:\myApps\myprog.exe
You'll want to load that every time you open a command prompt. Which you can do by any number of different methods. One way is to
Make a file containing all the doskey macros you want:
doskey fred=c:\whatever.exe
doskey alan=c:\whateverelse.exe
Change the file type / file name / file extension to .CMD or .BAT
ren myfile.txt myfile.CMD
Add the CMD/BAT file to your command processor autoruns key:
reg ADD \\HKCU\Software\Microsoft\Command Processor /v autorun /t REG_SZ /d myfile.CMD
For more information see
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/doskey
and
https://serverfault.com/a/1049766/142882
(serverfault.com/questions/95404/is-there-a-global-persistent-cmd-history)
Should anyone be looking for this after me
here's a really easy way to add your Path.
Send the path to a file like the image shows,
copy and paste it from the file and add the
specific path on the end with a preceding semicolon
to the new path. It may be needed to be adapted prior
to windows 7, but at least it is an easy starting point.
Command Prompt Image to Export PATH to text file
The best way to do this is just install the .EXE file into the windows/system32 folder. that way you can run it from any location. This is the same place where .exe's like ping can be found

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

Resources