Friday, March 17, 2017

Ten Years On

Just realized I've had this blog up on Blogger since February 2007.

My site is now no longer hosted on GitHub pages at https://psteiner.com/

See you there here!

[Edit - 11 Sept 2018: decided to move back, GitHub pages is too much work!]

Sunday, March 5, 2017

Control+Shift+Enter to launch a Windows program as admin!

To launch any Windows program with elevated (admin) privileges, hold Control+Shift keys, then double-click the program's icon, even on the taskbar.

Alternatively, hit the Windows key, type the program name, e.g. cmd then type Control+Shift+Enter to launch the program with elevated (admin) privileges. You might have to enter admin credentials in the UAC popup.

See this LifeHacker article for more details.

Wednesday, April 13, 2016

How to check for admin rights from a Windows batch file

Simple check for administrative permissions in a batch file:

REM Check for admin rights - net session must run as admin
net session >nul 2>&1
if %ErrorLevel% NEQ 0 (
    echo You must right-click and select "RUN AS ADMINISTRATOR" to run this script.
    echo.
    pause
    exit /B
)

Wednesday, February 17, 2016

Another HEREDOC style for Windows Batch Files

I wanted to pipe a SQL query to sqlplus in a batch file, without using a temp SQL file.

That technique involves echo'ing the SQL statements to a temp file, then call sqlplus on that file:

REM create the temp SQL file
echo SELECT USER >>temp.sql
echo FROM DUAL;  >>temp.sql

REM execute sqlplus
sqlplus -S / @temp.sql

REM cleanup!
del temp.sql

An alternative is to wrap the echo statements in parentheses "( ... )", so they execute as a block, then pipe "|" the result to sqlplus:

(
    echo SELECT USER
    echo FROM DUAL;
) | sqlplus -S /

Admittedly, this is not much prettier than the first example, but it's self-contained, and doesn't leave random temp files that may or may not get cleaned up.

Friday, May 9, 2014

HEREDOC for Windows Batch Files

From Wikipedia: "In computer science, a here document (here-document, heredoc, hereis, here-string or here-script) is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file."


Here's one way to accomplish this in a Windows batch file. Inside the batch file, echo the text to an output redirection, e.g. "> here.txt". Use carets "^" followed by double linebreaks to output on separate lines:

here_test.bat

echo This is my ^

multi-line here document ^

that this batch file ^

will print! > here.txt



When executed here_text.bat will create a new file here.txt containing the lines of text:

This is my
multi-line here document
that this batch file
will print!

Monday, March 3, 2014

Protective

Noticed this rather defensive SSID in passing from my bus commute. I'm not sure if it's the WiFi or the Wife that's under guard, but the security's pretty robust. 

Thursday, May 16, 2013

Do-it-yourself uptime command for Windows 7

How long has my computer been running? A fundamental question that Unix-y systems can answer with the uptime command.

For some odd reason, Windows 7 has no built-in uptime command. You can simulate this by displaying the date and time Windows 7 last rebooted as reported by the net statistics command. Put this in a file named uptime.bat somewhere on your path:

@echo off
for /f "tokens=1,2,*" %%i in ('net statistics workstations ^| find "since"') do @echo %COMPUTERNAME% up since %%k

Then open a command prompt and type in the freshly minted command:

C:\Users\philip>uptime
MYCOMPUTER up since 5/15/2013 5:21:27 PM