#116960 - 2004-03-28 11:10 AM
InUse() - Function to remove in use files
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
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.
|
Top
|
|
|
|
#116964 - 2004-07-05 07:56 AM
Re: InUse() - Function to remove in use files
|
Dann Cox
Fresh Scripter
Registered: 2002-01-18
Posts: 11
Loc: Nanaimo, BC, Canada
|
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]
Edited by Les (2004-07-05 03:38 PM)
_________________________
Dann Cox Infrastructure Administrator, School District 68 Nanaimo, BC, Canada mailto:dcox@sd68.bc.ca (250) 741-5270
|
Top
|
|
|
|
#116968 - 2004-11-26 03:25 PM
Re: InUse() - Function to remove in use files
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
...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
Edited by Richard H. (2004-11-26 04:30 PM)
|
Top
|
|
|
|
#116970 - 2004-12-07 08:55 AM
Re: InUse() - Function to remove in use files
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
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.
|
Top
|
|
|
|
#116972 - 2004-12-07 11:13 AM
Re: InUse() - Function to remove in use files
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
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.
|
Top
|
|
|
|
#116978 - 2006-01-14 12:13 PM
Re: InUse() - Function to remove in use files
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
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.
|
Top
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 496 anonymous users online.
|
|
|