Windows Command Line – 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

Here a picture for proof of concept

Commandline-password

Windows Command Line – Service Menu

If you have a collection of CMD Tools you fast loose the overview of what you have. For this I have developed a little menu where you can choose from your programs by name.

Here is the Main Menu

menu-and-logo-ready-to-use

 

You can create your own logo with the following steps.

copy-ascii-logo

 

  • Search and replace all occurences of | with ^| (Mostly found with CTRL+H)

replace-special-characters

 

  • Add echos and some extras

main-menu-with-extras

  •  Copy it into your menu

The good thing about this menu is, that you don’t have to search in a big script for stuff. You just alter this file here

rem Variables
@echo off

call :Var "%source%Add printer.vbs"				"Add a Printer"
call :Var "%source%all-printers-settings.cmd"	"Apply BW Print to all Printers"
call :Var "%source%printercolor.cmd"	"Apply Color Print to one Printer"
call :Var "%source%AddWSUSURLs.cmd"				"Add WSUS to Registry"
call :Var "%source%Softphone.cmd"				"Set Softphone DW"
call :Var "%source%userinfo.cmd"				"User Information + Services"
call :Var "%source%connectionstab.cmd"			"IE Connections Tab - Internet Explorer Verbindungen Reiter"
call :Var "%source%dfue.cmd"						"Create DFUE"
call :Var "%source%austria.hol"					"Outlook Holidays 2013-2015"
call :Var "%source%office-languagepacks.cmd"		"Office Language Packs"
call :var "%source%Abfragegenerator2007.cmd"			"Query Builder - Abfragegenerator Office 2007"
call :var "%source%Terminal-Autologin.cmd"			"Terminal Autologin"
call :Var "%source%VM2-ODBC.cmd"			"Versandmodule 2 - ODBC Settings"
call :var "%source%Lawi-setup.cmd"			"Lawi Setup"
call :Var "%source%lawi-etikett.cmd"			"Lawi Etikett"
call :var "%source%emppack.cmd"			"Install Empirum Package"
call :var "%source%EmpirumAgent.cmd"			"Install Empirum Agent"

goto :end

rem Variables
:Var
set /a id+=1
set /a nextpage=%id%%9
if [%nextpage%] EQU [0] set /a menumaxsiteindex+=1
rem set %id%.name=%1&& shift
set %id%.path=%1&& shift
set %id%.description=%1
goto:EOF

:end

And here is the menu where you put your logo

@echo off
cls
setLocal EnableDelayedExpansion

set version=0.6
set menusiteindex=0
set menumaxsiteindex=0
set id=0
set uid=0

rem Choose Source
call :ChooseSource
rem User Variables
if exist "%source%uservar.cmd" (call "%source%uservar.cmd") else (call "%source%..uservar.cmd")
rem Program Variables
if exist "%source%progvar.cmd" (call "%source%progvar.cmd") else (call "%source%..progvar.cmd")

set /a menumaxsiteindex=%id%/9+1
rem Variables

:ServiceLoop
call :MenuMapping
call :WriteScreen !%menu_1%.description! !%menu_2%.description! !%menu_3%.description! !%menu_4%.description! !%menu_5%.description! !%menu_6%.description! !%menu_7%.description! !%menu_8%.description! !%menu_9%.description!
goto:ServiceLoop

rem ***************************************************************************
rem * Functions
rem ***************************************************************************

:WriteScreen
cls
call :Logo
call :Menu %*
call :MenuChoice
goto:EOF

:MenuMapping
set prefix=%1
for /L %%a in (1,1,9) do (
	set menuindex=%%a
	set /a menu_%prefix%!menuindex!=!menuindex!+!menusiteindex!*9"
)
goto:EOF

