Get the Current Hour in Batch files

Filed under: Windows — jac @ September 5, 2006 - 7:39 am

(from the I dislike Windows slightly less than I used to dept.)

In a project I’m working on, I needed a way to get the current hour from within a Windows batch file. This sort of thing is trivial on Unix like systems (or using Cygwin with Windows, which wasn’t an option in this case).

Poking around the web, I found the solution here.

The short answer:

set hr=%TIME:~0,2%

In the above code snippet, hr will be set to the current hour.

The long answer:

The “:~” characters tell the batch file to return a subset of data from the variable. The number that immediately follows :~ is the character position to start with, and the first character in the string is always 0. So %TIME:~0% is functionally equivalent to %TIME%. Optionaly after the number can be a comma followed by another number, indicating how many characters to include. So the reference %TIME:~3,2% tells the batch file to return two characters starting at position 3 from the current time. In other words, the two characters that represent the current minute.



That was quick

Filed under: Windows — jac @ August 5, 2005 - 7:18 am

(via email)

First Windows Vista viruses unleashed:

An Austrian hacker earned the dubious distinction of writing what are thought to be the first known viruses for Microsoft Corp.’s Windows Vista operating system. Written in July, the viruses take advantage of a new command shell, code-named Monad, that’s included in the Windows Vista beta code.

The viruses were published last month in a virus-writing tutorial written for an underground hacker group calling itself the Ready Ranger Liberation Front, and take advantage of security vulnerabilities in the new command shell. Unlike the traditional Windows graphical user interface, which relies heavily on the mouse for navigation, command shells allow users to use powerful text-based commands, much like Windows’ predecessor, DOS.

The viruses were written by a hacker calling himself “Second Part To Hell” and published on July 21, just days after Monad was publicly released by Microsoft, according to Mikko Hypponen, chief research officer at Helsinki, Finland-based F-Secure Corp. Second Part To Hell is the pseudonym of an Austrian-based hacker who also goes by the name Mario, Hypponen said.

Because of its sophistication, the new command shell offers new opportunities for hackers, Second Part To Hell wrote in the tutorial, a copy of which was obtained by the IDG News Service. “Monad will be like Linux’s BASH (Bourne Again Shell) — that means a great number of commands and functions,” he wrote. “We will be able to make as huge and complex scripts as we do in Linux.”

F-Secure has named the virus family Danom (Monad in reverse). After examining the code, Hypponen said that the Danom family is disruptive but not capable of causing significant damage to Windows users. “These are proof-of-concept viruses where virus writers want to break new ground and write the first viruses for a new platform.”

Most security experts had not expected to see a Windows Vista virus so soon, Hypponen said. “The only surprise here is that it came so early. It’s been eight days since the beta of the operating system was out.”

Monad was released several days prior to the Windows Vista beta.

Still, Danom’s release does raise questions about whether Microsoft should enable the Monad shell by default in Windows Vista.

Because Monad’s scripting capabilities will be used only by advanced users, Hypponen believes Microsoft should not offer the software as part of the standard Windows Vista package when it becomes commercially available in the second half of 2006. This would make the software less prevalent, and therefore less attractive to virus writers, he said.

Microsoft “got burned,” by including similar software, called Windows Script Host, by default in its Windows 2000 operating system, he said. “Since it was on the system, all the virus writers were exploiting it.”

Microsoft was unable to immediately comment.

… shells allow users to use powerful text-based commands, much like Windows’ predecessor, DOS.

  1. The text-based commands in DOS weren’t at all powerful.
  2. These text-based commands were always available in Windows.
  3. Powerful scripting is available for Windows, check out BASH (which isn’t Linux specific, BTW), which can be obtained as part of Cygwin (which is the first thing I download when I’m required to use Windows).


Converting ISO-8859-1 data to UTF-8 (and back again)

Filed under: Windows — jac @ February 22, 2005 - 7:32 pm

Recently I had to convert ISO-8859-1 data to UTF-8. The quick and easy way to do this is to use iconv from the command line. Unfortunately this had to be done from within a Visual C++/MFC application on Windows (so Cygwin wasn’t really an option). Fortunately, I found libiconv-win32. I installed the source and built the library (part of the process involves installing gettext for Win32 - just follow the instructions).

Since making libiconv-win32 part of the app’s project and adding the appropriate function calls, this app can now convert ISO-8859-1 data to UTF-8 (and back again).




  



November 2008
M T W T F S S
« Aug    
 12
3456789
10111213141516
17181920212223
24252627282930

Statistics

There are currently 31 posts and 16 comments, contained within 12 categories.


Miscellaneous
- Source Files

Add to Technorati Favorites



Storage B
-OpenDDS Version 1.2 Released
-FreeVMS
-OpenDDS Version 1.1 Released
-C++ functions to convert between decimal degrees and degrees, minutes, and seconds
-WordPress 2.5
-Multics
-C++ Functions to Evaluate Chebyshev Polynomials
-OpenDDS
-X Windows Programming in C++: Part III
-X Windows Programming in C++: Part II

Valid XHTML 1.0!

Valid CSS!