NTDOCAdministrator
(KiX Master)
2004-03-28 11:10 AM
InUse() - Function to remove in use files

I would like to see a new function added to KiXtart that would allow for the COPY/MOVE/DELETE of in use files.

Further information can be reviewed here.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/movefileex.asp

http://www.jsiinc.com/subk/tip5300/rh5378.htm

You can add a single entry into this location with KiXtart to delete a file that is currently locked, but you can't seem to add multiple entries possibly due to the use of NULL

The program MoveEX can if run multiple times can add multiple files to the list as marked for DELETION on the next reboot.

Files are not deleted by this process live, this happens after a reboot of the system.

The Key location is here
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

The new function should support Adding entries for Copy/Move/Delete as well as removal of current entries.


Sealeopard
(KiX Master)
2004-03-28 03:29 PM
Re: InUse() - Function to remove in use files

See the UDF Forum under UpdateFileOnReboot()- Schedules a file to be replaced on reboot.

I will update this function to include file removal if only one parameter is being supplied to it.


NTDOCAdministrator
(KiX Master)
2004-03-28 09:56 PM
Re: InUse() - Function to remove in use files

Yes, I've seen the UDF, but I would like KiXtart to be able to deal with MULTIPLE files/folders just as the INUSE program from Microsoft does. I can easily manage any operation on a single file, it's the multiple files/folders that is an issue.

Sealeopard
(KiX Master)
2004-03-29 05:11 AM
Re: InUse() - Function to remove in use files

It does support multiple files. It will always append to the existing content of the PendingFileRenameOperations registry value. It currently just doesn't support the removal of in-use files, just the replacement.

Dann Cox
(Fresh Scripter)
2004-07-05 07:56 AM
Re: InUse() - Function to remove in use files

Jens,
I've been trying to do just this, no success before. As mentioned at the top of this thread, Nulls seem to be the catch. I haven't found a way to write a null string to this key, which is required as the second string to delete a file. I'm hoping, from your post here, that you have a way!

[Topic closed by moderator because it is posted to wrong forum]


NTDOCAdministrator
(KiX Master)
2004-11-26 10:13 AM
Re: InUse() - Function to remove in use files

I still don't see that your UDF is able to handle the removal of multiple files correctly, so I still opt to ask/suggest that a similar function as the INUSE.EXE has be added to KiXtart.


Sealeopard
(KiX Master)
2004-11-26 02:10 PM
Re: InUse() - Function to remove in use files

If you're talking about my UDF, it only deals with the replacement of files during reboot.

Richard H.Administrator
(KiX Supporter)
2004-11-26 03:03 PM
Re: InUse() - Function to remove in use files

It's an interesting problem.

Null values are illegal in REG_MULTI_SZ records - try adding one manually and REGEDIT will bitch about it and remove the null string.


Richard H.Administrator
(KiX Supporter)
2004-11-26 03:25 PM
Re: InUse() - Function to remove in use files

...but I have a way to do it

[update]
Damnit! I had a solution but it writes in ASCII, and the registry strings need to be UNICODE


LonkeroAdministrator
(KiX Master Guru)
2004-12-07 07:56 AM
Re: InUse() - Function to remove in use files

what is this problem you talk about?

NTDOCAdministrator
(KiX Master)
2004-12-07 08:55 AM
Re: InUse() - Function to remove in use files

Jens,

Quote:

If you're talking about my UDF, it only deals with the replacement of files during reboot.




I've tried a few methods but I'm unable to get your udf to properly handle multiple files for replacement either. As far as I can tell this requires the nul value which I don't think KiXtart can do natively.

If I'm wrong that's cool, please post a valid working example.


Think Ruud could easily add this to KiXtart though with very minimal effort and size increase. Have seen code around 20k to do this I think, but a lot of that size is just the fact of creating the EXE in the first place I would guess, so the increase for the KiXtart EXE would probably only increase a very small amount.


LonkeroAdministrator
(KiX Master Guru)
2004-12-07 09:32 AM
Re: InUse() - Function to remove in use files

so, what's wrong with the pipe-character?
doesn't it write null to the regvalue?


Richard H.Administrator
(KiX Supporter)
2004-12-07 11:13 AM
Re: InUse() - Function to remove in use files

Quote:

so, what's wrong with the pipe-character?
doesn't it write null to the regvalue?




