Sense or Nonsense!?

19.04.2010

Howto determine if a drive is compressed or not in Windows XP or later

Filed under: Windows — Ephraim @ 12:05

For NTFS file-based compression method you will need to check the attributes of any specific file to see if it’s compressed. Usually it is enough to look at the attributes of C:\ but this is not
really needed to be compressed to have other files being compressed on the drive as NTFS supports to have just single files being compressed.

Here a function C# implementation to check the attribute:

// call this function like e.g.  bool b = IsCompressed(@”C:\”);
// when C:\ marked to be compressed, it will return true … says nothing about the whole drive!!!!
public static bool IsCompressed(string path)
{
return IsCompressed((FileSystemInfo)new FileInfo(path));
}

public static bool IsCompressed(FileSystemInfo fsi)
{
return (fsi.Attributes & FileAttributes.Compressed) == FileAttributes.Compressed;
}

For drive-based  compression method, like good old doublespace, you just need to get yourself the instance of Win32_LogicalDisk of the drive you want to check and look at the property “Compressed”.

e.g. for root\cimv2\Win32_LogicalDisk.DeviceID=”C:” you will get something like following:

instance of Win32_LogicalDisk
{
Caption = “C:”;
Compressed = FALSE;
CreationClassName = “Win32_LogicalDisk”;
Description = “Lokale Festplatte”;
DeviceID = “C:”;
DriveType = 3;
FileSystem = “NTFS”;
FreeSpace = “25166004224″;
MaximumComponentLength = 255;
MediaType = 12;
Name = “C:”;
QuotasDisabled = TRUE;
QuotasIncomplete = FALSE;
QuotasRebuilding = FALSE;
Size = “52427898880″;
SupportsDiskQuotas = TRUE;
SupportsFileBasedCompression = TRUE;
SystemCreationClassName = “Win32_ComputerSystem”;
SystemName = “XXXXXXX”;
VolumeDirty = FALSE;
VolumeName = “System”;
VolumeSerialNumber = “XXXXXXX”;
};

Here is a small VBScript which does this for the drive “C” …

Set oWmi = GetObject(“winmgmts:/root/cimv2″)
Set driveC = oWmi.Get(“Win32_LogicalDisk.DeviceID=”"C:”"”)

if not driveC.Properties_.Item(“Compressed”).Value then
WScript.echo(“Drive C: is NOT compressed.”)
else
WScript.echo(“Drive C: IS compressed.”)
end if

Ciao Thilo

16.07.2009

THE missing functions in windows …

Filed under: Windows — Ephraim @ 15:15

Here are the two functions I often missed in the windows C/C++ libraries …

#include <sys/types.h>
#include <sys/stat.h>

bool file_exists(const TCHAR* lspzFile) {
	int i;
	struct _stat s;

	if(!lspzFile) return false;

	i = _tstat(lspzFile, &s);

	if(!i && (s.st_mode & _S_IFREG) != 0)
		return true;
	else
		return false;
}

bool dir_exists(const TCHAR* lspzDirectory) {
	int i;
	struct _stat s;

	if(!lspzDirectory) return false;

	i = _tstat(lspzDirectory, &s);

	if(!i && (s.st_mode & _S_IFDIR) != 0)
		return true;
	else
		return false;
}

Ciao Ephraim

07.07.2009

Creating a WinPE 3.0 ISO with Windows AIK and mkisofs

Filed under: Windows — Ephraim @ 13:57

When you have succeeded in downloading and installing Windows AIK for Windows 7 and wonder how you can create a WinPE 3.0 CD now, you are in the same situation as I was some time before.

Of course you can use WinBuilder or PEBuilder or such things, but if you need to do anything by hand, then you’ll need to go the same way as I did.

First of all you can create a basic WinPE 3.0 ISO content with the copype.cmd of the Windows AIK installation.
Just navigate to the folder, containing copype.cmd and fire up the following command (my WinPE working folder is here C:\WinPE, but you can name this as you want):

copype.cmd x86 C:\WinPE

This will copy some files/folders to C:\WinPE.
One folder is called ISO, this is the WinPE 3.0 ISO Content folder, where later your ISO will be created from.
And one file is called winpe.wim, which is the start windows image file.

If you want to have a very basic WinPE, you can skip the next steps and go over to copying the WIM.
I needed to include WMI in the WinPE so I need to include WMI Package into the wim.
For that you will need to mount the WIM, this can be done by the following command:

imagex.exe /mountrw C:\WinPE\winpe.wim 1 c:\WinPe\mount

This will mount the wim to C:\WinPE\mount.
Then you need to install the WMI Package from Windows AIK into the mounted WIM.

dism.exe /Image:C:\WinPE\mount /add-package /packagepath:<winAikFolder>\Tools\PETools\x86\WinPE_FPs\winpe-wmi.cab

So now just umount and commit the wim by executing the following command:

imagex.exe /unmount /commit c:\WinPe\mount

Copying the WIM; The winpe.wim needs to be copied to the ISO Folder. And it must go into the Sources folder as boot.wim.

xcopy c:\WinPE\winpe.wim C:\WinPe\ISO\Sources\boot.wim

Ok, so far the preperations of the WinPE 3.0 ISO Content folder is done.
Now we need to create a ISO of the folder.
For this job, I used the mkisofs.exe, with the following commandline:

mkisofs.exe -iso-level 4 -allow-lowercase -volid "MyWinPe" -b "boot/etfsboot.com" -no-emul-boot -boot-load-size 8 -hide boot.catalog -o C:\WinPE\WinPE-3.0.iso C:\WinPE\ISO

As a hint, try your ISO in vmware before burning it to a cd, or use a cdrw :) .

Ciao Ephraim

Powered by WordPress