Jump to content
Sign in to follow this  
jsmall

Script spawns itself over and over on x64

Recommended Posts

jsmall

I am having trouble with the following script running on x64 based machines. It runs fine on x86. On x64 machines when I run the script (named drivedefrag.exe) it seems to get stuck in a loop of sorts where it basically spawns the drivedefrag.exe script over and over and over. The only way to stop it seems to be rebooting the computer as the drivedefrag.exe script process launches itself hundreds of times within seconds. I am not sure why it does this. I have tried compiling the script in x64 format without any change in behavior. I have narrowed it down to the shellexecutewait line of code that seems to be the issue. I tried changing the line of code to use the RunWait command calling the c:\windows\system32\defrag.exe explicitly but that seems to have the same behavior. I have tried specifying the drive letter to be defragged rather than using the For/In loop and still same behavior. I am stumped. Any help is greatly appreciated.

$systemdrive = EnvGet ("SystemDrive")
$fixeddrives = DriveGetDrive ("FIXED")
If NOT @error Then
       FOR $eachdrive IN $fixeddrives
    ShellExecuteWait ("defrag", $eachdrive, "","open",@SW_MAXIMIZE)
Next 
FileOpen ($systemdrive &"\temp\defrag.txt",2)
FileWrite ($systemdrive &"\temp\defrag.txt", "All drives have been defragged!")
FileClose ($systemdrive &"\temp\defrag.txt")
EndIf

Share this post


Link to post
Share on other sites
Xenobiologist

Are you sure, that you do not start any of your early script.exe version with the shellexecute command?

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
martin

I am having trouble with the following script running on x64 based machines. It runs fine on x86. On x64 machines when I run the script (named drivedefrag.exe) it seems to get stuck in a loop of sorts where it basically spawns the drivedefrag.exe script over and over and over. The only way to stop it seems to be rebooting the computer as the drivedefrag.exe script process launches itself hundreds of times within seconds. I am not sure why it does this. I have tried compiling the script in x64 format without any change in behavior. I have narrowed it down to the shellexecutewait line of code that seems to be the issue. I tried changing the line of code to use the RunWait command calling the c:\windows\system32\defrag.exe explicitly but that seems to have the same behavior. I have tried specifying the drive letter to be defragged rather than using the For/In loop and still same behavior. I am stumped. Any help is greatly appreciated.

$systemdrive = EnvGet ("SystemDrive")
$fixeddrives = DriveGetDrive ("FIXED")
If NOT @error Then
 FOR $eachdrive IN $fixeddrives
    ShellExecuteWait ("defrag", $eachdrive, "","open",@SW_MAXIMIZE)
Next 
FileOpen ($systemdrive &"\temp\defrag.txt",2)
FileWrite ($systemdrive &"\temp\defrag.txt", "All drives have been defragged!")
FileClose ($systemdrive &"\temp\defrag.txt")
EndIf

What does this produce?

$fixeddrives = DriveGetDrive ("FIXED")
If NOT @error Then
    FOR $iD = 1 to $fixeddrives[0]
         ConsoleWrite("Drive " & $iD " > " & $fixeddrives[$iD] & @CRLF)
Next

EndIf

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jsmall

Martin:

Thank you for your help. Here is the output that I receive. I am assuming that is not the output you were hoping for.

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\jsmall\Desktop\test.au3"

C:\Users\jsmall\Desktop\test.au3 (4) : ==> Error in expression.:

ConsoleWrite("Drive" & $iD " > " & $fixeddrives[$iD] & @CRLF)

