function InitializeCustomInfo()
	STRING	svUninstParam;
begin
	gCustomInfo.szTwainDir = WINDIR ^ "TWAIN_32" ^ IFX_PRODUCT_KEY;
	gCustomInfo.szDriverPackageDir = COMMONFILES ^ IFX_PRODUCT_KEY;
    StrSub(svUninstParam, UNINSTALL_STRING, 9, StrLength(UNINSTALL_STRING));
	gCustomInfo.szUninstParam = svUninstParam;
	   
    gCustomInfo.szSYRootKey = "System\\Sonix";
    gCustomInfo.szSoftRootKey = "Software\\Sonix";
    gCustomInfo.szProductType = "PCCAM";
    
    gCustomInfo.szDriverService = IFX_PRODUCT_KEY;
    gCustomInfo.szDefInfPath = WINDIR ^ "INF" ^ IFX_PRODUCT_KEY + ".inf";
    
	if (SYSINFO.WINNT.bWinNT) then
 		gCustomInfo.szUninstToolPath = WINDIR ^ "u" + IFX_PRODUCT_KEY + ".exe";
 	else
 		gCustomInfo.szUninstToolPath = "";
 	endif;

	gCustomInfo.bInitialized = TRUE;
end;

function InitializeCustomTarget()
begin
	if (!gCustomInfo.bInitialized) then
		InitializeCustomInfo();
	endif;
	
    ComponentSetTarget (MEDIA, "<TWAIN_DS_DIR>", gCustomInfo.szTwainDir);
    ComponentSetTarget (MEDIA, "<DRIVER_PACKAGE_DIR>", gCustomInfo.szDriverPackageDir);
    ComponentSetTarget (MEDIA, "<UNINST_PARAM>", gCustomInfo.szUninstParam);
end;

function UninstallDriver()
	STRING szSoftProductTypeKey;
	NUMBER nKeyCounts, nNameCounts;
	NUMBER OldValue;
    NUMBER nResult;
    NUMBER hkResult, dwDisposition;
    NUMBER nValue; 
    STRING svKeyName[MAX_PATH];
    STRING svResult;
    NUMBER hkResult2, hkResult3;
    NUMBER nIndex;
    LIST listID;    
    STRING szTmp[256];
 
begin               
	Sprintf(szTmp, "Maj=%d Min=%d", SYSINFO.nWinMajor, SYSINFO.nWinMinor); 
//	MessageBoxEx(szTmp, "UninstallDriver", INFORMATION);
	if (!gCustomInfo.bInitialized) then
		InitializeCustomInfo();
	endif;
    
    // remove driver service and hardware key    
	if (SYSINFO.WINNT.bWinNT) then
		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
//			MessageBoxEx("123", "", INFORMATION);
			Wow64DisableWow64FsRedirection(&OldValue);
	    	LaunchAppAndWait ( "rundll32.exe" , WINSYSDIR ^ "c" + IFX_PRODUCT_KEY + ".dll,DelHwKey Software\\Sonix\\PCCAM\\" + IFX_PRODUCT_KEY , LAAW_OPTION_WAIT );
	    	Wow64RevertWow64FsRedirection(OldValue);
			
		else                  
//			MessageBoxEx("456", "", INFORMATION);
		    if (Is ( FILE_EXISTS , WINDIR^"usnp2std.exe" )) then
	           ServiceRemoveService ( gCustomInfo.szDriverService );
			   LaunchAppAndWait ( WINDIR ^ "u" + IFX_PRODUCT_KEY + ".exe", "NOREBOOT" , LAAW_OPTION_WAIT );
	        else 
		       LaunchAppAndWait ( "rundll32.exe" , WINSYSDIR ^ "c" + IFX_PRODUCT_KEY + ".dll,DelHwKey Software\\Sonix\\PCCAM\\" + IFX_PRODUCT_KEY , LAAW_OPTION_WAIT );
		    endif; 
		endif; 

	endif;

    if (SYSINFO.WINNT.bWinNT) then
   // 	ServiceStopService ( "StiSvc" );
    	ServiceRemoveService ( gCustomInfo.szDriverService );