No, for two reasons. First, two pipes together "||" are interpreted as a pipe character in the data rather than a null field.

Second, have you tried using Regedit to add a null entry to the value? It removes it and states that null values are not allowed in REG_MULTI_SZ strings.

You *can* write them. I've done it using StdRegProv and SetMultiStringValue along with my binary data UDFs.

The problem is that the values need to be (sort of) UNICODE.

I got part way through writing the ASCII -> UNICODE conversion stuff, but "real work" has intervened and as this is not something I need right now I have had to drop it.

If anyone would like to pick it up and complete it, here is what I have so far...
Code:
Break ON
$=SetOption("Explicit","ON")
$=SetOption("WrapAtEOL","ON")

udfAppendMultiSZ(".","HKCU","Software\KiXtart\Testing","RMSZKEY","fooBAR")
If @ERROR "ERROR: " @ERROR ": " @SERROR EndIf

Exit @ERROR

Function udfAppendMultiSZ($sComputer,$sHive,$sKey,$sValueName,$aValues)
Dim $iResult
Dim $aOldValues
Dim $iHiveID
Dim $oReg
Dim $iIndex

Select
Case $sHive="HKCU" or $sHive="HKEY_CURRENT_USER"
$iHiveID=&80000001
Case $sHive="HKLM" or $sHive="HKEY_LOCAL_MACHINE"
$iHiveID=&80000002
Case "Default"
Exit 1
EndSelect

$aOldValues=ReadValue("\\"+$sComputer+"\"+$sHive+"\"+$sKey,$sValueName)
If @ERROR Exit @ERROR EndIf

If VarType($aValues) & 8192 $aValues=Join($aValues,"|") EndIf
If $aOldValues<>"" $aValues=$aOldValues+"|"+$aValues EndIf

$aValues ?

$oReg=GetObject(
"winmgmts:{impersonationLevel=impersonate}!\\"+
+$sComputer
+"\root\default:StdRegProv")
If @ERROR Exit @ERROR EndIf
$aValues=Split($aValues,"|")
For $iIndex=0 to UBound($aValues)
$aValues[$iIndex]=ASCIItoUNICODE($aValues[$iIndex])
Next
Exit $oReg.SetMultiStringValue($iHiveID,$sKey,$sValueName,$aValues)

EndFunction

; Convert an ASCII string to a UNICODE string
Function ASCIItoUNICODE($s)
Dim $oStream,$adTypeBinary,$adTypeText

$adTypeBinary=1
$adTypeText=2

$oStream=CreateObject("ADODB.Stream")
If @ERROR Exit @ERROR EndIf


$oStream.Type=$adTypeBinary
$oStream.Open

;$oStream.Write(udfIntToByte(255))
;$oStream.Write(udfIntToByte(254))
While $s <> ""
$oStream.Write(udfIntToByte(Asc($s)))
$oStream.Write(udfIntToByte(0))
$s=SubStr($s,2)
Loop
; Write end of string sentinel
$oStream.Write(udfIntToByte(0))
$oStream.Write(udfIntToByte(0))
$oStream.SetEOS

$oStream.Position=0

$ASCIItoUNICODE=$oStream.Read($oStream.Size)
$oStream.Close
"Data type now: " VarTypeName($ASCIItoUNICODE) ?
Exit 0

EndFunction

; Convert a single integer to a byte array
Function udfIntToByte($i)
Dim $oStream,$adTypeBinary,$adTypeText

$adTypeBinary=1
$adTypeText=2

$oStream=CreateObject("ADODB.Stream")
If @ERROR Exit @ERROR EndIf

$i=CInt($i) & 255

$oStream.Type=$adTypeText
$oStream.CharSet="unicode"
$oStream.Open
$oStream.WriteText(" "+Chr($i))
$oStream.Position=0
$oStream.Type=$adTypeBinary

If $i
$oStream.Position=$oStream.Size-2
Else
$oStream.Position=$oStream.Size-1
EndIf
$udfIntToByte=$oStream.Read(1)
$oStream.Close
Exit 0

EndFunction



The problem is that the ASCIItoUNICODE function converts the string OK, but because it ends up as a BYTE ARRAY the .SetMultiStringValue method rejects the data.

I've also tried reading the data back from the converter using .ReadText with a charset of Unicode. While this returns a string is appears to get set back to an ASCII type which kind of defeats the object.


NTDOCAdministrator
(KiX Master)
2005-12-15 02:33 AM
Re: InUse() - Function to remove in use files

Has anyone heard anything from Ruud about this?

I end up wanting/needing this type of support from KiX quite often now.
 


LonkeroAdministrator
(KiX Master Guru)
2005-12-15 06:36 PM
Re: InUse() - Function to remove in use files

you talking about inuse() stuff or what?

NTDOCAdministrator
(KiX Master)
2005-12-15 10:11 PM
Re: InUse() - Function to remove in use files

Yes, I'd like to see KiXtart natively support a file inuse type function that would alter the registry properly and allow files to be removed/replaced on reboot.
 


LonkeroAdministrator
(KiX Master Guru)
2006-01-06 10:26 PM
Re: InUse() - Function to remove in use files

Done in 4.52 Beta 2

NTDOCAdministrator
(KiX Master)
2006-01-06 11:58 PM
Re: InUse() - Function to remove in use files

Cool, I'll test this and the RD and post back.

NTDOCAdministrator
(KiX Master)
2006-01-14 12:13 PM
Re: InUse() - Function to remove in use files

Okay took me a while but finally did some testing.

Well as it turns out Ruud didn't tell us what that NEW switch was in 4.52 beta 2 for DEL and MOVE

From the readme for 4.52 beta 2
Quote:

6) Added an option to MOVE and DEL to postpone the actual file operation until
the next re-boot. This enables you to replace or delete files that are in
use. Note that this option requires the user to have administrative
privileges.





