Sign in to follow this  
Followers 0
i2i8

This is my script, it seems not perfect, can you help me write a more perfect example of it?

5 posts in this topic

#1 ·  Posted (edited)

This is my script, it seems not perfect, can you help me write a more perfect example of it?

#include <File.au3>
Local $setFiles[13]
$setFiles[0] = @ScriptDir & "\idsdk.dll"
$setFiles[1] = @ScriptDir & "\sdk.dll"
$setFiles[2] = @ScriptDir & "\ProcSafe.exe"
$setFiles[3] = @ScriptDir & "\Safe.dll"
$setFiles[4] = @ScriptDir & "\BHOEx.dll"
$setFiles[5] = @ScriptDir & "\CServer.dll"
$setFiles[6] = @ScriptDir & "\vDiskBus.inf"
$setFiles[7] = @ScriptDir & "\vDiskBus.sys"
$setFiles[8] = @ScriptDir & "\nti.exe"
$setFiles[9] = @ScriptDir & "\GdiPlus.dll"
$setFiles[10] = @ScriptDir & "\data\ClientBrand.ini"
$setFiles[11] = @ScriptDir & "\data\GameSearchCfg.ini"
$setFiles[12] = @ScriptDir & "\processSafe\ProcessSafe.ini"
For $i = 0 To UBound($setFiles) -1
    If FileExists($setFiles[$i]) Then
    FileDelete($setFiles[$i])
ElseIf Not FileExists($setFiles[$i]) Then
    _FileCreate($setFiles[$i])
    Sleep(200)
    FileSetAttrib($setFiles[$i],"+RSH")
EndIf
Next
Local $SetACL_Set = "SetACL -on ",$copy_permissions = ' -ot file -actn setprot -op "dacl:p_c;sacl:p_c"',$remove_permissions = ' -ot file -actn clear -clr "dacl,sacl"',$iRead_ex = ' -ot file -actn ace -ace "n:Everyone;p:read_ex"'
For $i = 0 To UBound($setFiles) -1
    If FileExists($setFiles[$i]) Then
    RunWait(@ComSpec & " /c " & $SetACL_Set & $setFiles[$i] & $copy_permissions,"",@SW_HIDE)
    RunWait(@ComSpec & " /c " & $SetACL_Set & $setFiles[$i] & $remove_permissions,"",@SW_HIDE)
    RunWait(@ComSpec & " /c " & $SetACL_Set & $setFiles[$i] & $iRead_ex,"",@SW_HIDE)
    EndIf
Next
MsgBox(0,"Waiting......","Waiting......",3)

Run this script there is a problem, the first run, does not create an empty file with the same name, run it again, it can create $ setFiles function definitions for all files.Why?

Edited by i2i8

Share this post


Link to post
Share on other sites



Hi,

In your first For loop :

If FileExists Then
    DeleteFile << The file exists and is deleted
ElseIf Not FileExists Then
    FileCreate << The file does NOT exist and is created
EndIf

The code cannot pass from an If to another one, so either the file exists or it does not.

#include <File.au3>
#include <Constants.au3>
 
Local $setFiles[13] = [ _
        "idsdk.dll", _
        "sdk.dll", _
        "ProcSafe.exe", _
        "Safe.dll", _
        "BHOEx.dll", _
        "CServer.dll", _
        "vDiskBus.inf", _
        "vDiskBus.sys", _
        "nti.exe", _
        "GdiPlus.dll", _
        "data\ClientBrand.ini", _
        "data\GameSearchCfg.ini", _
        "processSafe\ProcessSafe.ini"]
 
For $i = 0 To UBound($setFiles) - 1
    If FileExists(@ScriptDir & "\" & $setFiles[$i]) Then
        FileDelete(@ScriptDir & "\" & $setFiles[$i])
    EndIf
 
    ;the file is necessarily deleted
    _FileCreate(@ScriptDir & "\" & $setFiles[$i])
    ;Sleep(200) ;Why??
    FileSetAttrib(@ScriptDir & "\" & $setFiles[$i], "+RSH")
Next
 
Local $SetACL_Set = "SetACL -on"
Local $copy_permissions = '-ot file -actn setprot -op "dacl:p_c;sacl:p_c"'
Local $remove_permissions = '-ot file -actn clear -clr "dacl,sacl"'
Local $iRead_ex = '-ot file -actn ace -ace "n:Everyone;p:read_ex"'
 
For $i = 0 To UBound($setFiles) - 1
    If FileExists(@ScriptDir & "\" & $setFiles[$i]) Then ;this may be useless as the file is created before
        RunWait(@ComSpec & " /c " & $SetACL_Set & " " & @ScriptDir & "\" & $setFiles[$i] & " " & $copy_permissions, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & $SetACL_Set & " " & @ScriptDir & "\" & $setFiles[$i] & " " & $remove_permissions, "", @SW_HIDE)
        RunWait(@ComSpec & " /c " & $SetACL_Set & " " & @ScriptDir & "\" & $setFiles[$i] & " " & $iRead_ex, "", @SW_HIDE)
    EndIf
Next
 
MsgBox($MB_SYSTEMMODAL, "Waiting......", "Waiting......", 3)

Br, FireFox.

1 person likes this

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thank you very much FireFox, I will now try your script.

Share this post


Link to post
Share on other sites

i2i8,

you have already a thread for this issue. Why don't you stick with that?

title="View Topic">Function definition files can be deleted, but can not create the same file?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sorry,Water.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0