Posts tagged as programming

Cool commandline moves

2009-02-06 by Administrator, tagged as microsoft, programming
FOR /L %f IN (1,1,254) DO ping -w 500 -n 1 192.168.1.%f |
findstr /I reply >> %TEMP%\ping_results.txt

T-SQL Simple Timestamp With Leading Zeros

2008-12-04 by Administrator, tagged as microsoft, programming

I just had to create a simple string in MS T-SQL that would look like the following:

200812041613
or
yyyymmddhhmm

I solved it this way but I have no idea if this is a good solution (comments welcome):

DECLARE @timestamp AS varchar(12)
-- Create Timestamp with leading zeros
-- Year
SET @timestamp = CONVERT( varchar(4), DATEPART(year, GETDATE() ) )
-- Month
IF DATEPART( month, GETDATE() ) < 10
	SET @timestamp = @timestamp + '0' + CONVERT( varchar, DATEPART( month, GETDATE() ) )
ELSE
	SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( month, GETDATE() ) )
-- Day
IF DATEPART( day, GETDATE() ) < 10
	SET @timestamp = @timestamp + '0' + CONVERT(varchar, DATEPART( day, GETDATE() ) )
ELSE
	SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( day, GETDATE() ) )
-- Hour
IF DATEPART( hour, GETDATE() ) < 10
	SET @timestamp = @timestamp + '0' + CONVERT(varchar, DATEPART( hour, GETDATE() ) )
ELSE
	SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( hour, GETDATE() ) )
-- Minute
IF DATEPART( minute, GETDATE() ) < 10
	SET @timestamp = @timestamp + '0' + CONVERT(varchar, DATEPART( minute, GETDATE() ) )
ELSE
	SET @timestamp = @timestamp + CONVERT(varchar(2), DATEPART( minute, GETDATE() ) )
-- Done creating timestamp
print N'' + @timestamp

Automatically Create IIS Application Pools

2008-08-28 by Administrator, tagged as microsoft, programming

Here is the script for the AppPools

@ECHO OFF
ECHO.
FOR /F "eol=# delims=; tokens=1,2*" %%f in (apppools.txt) DO (
  ECHO Creating AppPool "%%f" with user identity "%%g"
  CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS CREATE "w3svc/AppPools/%%f" IIsApplicationPool
  CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET "w3svc/AppPools/%%f/WamUserName" "%%g"
  CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET "w3svc/AppPools/%%f/WamUserPass" "%%h"
  CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET "w3svc/AppPools/%%f/AppPoolIdentityType" 3
  ECHO.
)
pause

And the correspondign text file:

#
# ";"-delimited file to create application pools
# Beware of strange characters in password,
# though ; should work 
# Structure is
#
# AppPool Name	;	User	;	Password
tmpAppPool;tmpUser;tmpPass

Automatically Create IIS Websites

2008-08-21 by Administrator, tagged as microsoft, programming

I had to create quite a lot websites on a Microsoft IIS webserver and of course there is a nice scripting solution to it. Here is how I did it:

Batch code:

@ECHO OFF
SET webRoot=D:\websites
ECHO.
ECHO Creating directories
ECHO and websites
ECHO.
FOR /F "eol=# delims=; tokens=1,2*" %%f in (websites.txt) DO (
	ECHO Creating Dir %webRoot%\%%f\%%g and website %%g in appPool %%h
	MD "%webRoot%\%%f\%%g"
	iisweb /create "%webRoot%\%%f\%%g" "%%g" /i 192.168.228.30 /d %%g.perimeterless.org /ap %%h
	ECHO.
)
pause

and here is the text file that goes with it:

#
# ";"-delimited file to create directory structure,
# websites and application pools
#
# Structure is
#
# Subdirectory	;	Sitename	;	AppPool
testing;test1;DefaultAppPool
testing;test2;DefaultAppPool
testing;test3;DefaultAppPool

Mount ISO images in Konqueror / Dolphin

2007-10-23 by Administrator, tagged as linux, programming

I didn’t want to bring up a console every time I had to mount an ISO image. So I browsed the web a lil’ bit and found a good solution for my needs. I am a big fan of context menus or service menus as they are called in KDE. These menus are configured through .desktop files. To create such a file only a few steps are necessary:

  1. Find out the location of .desktop files
  2. Learn about the syntax of a .desktop file
  3. Check the mime type of the file where the context menu should appear
  4. Some eye candy with Icons and submenus

In the end you will have entries under Actions when you right-click on and ISO image that look somewhat like this:
KDEServiceMenu

1. Where are these files?

You can use

kde-config --prefix

to find out where your KDE has been installed. You will then find a folder

/usr/share/apps/konqueror/servicemenus (in my case)

Here you create a file with any name you like it only must end with .desktop
Since there now also is a noob file manager Dolphin there also is a folder

/usr/share/apps/d3lphin/servicemenus

Anyway, I used a symbolic link to only have to configure one file for both apps.

2. File syntax

Mine looks like this:

[Desktop Entry]
ServiceTypes=application/x-iso
Actions=mountIsoImage;umountIsoImage
X-KDE-Submenu=ISO Image

[Desktop Action mountIsoImage]
Name=Mount
Icon=cdrom_mount
Exec=kdesu -c 'mount -o loop -t iso9660 %f /mnt/iso'

[Desktop Action umountIsoImage]
Name=Unmount
Icon=cdrom_unmount
Exec=kdesu -c 'umount %f'

Here you’ll find a good explanation of the file options.

3. MIME type

As you can see you must declare a ServiceType in the .desktop file. This defines when the context menu should appear. A good way to search for these types is to go to Settings -> Configure Konqueror -> File Associations and use the search feature.

4. Eye candy

You may use you own icon images but if you want to use the system icons I suggest editing a K-Menu entry, clicking on the icon and then using the icon browser to find a name of an icon you like.

REMARK
This is tested with Kubuntu Gutsy Gibbon. But I guess it should also work with other distributions.

IMPROVEMENTS
Instead of using the mount command more or less directly one could use a script to create a temporary folder at the current location where the ISO is then mounted. Unmounting would delete the folder again.