robiezhou Posted January 10, 2006 Share Posted January 10, 2006 Hi, Dudes I found FileExists and DirRemove do not work for some directories, such as C:\WINNT\$NtUninstallKB890923-IE501SP4-20050225.100310$ In my script, I want to check it the dir exists and then remove it, but it does not work. I tried AutoIt V3.1.1.0 and the latest V3.1.1.100 beta. Thanks a lot. Robie Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 10, 2006 Moderators Share Posted January 10, 2006 (edited) Can you give an example of how you used this?Try this... see what error is thrown if you use it in a stand alone test.au3 script.$File = 'C:\WINNT\$NtUninstallKB890923-IE501SP4-20050225.100310$' If FileExists($File) Then If DirRemove($File, 1) = 0 Then MsgBox(0, 'Error', 'Could not remove Directory' & @CRLF & 'Please check if protected') Else MsgBox(0, 'Error', 'Could not find file, please check path') EndIfEDITI tested this with exactly the same folder and subfolder you had as the example and it worked for me (Win XP Pro Corp. Sp2)....I hope you are only trying to delete the '$NtUninstallKB890923-IE501SP4-20050225.100310$' and subfolders part of the folder and not the WINNT, otherwise your approach is a bit wrong. Edited January 10, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
robiezhou Posted January 11, 2006 Author Share Posted January 11, 2006 Thanks a lot. It was used in this script... expandcollapse popup#include <_mymsg.au3> #include <Array.au3> Global $header = "KBClean " Global $version = "V0.1.0" Dim $keyroot = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' Dim $keyname = 'UninstallString' Dim $akeys[1] Dim $index If MsgQuestion($header & $version, "Are you sure you want to delete the KBUninstall DIRs and these components in registry?") = 0 Then MsgInfo($header & $version, "Program exit...") Exit EndIf ; Get KB List GetKBList(); ;_ArrayDisplay($akeys, "KBList") ; Clean each KB For $index = 0 To UBound($akeys) - 1 If $akeys[$index] <> "" Then CleanKB($akeys[$index]) EndIf Next ; ; ; Func GetKBList() Local $i For $i = 1 To 100 Local $subkey = RegEnumKey($keyroot, $i) If @error Then ExitLoop ; If key found, record it. If StringLeft($subkey, 2) == "KB" AND StringIsDigit(StringMid($subkey, 3, 6)) Then _ArrayAdd($akeys, $subkey) EndIf If StringLeft($subkey, 1) == "Q" AND StringIsDigit(StringMid($subkey, 2, 6)) Then _ArrayAdd($akeys, $subkey) EndIf Next EndFunc Func CleanKB($kbname) Local $dirname = "" $dirname = GetDir(RegRead($keyroot & "\" & $kbname, $keyname)) If $dirname <> "" AND FileExists($dirname) Then If MsgQuestion($header & $version, "Delete " & $dirname & " ?") = 1 Then If DirRemove($dirname, 1) Then RegDelete($keyroot & "\" & $kbname) EndIf EndIf EndIf EndFunc ;"C:\WINNT\xxx\spuninst\spuninst.exe" Func GetDir($fullpath) Local $res = "" Local $pos $pos = StringInStr($fullpath, "\", 0, 3) If $pos > 10 Then $res = StringLeft($fullpath, $pos) If StringInStr($res, " ") > 1 Then $res = "" EndIf Else $res = "" EndIf Return $res EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now