Windows Command Line Hacks
Windows command line hacks are a set of commands or tools that can be used to perform certain tasks on a Windows system. These hacks can be used to perform various tasks such as managing files and folders, changing system settings, and troubleshooting problems.
There are a number of different ways to access the command line in Windows, but the most common method is to use the Command Prompt tool. This tool can be found in the Accessories folder of the Start menu. To open the Command Prompt, simply type „cmd“ into the search bar and press Enter.
Once you have the Command Prompt open, you can begin typing in commands. Some of the most common commands include „dir“ to list the contents of a directory, „cd“ to change the current working directory, and „copy“ to copy files. There are many other commands that can be used as well, but these are some of the most basic and commonly used.
Here are some useful commandline scripts for the advanced Microsoft Windows user.
Password Function
Here is a little password function if you need it. Be aware that it is very slow, don’t type too fast. 😉 It’s more a concept than a tool you can work with. Just Enter your password and hit ALT+222 (on your numblock) to terminate.
@echo off
setLocal EnableDelayedExpansion
set allchar=Þ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
set pw=
echo Please enter password SLOWLY and terminate with ALT+222
:pwloop
choice /C %allchar% /CS >nul
set cint=%errorlevel%
set /a cint-=1
set pw=%pw%!allchar:~%cint%,1!
if %cint% neq 0 goto pwloop
set pw=%pw:~0,-1%
echo %pw%
set pw=
pause>nul
Can’t Print FAX files – Workaround
If you have FAX files and open them in Windows with the Windows Photo Viewer or Windows Picture and Fax Viewer you may experience the problem that you can’t print the FAX file. Microsoft has not released any patch for this for now.
There is a little workaround to rename the files to .TIFF. But if you have a lot of FAX files it is too much trouble for such a little problem.
- Rightclick a FAX file
- Select open with
- Select the FAX.exe
- Be sure to check the box: always open with this program
Here is the original FAX.cmd file
cls
@echo off
set tmpf=%temp%\myFAX
set file=%~nx1
if not exist %tmpf% mkdir %tmpf%
if exist %tmpf%\%file% erase %tmpf%\%file%
if exist %tmpf%\%file%.tiff erase %tmpf%\%file%.tiff
copy %1 %tmpf%
cd %tmpf%
ren "%file%" "%file%.tiff"
start "" "%tmpf%\%file%.tiff"
exit
This file can be converted with the Bat2Exe Converter and made an executable.
Quick Admin Check with Version info for Windows in Batch
A little script which checks for your Version and also tells you if you have Admin rights or not.
@echo off
rem ***************************************
rem Info: http://en.wikipedia.org/wiki/Ver_(command)
rem ***************************************
ver | findstr "DOSBox\ version\ 0.72.\ Reported\ DOS\ version\ 5.0.">nul && echo DOSBox
ver | findstr "Windows\ NT.\ Version\ 4.0">nul && echo Windows NT
ver | findstr "Microsoft\ Windows\ 2000\ [Version\ 5.00.2195]">nul && echo Windows 2000
ver | findstr "Microsoft\ Windows\ XP\ [Version\ 5.1.2600]">nul && echo Windows XP
ver | findstr "Microsoft\ Windows\ [Version\ 5.2.3790]">nul && echo Windows Server 2003 or XP 64bit
ver | findstr "Microsoft\ Windows\ [Version\ 6.0.6001]">nul && echo Windows Vista
ver | findstr "Microsoft\ Windows\ [Version\ 6.0.6002]">nul && echo Windows Server 2008
ver | findstr "Microsoft\ Windows\ [Version\ 6.1.7600]">nul && echo Windows Server 2008 R2 or Windows 7 SP0
ver | findstr "Microsoft\ Windows\ [Version\ 6.1.7601]">nul && echo Windows 7 SP1
ver | findstr "Microsoft\ Windows\ [Version\ 6.2.9200]">nul && echo Windows 8
(mkdir %windir%\system32\test 2>nul && rmdir %windir%\system32\test) || goto error
echo User has admin rights
goto End
:Error
echo User has *NO* admin rights
goto End
:End
pause>nul
Delete protected partitions with windows
Sometimes it comes to a time where you need to delete partitions with windows and the diskmanager is not able to. I got a harddrive with 6 windows partitions here. To delete them all you can use a commandlinetool called diskpart.
Start a console with administrative rights and type-in
diskpart
After this you can list all your disks with
list disk
select your preferred disk. Best thing is to choose them by the size. If you have two equal sized disks just disconnect the one, list the disks and then connect it again, list the disks and you see which one is new.
DISKPART> list disk
Datenträger ### Status Größe Frei Dyn GPT
--------------- ------------- ------- ------- --- ---
Datenträger 0 Online 149 GB 0 B
Datenträger 1 Online 119 GB 0 B
DISKPART>
Now select the disk with
select disk 0
now you can list the partition
list partition
result:
Partition ### Typ Größe Offset
------------- ---------------- ------- -------
Partition 1 Primär 149 GB 1024 KB
DISKPART>
now you can select the partition
select partition 0
and delete the partition with
delete partition override
the parameter override is needed for protected partitions. For more partitions and harddrives you can prepare something like this:
select partition 0
delete partition override
select partition 1
delete partition override
select partition 2
delete partition override
select partition 3
delete partition override
select partition 4
delete partition override
select partition 5
delete partition override
select partition 6
delete partition override
Batch – Choose a directory by number
If you like your users to manually choose a directory in you filesystem but do not want them to type in the complete name of it, just use following script.
@echo off
setLocal EnableDelayedExpansion
set i=0
set c=0
for /f "tokens=*" %%a in ('dir C:\temp /AD /b') do (
set /a i+=1
set dir!i!=%%a
if !i! leq 9 (echo [ !i!] %%a)
if !i! gtr 9 (echo [!i!] %%a)
)
:choose
set /p choice="Please choose: "
if !dir%choice%! equ ^!dir^%choice^%^! echo Your choice !dir%choice%! was not found. &goto choose
echo Your choice was !dir%choice%!
pause>nul