Jump to content

FileClose Issue


Go to solution Solved by caramen,

Recommended Posts

               Case $Num_PC

                  Local $MyNum_PC = InputBox("Nump_PC", "Que voulez vous comme numéro de pc?"&@CRLF &"Pour Planitec 2.0")

                  Local Const $NumPCPath = "C:\windows\system32\Num_PC.reg"
                  _FileCreate ( $NumPCPath )
                  Local $hFileOpen = FileOpen($NumPCPath, $FO_APPEND)

                        If $hFileOpen = -1 Then
                              MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                        Return False
                        EndIf

                  FileOpen ($NumPCPath)

                  FileWriteLine($hFileOpen, "Windows Registry Editor Version 5.00")
                  FileWriteLine($hFileOpen, @CRLF)
                  FileWriteLine($hFileOpen, "[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]")
                  FileWriteLine($hFileOpen,@CRLF)
                  FileWriteLine($hFileOpen,'"NUM_PC"="'&$MyNum_PC&'"')

                  FileClose ($NumPCPath)

                  NumpRunDeletion ()

i got this case in my switch

I think if i understand good.... the "Case" keep the file open even if i do FileClose ($NumPCPath) until the "Case" is not ended

so i cant run the NumpRunDeletion () function properly becose i got a file usef error this is the commandprompt error message

(i see the file in my system32 and yes he is used becose i cant delet it while the script is running  )

E:\>C:\Windows\System32\cmd.exe /k C:\WINDOWS\System32\reg.exe Import Num_Pc.reg

ERROR: Error opening the file. There may be a disk or file system error.

missed to give you the fonction :

Func NumpRunDeletion ()
   ShellExecute (@ScriptDir & "\NUM-PC.bat")
   FileDelete ($NumPCPath)
EndFunc

the strange thing is shellexecute does not work

filedelete work... hmmmmmmmmmmm

 

I add this : if i close my script and try again  NumpRunDeletion () it s working

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

RE post with updated script : Still same issue the reg wont be imported and the file is deleted if i quit the script (ONLY if i run Func NumpRunDeletion () )

Case $Num_PCMake

                  Local $MyNum_PC = InputBox("Nump_PC", "Que voulez vous comme numéro de pc?"&@CRLF &"Pour Planitec 2.0")

                  Local Const $NumPCPath = "C:\windows\system32\Num_PC.reg"
                  _FileCreate ( $NumPCPath )
                  Local $hFileOpen = FileOpen($NumPCPath, $FO_APPEND)

                        If $hFileOpen = -1 Then
                              MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                        Return False
                        EndIf

                  FileOpen ($NumPCPath)

                  FileWriteLine($hFileOpen, "Windows Registry Editor Version 5.00")
                  FileWriteLine($hFileOpen, @CRLF)
                  FileWriteLine($hFileOpen, "[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]")
                  FileWriteLine($hFileOpen,@CRLF)
                  FileWriteLine($hFileOpen,'"NUM_PC"="'&$MyNum_PC&'"')

                  FileClose ($NumPCPath)

               Case $Num_PCRun

                  NumpcRunDeletion ()
Func NumpcRunDeletion ()
   FileClose ($NumPCPath)
   ShellExecute (@ScriptDir & "\NUM-PC.bat")
   FileDelete ($NumPCPath)
EndFunc

To clarify and make this simple

Case $Num_PCMake = Make a reg file

Case $Num_PCRun = Run the reg and delete it

If i run Case $Num_PCMake And Case $Num_PCRun It s not working (File in use)

If i only run $Num_PCMake Close the script and run $Num_PCRun It s working

how to solve that file close issue ... i tryed a lot of thing...

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Corrected the lines still same issue

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Developers

Corrected the lines still same issue

show the corrected code to see what else could be wrong.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution

i just found the solution and it was the correct code if i post full script it's 1800 lines

The solution is if i call file delete directly after the execute commande the file delete is lunched while the files is runned with a pause of 3000 ms this is now working

Func NumpcRunDeletion ()
   Local $NumPCPath = "C:\windows\system32\Num_PC.reg"
   ShellExecute (@ScriptDir & "\NUM-PC.bat")

   Sleep (3000)

   FileDelete ($NumPCPath)
EndFunc

i guess autoit dont get it becose of the batch file is out of autoit and then he cant figure this out

 

ShellExecuteWait can be a solution too i guess i am gonna try

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

working also with ShellExecuteWait thx all :) and without pause

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

better route for async:

Func NumpcRunDeletion ()
    FileClose ($NumPCPath)
    $iPid = ShellExecute (@ScriptDir & "\NUM-PC.bat")
    While ProcessExists($iPid)
        Sleep(10)
    WEnd
    FileDelete ($NumPCPath)
EndFunc

would probably want a max execution length as well

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...