//    	LaunchAppAndWait ( gCustomInfo.szUninstToolPath , "NOREBOOT" , LAAW_OPTION_WAIT );
 //   	ServiceStartService ( "StiSvc" , "" );
    else
        RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6240"); //SN9C201 + MI1300
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6242"); //SN9C201 + MI1310
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_624e"); //SN9C201 + OV9630
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_624f"); //SN9C201 + OV9650
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6270"); //SN9C201 + MI0360
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_627c"); //SN9C201 + HV7131R   
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_627b"); //SN9C201 + OV7660  
        RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_627a"); //SN9C201 + S5K53BEB  
        RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_624b"); //SN9C201 + CX1332
        RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6243"); //SN9C201 + S5K4AAFX 
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_627f"); //EEPROM
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6260"); //SN9C201 + OV7670ISP 
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6248"); //SN9C201 + OV9655
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_624c"); //SN9C201 + MI1320
             
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6280"); //SN9C202 + MI1300 
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6280&MI_00");
      	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6280&MI_01");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6282"); //SN9C202 + MI1310  
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6282&MI_00");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6282&MI_01");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628e"); //SN9C202 + OV9630  
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628e&MI_00");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628e&MI_01");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628a"); //SN9C202 + ICM107   
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628a&MI_00"); 
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628a&MI_01"); 
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628f"); //SN9C202 + OV9650   
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628f&MI_00");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628f&MI_01");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62b0"); //SN9C202 + MI0360 
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62b0&MI_00");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62b0&MI_01");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62bc"); //SN9C202 + HV7131R   
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62bc&MI_00"); 
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62bc&MI_01"); 
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62bb"); //SN9C202 + OV7660  
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62bb&MI_00");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62bb&MI_01");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62ba"); //SN9C202 + S5K53BEB  
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62ba&MI_00");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62ba&MI_01");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628b"); //SN9C202 + CX1332   
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628b&MI_00"); 
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628b&MI_01"); 
      	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6283"); //SN9C202 + S5K4AAFX  
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6283&MI_00");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6283&MI_01");
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62a0"); //SN9C202 + Ov7670ISP  
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62a0&MI_00");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_62a0&MI_01");
       	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6288"); //SN9C202 + Ov9655 
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6288&MI_00");
     	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_6288&MI_01");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628c"); //SN9C202 + MI1320  
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628c&MI_00");
    	RegDBDeleteKey ( "Enum\\USB\\VID_0c45&PID_628c&MI_01");     		

    	RegDBDeleteKey ( "Enum\\Root\\Unknown" );
    	DeleteFile ( WINDIR ^ "INF" ^ "drvidx.bin");
    	DeleteFile ( WINDIR ^ "INF" ^ "drvdata.bin");
    endif;

	// remove software key
	if (MAINTENANCE) then
        RegDBSetDefaultRoot ( HKEY_CLASSES_ROOT );
        
        RegDBDeleteKey ( "CLSID\\{D80AF729-7C23-4e10-BC5F-1D8C157F96E3}" );
        RegDBDeleteKey ( "CLSID\\{FCDF1C13-A80A-44bd-A5D7-D5D02EFDE936}" );
        RegDBDeleteKey ( "CLSID\\{BD534CAF-A832-441d-82EF-2D0564943676}" );
        RegDBDeleteKey ( "CLSID\\{BD534CAF-A832-441d-82EF-2D0564943677}" );
             
        RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
        
        RegDBDeleteKey ( "System\\CurrentControlSet\\Control\\MediaInterfaces\\{D80AF729-7C23-4e10-BC5F-1D8C157F96E3}" );
        RegDBDeleteKey ( "System\\CurrentControlSet\\Control\\MediaSets\\{D80AF729-7C23-4e10-BC5F-1D8C157F96E3}" );
      
        RegDBDeleteValue ( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" , IFX_PRODUCT_KEY );
        
        nKeyCounts = RegDBQueryKeyCount ( szSoftProductTypeKey , REGDB_KEYS );
        nNameCounts = RegDBQueryKeyCount ( szSoftProductTypeKey , REGDB_NAMES );
        if (nKeyCounts == 0 && nNameCounts == 0) then
         	RegDBDeleteKey ( szSoftProductTypeKey );
        endif;
        nKeyCounts = RegDBQueryKeyCount ( gCustomInfo.szSYRootKey , REGDB_KEYS );
        nNameCounts = RegDBQueryKeyCount ( gCustomInfo.szSYRootKey , REGDB_NAMES );
        if (nKeyCounts == 0 && nNameCounts == 0) then
        	RegDBDeleteKey ( gCustomInfo.szSYRootKey );
        endif;   
         
	    UseDLL ( "Advapi32.dll" );
	    listID = ListCreate (STRINGLIST);
		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
	    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\SONIX\\PCCAM\\SNP2STD", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult, &dwDisposition);
	    else
	    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\SONIX\\PCCAM\\SNP2STD", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult, &dwDisposition);
	    endif;	
	    if (nResult == ERROR_SUCCESS) then
	    	nIndex = 0;
	    	nResult = RegEnumKeyA(hkResult, nIndex, svKeyName, MAX_PATH);
	    	while (nResult != ERROR_NO_MORE_ITEMS)
	    		ListAddString (listID, svKeyName, AFTER);
	    		nIndex++;
	    		nResult = RegEnumKeyA(hkResult, nIndex, svKeyName, MAX_PATH);
	    	endwhile;
	    	nResult = ListGetFirstString (listID, svKeyName);
	    	while (nResult != END_OF_LIST)
      		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
	    			RegDeleteKeyExA(hkResult, svKeyName, KEY_WOW64_64KEY, 0);
			    else
	    			RegDeleteKeyA(hkResult, svKeyName);
			    endif;	
	    		nResult = ListGetNextString (listID, svKeyName);
	    	endwhile;
	    	RegCloseKey(hkResult);
		endif;
		ListDestroy (listID);
	
		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
	    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\SONIX\\PCCAM", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult, &dwDisposition);
	    else
	    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\SONIX\\PCCAM", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult, &dwDisposition);
	    endif;	
	    if (nResult == ERROR_SUCCESS) then
    		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
    			RegDeleteKeyExA(hkResult, "SNP2STD", KEY_WOW64_64KEY, 0);
		    else
    			RegDeleteKeyA(hkResult, "SNP2STD");
		    endif;	
	    	
	    	nResult = RegEnumKeyA(hkResult, 0, svKeyName, MAX_PATH);
	    	if (nResult == ERROR_NO_MORE_ITEMS) then
           		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
			    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\SONIX", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult2, &dwDisposition);
			    else
			    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\SONIX", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult2, &dwDisposition);
			    endif;	
	    		if (nResult == ERROR_SUCCESS) then
					if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
		    			RegDeleteKeyExA(hkResult2, "PCCAM", KEY_WOW64_64KEY, 0);
				    else
		    			RegDeleteKeyA(hkResult2, "PCCAM");
				    endif;	
	    			
	    			nResult = RegEnumKeyA(hkResult2, 0, svKeyName, MAX_PATH);
	    			if (nResult == ERROR_NO_MORE_ITEMS) then
						if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
					    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult3, &dwDisposition);
					    else
					    	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult3, &dwDisposition);
					    endif;	
	    				if (nResult == ERROR_SUCCESS) then
							if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
				    			RegDeleteKeyExA(hkResult3, "SONIX", KEY_WOW64_64KEY, 0);
						    else
				    			RegDeleteKeyA(hkResult3, "SONIX");
						    endif;	
	    					RegCloseKey(hkResult3);
	    				endif;
	    			endif;
	    			
	    			RegCloseKey(hkResult2);
	    		endif;
	    	endif;
	    	
	    	RegCloseKey(hkResult);
	    endif;
	    //james for amcap in XP64
		if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
	  		nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\StillImage", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult, &dwDisposition);
		else
	   		nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\StillImage", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult, &dwDisposition);
		endif;
		if (nResult == ERROR_SUCCESS) then
			if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
				RegDeleteKeyExA(hkResult, "Registered Applications", KEY_WOW64_64KEY, 0);
			else
				RegDeleteKeyA(hkResult, "Registered Applications");
			endif;
			nResult = RegEnumKeyA(hkResult, 0, svKeyName, MAX_PATH);
			if (nResult == ERROR_NO_MORE_ITEMS) then
				if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
					nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult2, &dwDisposition);
				else
					nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult2, &dwDisposition);
				endif;
				if( nResult == ERROR_SUCCESS) then
					if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
						RegDeleteKeyExA(hkResult2, "StillImage", KEY_WOW64_64KEY, 0);
					else
						RegDeleteKeyA(hkResult2, "StillImage");
					endif;                                  
					RegCloseKey(hkResult2);
				endif;
			endif;
			RegCloseKey(hkResult);
		endif;     
	    UnUseDLL ( "Advapi32.dll" );
	endif;




