MSwindows

From wiki
Jump to navigation Jump to search

If you really have to use MSwindows sometimes this may help

Things I learned that may come in handy whenever I'm forced to go windows.

Scripting

%1, %2
Positional parameters (like $1,$2 in unix shells)
pause
Wait until the user presses the any key ;-)
set now=%date:~<start>,<len>%
Get a substring from date
set bstring=%astring:.txt=.csv%
Replace .txt with .csv in astring


for /F %%i in (<filename>) do set var1=<%%i
Read filename and set var1 to the content of the file
if %var1% == %var2% command
Execute command if var2 is equal to var1. if /I ignores case
if EXIST file1 ( commandblock )
Execute the commandblock if file1 exists
if ERRORLEVEL <num> ( command )
Commands return ERRORLEVEL as exist status. Execute command if the ERRORLEVEL matches <num>
set /p var1='Prompt '
Ask for user input
command > outfile 2>&1
Redirect all output to outfile, same as in unix

Arithmetics

SET /A <name>=<a><operator><b>
Assign the value of the arithmetic operation to <name>

Functions

call:do_it hi bye
goto:eof

:do_it
zip -r %bckdir%\logs.zip %a%\test
echo Passed parameters %~1% and %~2%
goto:eof

Timestamp

NOTE: The exact positions (what follows :~) depend on the date format set on your system. Check what echo %date% and echo %time% return.

To avoid the resulting string to have spaces (e.g. for hours) replace them with 0.

SET YYYY=%date:~-4,4%
SET DD=%date:~-7,2%
SET MM=%date:~-10,2%
SET HR=%time:~0,2%
SET MIN=%time:~3,2%
SET SEC=%time:~6,2%
SET timestamp=%YYYY%%MM%%DD%_%HR%%MIN%%SEC%
SET timestamp=%timstamp: =0%

Recursively find files

for /R  %%D in (*) DO ( 
	echo full path: "%%D"
	echo fil ename: "%%~nxD"
	)

Add program to startup

  • Select the Start(Windows) button, then select Settings - Apps - Startup. Make sure any app you want to run at startup is turned On.

If the application is not listed there:

  • Select the Start(Windows) button find the app you want to run at startup.
  • Open file location (from menu or right-click). This opens the location where app (or shortcut to it) is saved. If there isn't an option for Open file location, it means the app can't run at startup.
  • If there is no shortcut yet, create one (right-click - Create Shortcut)
  • With the file location open, press the Windows key + R, type: 'shell:startup', then select OK. This opens the Startup folder.
  • Copy and paste the shortcut to the app from the file location to the Startup folder.

Errors and solutions

CMD does not support UNC paths as current directories.

You get this when you try to cd to a UNC path (\\server\dir\dir\)

pushd <UNCpath>
This works.

Unable to delete files

takeown /f <file name> /d y
icacls <file name> /grant administrators:F

Remove ownership from files

Get cygwin or another way to access your files the unix-way

find . -type f -exec cp {} ./tmp.file \; -exec mv tmp.file {} \;

Found running a python program

Error
"System.Messaging.MessageQueueException: Insufficient resources to perform operation."
Reason
There are insufficient resources to perform the migration, and this is specific to the MSMQ. The size of the MSMQ itself is limited to 4MB, requests have to be within that limit.
Solution
  • Open 'Server Manager'
  • Go to the "Features" tab - under the Features tab, right-click 'Message Queueing'
  • Select "Properties"
  • On the "General" tab, un-tick 'Storage limits'

OR

  • Go to Tools - 'Computer Management'
  • Go to 'Services and Applications'
  • Open the 'Message Queuing' properties, un-tick 'Storage limits'

FTP in passive mode

When ftp complains like 425 Use PORT or PASV first, set the client to passive mode (use port 21 only)

ftp> quote pasv

Windows 11 Taskbar

Windows 11 fucks up the task bar. To restore the windows 10 behaviour (e.g. having an icon for all windows) I installed the ExplorerPatcher as advised by microsoft [1]. That point you to this site . From github i installed 22000.556.42.37. That puts dxgi.dll in C;\Windows and fixed my issue after a restart.

Screenshot

This works most times:

WindowsKey + shift + S

Select the area you want, then it is on the clipboard (crtl-V)