ConsoleWrite(^ ERROR

>Exit code: 1 Time: 0.225

Share this post


Link to post
Share on other sites
BrettF

Martin screwed up :mellow:

Fixed... Learn to read the errors. They tell you the problem pretty much! :|

$fixeddrives = DriveGetDrive ("FIXED")
If NOT @error Then
    FOR $iD = 1 to $fixeddrives[0]
         ConsoleWrite("Drive " & $iD & " > " & $fixeddrives[$iD] & @CRLF)
Next

EndIf

Share this post


Link to post
Share on other sites
jsmall

Thanks BrettF. Here is the output that I received.

Drive 1 > c:

Drive 2 > d:

Share this post


Link to post
Share on other sites
martin

Thanks BrettF. Here is the output that I received.

Drive 1 > c:

Drive 2 > d:

Apologies for screwing up :mellow:

In that case what happens if you try

$fixeddrives = DriveGetDrive("FIXED")
If Not @error Then
    For $iD = 1 To $fixeddrives[0]
    ShellExecuteWait("defrag", $fixeddrives[$iD], "", "open", @SW_MAXIMIZE)

    ConsoleWrite("Defragged Drive " & $iD & " > " & $fixeddrives[$iD] & @CRLF)
    Next

EndIf

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jsmall

Martin,

That results in the same spawn loop. I did find that I can run my original script successfully by going to Start,Programs,AutoItv3,and then choose Run Script versus using the Run Script(x86). The Run Script option seems to run the script using native x64 and runs properly. However when I compile the script or try running it via SciTE it results in the spawn loop. When I compile the script which I have done several times using different methods I make sure to check the box to use x64 but it has no effect. Thank you again for your help. I truly appreciate it.

Share this post


Link to post
Share on other sites
martin

Martin,

That results in the same spawn loop. I did find that I can run my original script successfully by going to Start,Programs,AutoItv3,and then choose Run Script versus using the Run Script(x86). The Run Script option seems to run the script using native x64 and runs properly. However when I compile the script or try running it via SciTE it results in the spawn loop. When I compile the script which I have done several times using different methods I make sure to check the box to use x64 but it has no effect. Thank you again for your help. I truly appreciate it.

Well no need for the thanks since as far as I can see I had no useful effect at all :mellow:

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jsmall

I appreciate any help that comes my way...whether it solves the problem directly or just leads me down another train of thought. :mellow:

Any thoughts on how to get this script compiled in a format that will work properly?

Share this post


Link to post
Share on other sites
martin

I appreciate any help that comes my way...whether it solves the problem directly or just leads me down another train of thought. :mellow:

Any thoughts on how to get this script compiled in a format that will work properly?

I haven't got a 64 bit system so I can't even try to duplicate your problem. To me it sounds like a bug in AutoIt so the first thing to do is to examine the current bug reports in case this is already known about.

Then I would try a few other similar things. What happens if you use

ShellExecute("defrag.exe",$fixeddrives[$iD]);miss out the optional parameters

Try with some other app

ShellExecuteWait("Notepad.exe")

If you find that certain situations cause the same problem then start a new thread called somethng like "ShellExecuteWait bug on 64 bit os" with an example and ask if anyone can confirm. If they can then when you are confident post a bug report.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
kaotkbliss

one work-around to keep this from happening would be the use of singleton.......


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
BrettF
MHz

Testing with AutoIt 3.3.6.0 on Win7 64bit Laptop with 1 NTFS partition. I have no issues with the compiled 64bit script with the contents below.

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=DriveDefrag.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

If WinExists(@ScriptName & '_Interpreter') Then
    MsgBox(0, @ScriptName, 'Script Respawned')
    Exit 1
EndIf
AutoitWinSetTitle(@ScriptName & '_Interpreter')

$systemdrive = EnvGet ("SystemDrive")
$fixeddrives = DriveGetDrive ("FIXED")
If Not @error Then
    For $i = 1 To $fixeddrives[0]
        ShellExecuteWait('defrag', $fixeddrives[$i], @SystemDir)
;~      RunWait('"' & @SystemDir & '\defrag.exe" ' & $fixeddrives[$i], @SystemDir)
;~      RunWait('"' & @ComSpec & '" /c "' & @SystemDir & '\defrag.exe" ' & $fixeddrives[$i], @SystemDir)
    Next
    $handle_write = FileOpen ($systemdrive &"\temp\defrag.txt", 2)
    If $handle_write <> -1 Then
        FileWrite ($handle_write, "All drives have been defragged!" & @CRLF)
        FileClose ($handle_write)
    EndIf
EndIf

I tried the ShellExecuteWait() line and the 2 RunWait() lines on each test and all passed without issue. I did not try the For...In loop as I knew it was incorrect to use as to the first element being the drive count.

Also, notice I use a file handle for the log file for correct use.

Perhaps your AutoIt version is different? Perhaps you have another Defrag in the path which does the restart?

Share this post


Link to post
Share on other sites
Xenobiologist

You didn't by any chance name your script Defrag.au3, compiling it to Defrag.exe... did you?

:mellow:

See here : #781126

No answer :(


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
PsaltyDS

See here : #781126

No answer :(

I see now that you meant the same thing, but when I read that comment before I didn't understand what you were asking. Maybe it wasn't completely clear to the OP either.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
kaotkbliss

it basically spawns the drivedefrag.exe script over and over and over. The only way to stop it seems to be rebooting the computer as the drivedefrag.exe script process launches itself hundreds of times within seconds.

this is telling me that Run("script name here") is in a loop. the only way a script can have this kind of behavior that I can think of.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
jsmall

Yes as a matter of fact I did compile the script to defrag.exe which is exactly what was causing the loop. I actually discovered this yesterday but hadn't had a chance to follow up on my post and call myself out for being an idiot. :mellow: Thank you to everyone for their input and help along the way. It is truly appreciated.

Share this post


Link to post
Share on other sites
jsmall

Also one thing I found curious and a part of the reason I didn't suspect the self calling loop earlier is that this didn't occur on 32bit systems even though the script was named defrag.exe. This seems to only be an issue in 64bit OS. Any reason why that would be? Just curious.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.