:Logo
rem http://patorjk.com/software/taag/#p=display&f=Doom&t=www.sysstem.at
echo *******************************************************************************
echo *******************************************************************************
echo                                                 _                        _   
echo                                                ^| ^|                      ^| ^|  
echo __      ____      ____      _____ _   _ ___ ___^| ^|_ ___ _ __ ___    __ _^| ^|_ 
echo   / / /  / / /  / / / __^| ^| ^| / __/ __^| __/ _  '_ ` _   / _` ^| __^|
echo   V  V /   V  V /   V  V /__  ^|_^| __ __  ^|^|  __/ ^| ^| ^| ^| ^|^| (_^| ^| ^|_ 
echo   _/_/    _/_/    _/_(_)___/__, ^|___/___/_____^|_^| ^|_^| ^|_(_)__,_^|__^|
echo                                    __/ ^|                                     
echo                                  ^|___/                                    
echo ***************************************************Phone: 0043123456       ****
echo ***************************************************Email: admin@sysstem.at ****
echo.
goto:EOF

:Menu
set menucount=0
set choicestr=

rem http://www.robvanderwoude.com/parameters.php
:Loop
if [%1]==[] GOTO MenuFooter
	rem counter
	set /a menucount+=1
	rem save parameters in variables
	set _%menucount%=%1
	rem dequote variables
	call :DeQuote _%menucount%
	rem [Number] variable value
	echo [%menucount%] !_%menucount%!
	rem add Menunumber to string
	set choicestr=%choicestr%%menucount%
	rem get next parameter
	shift
goto Loop
:MenuFooter
echo.
echo [N]ext [P]revious [F]irst [L]ast [G]oto Page [A]dmin [E]xit
set choicestr=%choicestr%NPFLGAE
goto:EOF

:MenuChoice

choice /c %choicestr%
set /a menuchoice=%errorlevel%
set /a length=%menuchoice%-1
set programid=!menu_%menuchoice%!

if !menuchoice! LEQ !menucount! (
	start !%programid%.description! !%programid%.path!
) else (
	call :MenuSelection !choicestr:~%length%,1!
)
goto:EOF

:MenuSelection
set selection=%1
if /I [%selection%] equ [N] call :NextPage
if /I [%selection%] equ [P] call :PreviousPage
if /I [%selection%] equ [F] call :FirstPage
if /I [%selection%] equ [L] call :LastPage
if /I [%selection%] equ [G] call :GotoPage
if /I [%selection%] equ [A] call :Admin
if /I [%selection%] equ [E] call :Exit
goto:EOF

:NextPage
set /a maxpage=%menumaxsiteindex%-1
if [%menusiteindex%] LSS [%maxpage%] (
	set /a menusiteindex+=1
) else echo This is already the last page &pause>nul
goto:EOF

:PreviousPage
if [%menusiteindex%] GTR [0] (
	set /a menusiteindex-=1
) else echo This is already the first page &pause>nul
goto:EOF

:FirstPage
set /a menusiteindex=0
goto:EOF

:LastPage
set /a menusiteindex=%menumaxsiteindex%-1
goto:EOF

:GotoPage
set /p gotopage="Please enter pagenumber: "
set /a gotopage-=1
if %gotopage% GEQ 0 (
	if %gotopage% LSS %menumaxsiteindex% (
		set /a menusiteindex=%gotopage%
	) else echo No valid page number&pause>nul
) else echo No valid page number&pause>nul
goto:EOF

:Admin
2>nul 1>nul start "%source%runasadmin.exe" "%~dpf0"&&exit||(echo.&echo Could not get Admin rights.&pause>nul)
goto:EOF

:Exit
exit
goto:EOF

rem ******************************************
rem * Removes Quotes
rem * http://ss64.com/nt/syntax-dequote.html
rem ******************************************

:DeQuote
SET _DeQuoteVar=%1
CALL SET _DeQuoteString=%%!_DeQuoteVar!%%
IF [!_DeQuoteString:~0^,1!]==[^"] (
IF [!_DeQuoteString:~-1!]==[^"] (SET _DeQuoteString=!_DeQuoteString:~1,-1!
) ELSE (GOTO :EOF)
) ELSE (GOTO :EOF)
SET !_DeQuoteVar!=!_DeQuoteString!
SET _DeQuoteVar=
SET _DeQuoteString=
GOTO :EOF

:ChooseSource
set workingdir=%~dp0
set workingdir=%workingdir:~0,-1%
if exist "%workingdir%CMDTools" (set source=%workingdir%CMDTools
) else (
	set source=\backupserverCMDTools
)
GOTO:EOF

 

This currently only runs on Windows 7 (have not tested Windows 8, but should work too) because Windows XP does not bring choice.exe

And before I forget: you have to provide all the tools for yourselfs. But let me know if you are interessted in one of these mentioned here.

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.

Just download this program and move it to a save folder (e.g. C:Windows)

  • 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 I converted with the Bat2Exe Converter from this site and added a nice icon.