end;

function UninstallDriverFiles()
	STRING szUninstKeyParent;
	STRING svInfPath, svPnfPath;
	NUMBER nResult, nvType, nvSize;
	BOOL bResult;    //2004-04-08
	BOOL bPnfLocked;
	STRING	svInfPathName, svInfFileName;
	NUMBER	nvFileHandle; 
	STRING szTmp[256];
begin                   
	Sprintf(szTmp, "Maj=%d Min=%d", SYSINFO.nWinMajor, SYSINFO.nWinMinor); 
//	MessageBoxEx(szTmp, "UninstallDriverFiles", INFORMATION);
	if (!gCustomInfo.bInitialized) then
		InitializeCustomInfo();
	endif;   
	
	// remove uninstallation key
	szUninstKeyParent = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
    RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
    RegDBDeleteKey ( szUninstKeyParent + IFX_PRODUCT_KEY );
    RegDBDeleteKey ( szUninstKeyParent + IFX_PRODUCT_NAME );
    
	// delete .inf & .pnf             
   	RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );           
    nResult = RegDBGetKeyValueEx ( szUninstKeyParent + PRODUCT_GUID , "InfPath" , nvType , svInfPath , nvSize );
    if (nResult != 0) then
    	svInfPath = gCustomInfo.szDefInfPath;
    endif;    
	    
	    if ( Is ( FILE_EXISTS , svInfPath ) ) then
	    	bPnfLocked = FALSE;    
	svPnfPath = svInfPath;
	nResult = StrReplace(svPnfPath, ".inf", ".pnf", 0);
	if (nResult > 0) then
				if ( Is ( FILE_EXISTS , svPnfPath ) ) then    
		nResult = DeleteFile( svPnfPath);       //2004-04-08
		if ((nResult != 0) && SYSINFO.WINNT.bWinNT) then
						bPnfLocked = TRUE;
			bResult = MoveFileExA(svPnfPath, NULL, 0x00000004); //0x00000004: MOVEFILE_DELAY_UNTIL_REBOOT
						bResult = MoveFileExA(svInfPath, NULL, 0x00000004);
				BATCH_INSTALL = TRUE;
						
						ParsePath ( svInfPathName , svInfPath , PATH );
						ParsePath ( svInfFileName , svInfPath , FILENAME );
						OpenFileMode ( FILE_MODE_BINARY ); 
						if ( CreateFile ( nvFileHandle , svInfPathName , svInfFileName ) == 0 ) then
							WriteBytes ( nvFileHandle , "" , 0 , 0 );
							CloseFile ( nvFileHandle );
			endif;
		endif;
	endif;
			endif;
			
			if (!bPnfLocked) then
	DeleteFile( svInfPath);
			endif;	
		endif; 

	
	// delete unused directory
    DeleteDir ( gCustomInfo.szTwainDir, ALLCONTENTS );
	DeleteDir ( gCustomInfo.szDriverPackageDir, ALLCONTENTS );
