Slightly updated the answer the /D Y part will recursively accept taking ownership when directory listing is denied in the permissions:
To fix really broken permissions, the best is to run these two commands one after the other:
takeown /F /D Y "C:\path\to\folder" /R
icacls "C:\path\to\folder" /reset /T
The first one will give you ownership of all the files, however that might not be enough, for example if all the files have the read/write/exec permissions set to “deny”. You own the files but still cannot do anything with them.
In that case, run the second command, which will fix the broken permissions.
I wrote two tiny batch files that would dump the environment variables from the registry.
Various reasons:
Environment variables can be stored in two contexts: System and User (SET will show them all at once and for instance combine PATH up to 1920 characters).
Environment variables can be set to auto-expand or not, which you cannot see from a SET command (REG_EXPAND_SZ versus REG_SZ).
setlocal
set gbakExe=C:\Program Files (x86)\Firebird\Firebird_2_5\bin\gbak.exe
set dbPart=MyDatabase
set dbSource=192.168.199.24:C:\Path with spaces\%dbPart%.fdb
set dbUser=sysdba
set dbPassword=masterkey
"%gbakExe%" -verify -transportable -user %dbUser% -password %dbPassword% "%dbSource%" %dbPart%.fbk
endlocal
You need the quotes around %gbakExe% and %dbSource% to ensure spaces in paths are preserved.
Sometimes you want to run a batch file from a Task Scheduler task. For that, the user under which the task runs needs to Logon as a batch job right. If it hasn’t, you get this nice error message:
As ntrights uses a hard to remember SeBatchLogonRight name for it and I tend to forget the ntrights syntax, I wrote two batch files to grant or revoke the Logon as Batch Job rights for the specified user:
Usually I use the old Borland grep.exe that still ships with Delphi. Too bad it is 16-bit app which does not recognise Unicode.
FindStr does. Though much slower and with limited regular expression capabilities, can do recursive searches too:
findstr /spin /c:"string to find" *.*
The /spin is a shortcut for these case insensitive command-line options (the full list of possible options is below):
/S Searches for matching files in the current directory and all
subdirectories.
/I Specifies that the search is not to be case-sensitive.
/N Prints the line number before each line that matches.
/P Skip files with non-printable characters.
Sometimes I leave out the /P to include binary files.
I know, old knowledge, but I only recently added the below batch files to file collection.
Why? Because since a few Windows versions, the System process uses port 80 because IIS is installed by default in many configurations. And recently I had to do quote a bit of http communication work against a local machine outside the IIS realm.
:: http://stackoverflow.com/questions/22084561/difference-between-iisreset-and-iis-stop-start-command
:checkPrivileges
net file 1>nul 2>nul
if '%errorlevel%' == '0' ( goto :gotPrivileges ) else ( goto :getPrivileges )
:isNotAdmin
:getPrivileges
echo You need to be admin running with an elevated security token to run %0
goto :exit
:isAdmin
:gotPrivileges
:: net stop w3svc
:: net stop iisadmin
iisreset /stop
:exit
::pause
exit /b
Start IIS:
:: http://stackoverflow.com/questions/22084561/difference-between-iisreset-and-iis-stop-start-command
:checkPrivileges
net file 1>nul 2>nul
if '%errorlevel%' == '0' ( goto :gotPrivileges ) else ( goto :getPrivileges )
:isNotAdmin
:getPrivileges
echo You need to be admin running with an elevated security token to run %0
goto :exit
:isAdmin
:gotPrivileges
:: net start w3svc
:: net start iisadmin
iisreset /start
:exit
::pause
exit /b
The interwebs is full of posts telling about how to create file and directory junctions**.
But there is little information about removing them and even less being correct: some suggest to del a directory junction (which just deletes everything in it but the junction).
Finally there is little information about listing all junctions, so lets start with that:
Deleting a link depends on the kind of link, not the kind of source.
Since symlink and hardlinks are for files, and directory symlink and junctions are for directories, this is how:
Delete a directory symlink or junction using RMDIR.
SysInternals – I wrote about them before – has a great junction tool. It can be used to create, delete and (optionally recursively) list reparse points. All usages allow for file and directory junctions.
More about reparse points
This is about the **: actually they are reparse points; for files they are symlinks, for directories mostly junctions, but sometimes symlinks.
And actually the reason I wrote this blog post. As you also have hardlinks. Some combinations of files and directories with these kinds of links fail.
Lets first go to see what kind of links there are on a fresh Windows system.
This is the only directory symlink: C:\Users\All Users and junction will show it like this:
.\\?\C:\\Users\All Users: SYMBOLIC LINK
Print Name : C:\ProgramData
Substitute Name: \??\C:\ProgramData
It is unlike this directory junction C:\Users\Default User which junction will show as this:
\\?\C:\\Users\Default User: JUNCTION
Print Name : C:\Users\Default
Substitute Name: C:\Users\Default
Together with C:\Users\Default and C:\Users\desktop.ini they are hidden, so you need the /AH flag to show them using DIR (as a gist, since WordPress still screws up less than and greater than):
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Since symlinks are client side created and not verified until use, you can actually use mklink to create both file and directory symbolic links for a file. DIR shows them as SYMLINK or SYMLINKD.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
When you try this for directories, you are in for a few small surprises.
A SYMLINK to a directory neither works as file nor as directory. A SYMLINKD or JUNCTION to a directory works. Hardlinks don’t work for directories with reason: limit the risk of cycles.
Example batch file:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Below are some more batch files related to this. In each batch file, you can replace tf with call "%~dp0tf.bat" so the above batch file is executed first.
Many sites giving your public IP address return a web page with a bloat of html. From the command-line, you are usually only interested in the IP-address itself. Few services return exactly that.
Below are command-line examples to provide the public IP address mostly from a *nix perspective. Usually you can get similar commands to work with Windows binaries for wget and Windows binaries for curl.
In the end, I’ve opted for commands in this format, as I think akamai will last longer than the other sites (but does not include an end-of-line in the http result hence the echo on Mac/*nix):
The last two are convenient when you have both IPv4 and IPv6 configured on “the outside”.
You can replace curl with wget -q -O – (which outputs to stdout) for each command. You can even ommit the http:// (as that is the default protocol for both curl and wget).