Monday, September 17, 2012

GIT

You can find most of my older and current code at my GIT

(hosted on Bitbucket.com)

Friday, February 27, 2009

batch: ntbackup.exe and rotating daily backups

This one is older batch, that will NOT work on Vista or Windows server 2008.

If you need to do rotating daily backups (seven backups), you can use this simple batch code to call ntbackup.exe.

@echo off
for /f "tokens=1-3 delims=. " %%i in ('date /t') do (set day=%%i)
echo Day: %day%
ntbackup backup \\server\share /j "backup %day%" /f "c:\backups\backup.%day%.bak"


This will fill batch variable %day% with current day (two letters) taken from "date /t" command. Then it will call ntbackup to run a full backup of "\\server\share" including all subdirectories (/j) and will store it to "c:\backups\backup.%day%.bak". Variable %day% will be replaced by current day of the week... so this little script will create 7 backups and will rotate them (if you will run it daily using windows scheduler).

This is really simple batch and can be easily modified to do much more.

Thursday, February 26, 2009

Visual Studio express - problems with 32bit DLLs on 64bit OS.

When you are writing any application in Visual Studio 2005/2008 you can target the application to x86, x64 or by default to AnyCPU. Anytime you want to use 32bit only DLL, you have to set target to x86, otherwise your application will crash on 64bit OS.

However, you can't target your application to specific platform in Visual Studio 2005/2008 express edition! Express editions are targeted to AnyCPU, that will allow them to run in 64bit mode on 64bit OS. The problem is when you will link any 32bit DLL to this project. Your application will crash on 64bit OS as soon as it will try to call any function from the 32bit DLL.

Solution is simple. In full version of Visual studio, just target your application to x86 platform. If you need to do this in express edition, you have to do this manually by edditing your .csproj file. All you need is add one line into this file - <platformtarget>x86</platformtarget>.

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.21022</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{DF511499-467A-4B2D-873E-5297A2AB4698}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>WoL</RootNamespace>
    <AssemblyName>WoL</AssemblyName>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <StartupObject>WoL.Program</StartupObject>
    <SignAssembly>false</SignAssembly>
    <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

You will find several <PropertyGroup> sections there. Just add the <platformtarget>x86</platformtarget> to all these sections and save the file. Now open your project in VisualStudio and recompile it. It will now run in 32bit even on 64bit OS and everything will be working (application will be forced to run in 32bit mode only).