end;

function NUMBER SetDriverSigningStatus(nStatus)
	NUMBER nvPrevStatus, nvType, nvSize;
	STRING szKey, szName, svValue;
begin
	nvPrevStatus = 0;
	
    if (SYSINFO.WINNT.bWin2000) then
    	szKey = "SOFTWARE\\Microsoft\\Driver Signing";
    	szName = "Policy";
    	 
	    RegDBSetDefaultRoot ( HKEY_CURRENT_USER );
	    RegDBGetKeyValueEx ( szKey , szName , nvType , svValue , nvSize );
	    StrToNum(nvPrevStatus, svValue);
	    
	    NumToStr(svValue, nStatus);
	    RegDBSetKeyValueEx ( szKey , szName , REGDB_NUMBER , svValue , -1 );
	    
    	RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
    	Sprintf(svValue, "%c\0\0\0", nStatus);           
	    RegDBSetKeyValueEx ( szKey , szName , REGDB_BINARY , svValue , 4 );
    endif;
    
    return nvPrevStatus;
end;

function PostInstallation()
    STRING szInfPath, svOEMInfPath[MAX_PATH];
    STRING szUninstKey, szName;
    STRING szAMCapValue;
    BOOL bResult;
    NUMBER nResult;
    NUMBER hkResult, dwDisposition;