As it turns out the switch to use is /P

Using DEL and MOVE with /P worked as expected. It placed valid entries for single or multiple files into the

'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager'
PendingFileRenameOperations

Files were deleted on reboot, or moved to new location.


THANK YOU RUUD - Really nice to finally have this working. Greatly appreciated.
 

 


LonkeroAdministrator
(KiX Master Guru)
2006-01-14 12:41 PM
Re: InUse() - Function to remove in use files

hmm...
the beta2 post is screwed up now but nonetheless, in the notes ruud did say the switch:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=154281


Sealeopard
(KiX Master)
2006-01-14 01:58 PM
Re: InUse() - Function to remove in use files

Can somebody test whether MOVE /P will work if the source file resides on a share, UNC, or external drive like USB Stick? My gut feeling is that MOVE /P is designed to work with only local files. This should then be added to the documentation.

My UDF that replaces in-use files is specifically coded to copy files to the local drive to take care of situations where the source file is remote.


NTDOCAdministrator
(KiX Master)
2006-01-16 11:34 AM
Re: InUse() - Function to remove in use files

Don't need to Test. The files will only be removed from local device. The MOVE and DEL /P happen right after the AUTOCHECK routine which does not have access to any remote drives at that point in time. Possibly USB as long as it loads from BIOS and not by Windows drivers.
 


NTDOCAdministrator
(KiX Master)
2006-01-16 12:07 PM
Re: InUse() - Function to remove in use files

Okay I think the DEL is not correctly implmented on Windows 9x with the WININIT.INI file.

An example entry after using is:
[rename]
C:\WINDOWS\Temporary Internet Files\Content.IE5\index.dat=NUL

This is wrong for 2 reasons.
1. Long file names are not supported at that point in time
2. The DestinationFileName (in this case NUL) comes first not last

Working example:
[rename]
NUL=C:\WINDOWS\TEMPOR~1\CONTENT.IE5\INDEX.DAT


Further explanation can be found in this KB

How To Move Files That Are Currently in Use
http://support.microsoft.com/kb/140570
 
Quote:


The syntax of the [rename] section is:
DestinationFileName=SourceFileName
 
DestinationFileName and SourceFileName must reside on the same volume and be short (8.3) file names because Wininit.ini is processed before the protected mode disk system is loaded, and long file names are only available when the protected mode disk system is running. Destination and source files specified in Wininit.ini with long file names are ignored.





 


NTDOCAdministrator
(KiX Master)
2006-01-16 12:34 PM
Re: InUse() - Function to remove in use files

Well actually I take back item 1 on long file names. That was due to my own coding and does not need to be part of KiX executable (unless Ruud wants to add ERROR code to trap when a Long Filename is being used on Windows 9x - otherwise disregard the report of this as an error in the program)

The NUL though should be reversed to come first for deletes.
I did not test the MOVE functionality on Windows 9x but would assume it has same issue.