begin
	WriteProfString (WINDIR ^ "win.ini", "annie", "WantPreview", "1");  
    WriteProfString (WINDIR ^ "win.ini", "annie", "UseFrameRate", "1");
	WriteProfString (WINDIR ^ "win.ini", "annie", "FrameRate", "333333"); 
   	LaunchAppAndWait ( WINDIR ^ "t" + IFX_PRODUCT_KEY + ".exe", "" , LAAW_OPTION_NOWAIT );

	if (!gCustomInfo.bInitialized) then
		InitializeCustomInfo();
	endif;
	
    Disable(LOGGING);
    
    if (SYSINFO.WINNT.bWinNT) then
    	SetDriverSigningStatus(0);
    	
	    szInfPath = gCustomInfo.szDriverPackageDir ^ IFX_PRODUCT_KEY + ".inf";
	    UseDLL ( "Setupapi.dll" );
	    bResult = SetupCopyOEMInfA( szInfPath, NULL, 1, 0, svOEMInfPath, MAX_PATH, NULL, NULL );
	    UnUseDLL ( "Setupapi.dll" );
	    
	    if (bResult) then
	    	szUninstKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + PRODUCT_GUID;        
	    	szName = "InfPath";
	    	RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
		    RegDBSetKeyValueEx ( szUninstKey, szName , REGDB_STRING , svOEMInfPath , -1 );
	    endif;
	else
		WriteProfString (  gCustomInfo.szDefInfPath, "SN.USBPCam" , "CopyFiles" , "SN.MSDriver.CopyFiles" );
		WriteProfString (  gCustomInfo.szDefInfPath, "SN.PCamMic" , "CopyFiles" , "SN.MSDriver.CopyFiles" ); 
		WriteProfString (  gCustomInfo.szDefInfPath, "SN.USBPCamVGA" , "CopyFiles" , "SN.MSDriver.CopyFiles" );
		WriteProfString (  gCustomInfo.szDefInfPath, "SN.PCamMicVGA" , "CopyFiles" , "SN.MSDriver.CopyFiles" ); 

        // Auto Enable DMA
//	    LaunchAppAndWait ( "rundll32.exe" , WINSYSDIR ^ "c" + IFX_PRODUCT_KEY + ".dll,SwitchHdDma ON" , LAAW_OPTION_WAIT );
//      BATCH_INSTALL = TRUE;	
	endif;
	
    if (SYSINFO.WINNT.bWinNT) then 
    	LaunchAppAndWait ( WINDIR ^ "v" + IFX_PRODUCT_KEY + ".exe", "" , LAAW_OPTION_NOWAIT );
	endif;
//	if (SYSINFO.WINNT.bWinXP) then 
	if ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 1)) then
 	   	LaunchAppAndWait ( "rundll32.exe", WINSYSDIR ^ "csnp2std.dll,GetOSVersion Software\\Sonix\\PCCAM\\" + IFX_PRODUCT_KEY , LAAW_OPTION_WAIT );
    endif;          
    
    //james for amcap in XP64
    UseDLL( "Advapi32.dll" );
	if ( ((SYSINFO.nWinMajor == 5) && (SYSINFO.nWinMinor == 2)) || ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0))) then
	  	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\StillImage\\Registered Applications", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult, &dwDisposition);
	else
	   	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\StillImage\\Registered Applications", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult, &dwDisposition);
	endif;
	if (nResult == ERROR_SUCCESS) then
		szAMCapValue = WINDIR + "\AMCAP.EXE /StiDevice:%1 /StiEvent:%2";
		nResult = RegSetValueExA(hkResult, "AMCap", 0, 1, &szAMCapValue, StrLength(szAMCapValue)+1);
	   	RegCloseKey(hkResult);
	endif;       
	UnUseDLL( "Advapi32.dll" );   
    Enable(LOGGING);
/*
    //Registry amcap in Vista x64
    UseDLL( "Advapi32.dll" );
	if ((SYSINFO.nWinMajor == 6) && (SYSINFO.nWinMinor == 0)) then
	  	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\StillImage\\Registered Applications", 0, 0, 0, (KEY_ALL_ACCESS | KEY_WOW64_64KEY), 0, &hkResult, &dwDisposition);
	else
	   	nResult = RegCreateKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\MICROSOFT\\WINDOWS\\CURRENTVERSION\\StillImage\\Registered Applications", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkResult, &dwDisposition);
	endif;
	if (nResult == ERROR_SUCCESS) then
		szAMCapValue = WINDIR + "\AMCAP.EXE /StiDevice:%1 /StiEvent:%2";
		nResult = RegSetValueExA(hkResult, "AMCap", 0, 1, &szAMCapValue, StrLength(szAMCapValue)+1);
	   	RegCloseKey(hkResult);
	endif;       
	UnUseDLL( "Advapi32.dll" );   
    Enable(LOGGING);
  */
end;