Jump to content
Natulux

Script takes ages on startup

Recommended Posts

Hey Surya,

no need to apologize, I'm happy that you are helping me! :-)

I tried your code but unfortunately nothing happened.
After changing
 

$fini = "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini"

to
 

$fini = "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts1.ini"

I got confused. It didn't even create the nonexistent scripts1.ini. I just updated AutoIt to the newest version 3.3.14.1, maybe there's a difference?
The help file claimed: "If the file does not already exist, it is created so long as the directory exists.", but it doesn't!

Not sure what I'm missing.

Greets
Natulux

Share this post


Link to post
Share on other sites

natulux just copy down the whole script and runn it in scite then open cmd and type what i said earlier. do not edit anything .The code works fine for me.Can you please do what i said and post me the results


No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Share this post


Link to post
Share on other sites

Sure, here you go:

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:\Programmierung\MyProjects\AutoIt\ATOSS_FavMan\FavManStartup.au3" /UserParams    
+>17:21:58 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\MKramer\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\MKramer\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.1)  from:C:\Program Files (x86)\AutoIt3  input:D:\Programmierung\MyProjects\AutoIt\ATOSS_FavMan\FavManStartup.au3
+>17:21:58 AU3Check ended.rc:0
>Running:(3.3.14.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Programmierung\MyProjects\AutoIt\ATOSS_FavMan\FavManStartup.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>17:22:00 AutoIt3.exe ended.rc:0
+>17:22:00 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.479

"FavManStartup.au3" is the .au3 file with your code without any changes. You can see the results of the debugger console above.
I can't see, why it wouldn't do something...

Script.ini is empty.

Regards
Natulux

EDIT: I added admin rights, to be sure. Didn't help:
 

#RequireAdmin
If IsAdmin() Then MsgBox($MB_SYSTEMMODAL, "", "The script is running with admin rights.")

 

Edited by Natulux

Share this post


Link to post
Share on other sites

then i would cut short the code simply to its bones here it is:

#requireadmin
$fini = "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini"
IniWrite($fini,"Startup","0CmdLine","E:\FavMan_AktuellesRelease\ATOSS-FavoritenManager.exe")
IniWrite($fini,"Startup","0Parameters","")

This would write the script.ini after running this code check wether the script.ini is empty


No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Share this post


Link to post
Share on other sites

Yes, I will try that tomorrow.
There must be a reason, why IniWrite() resisted my efforts though. I will tell you, if I succeed.

Natulux

Share this post


Link to post
Share on other sites

Well according do the console output you posted you are running x86 AutoIt on x64 Windows, that means you would be opening the file in WysWOW64 not System32.

File System Redirector

Either make sure you are using x64 with #AutoIt3Wrapper_UseX64=y or work around it with \Sysnative folder. You probably shouldn't mess around with Wow64DisableWow64FsRedirection() if you don't know what you're doing.

Share this post


Link to post
Share on other sites

Hello AdmiralAlkex,

I'm not sure if I understand that. I mean, how does x86 AutoIt influence, where the ini file should be edited, when I give a full path?
 

$fini = "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini"
IniWrite($fini,"Startup","0CmdLine","E:\FavMan_AktuellesRelease\ATOSS-FavoritenManager.exe")

Nevertheless,
 

C:\Windows\SysWOW64\GroupPolicy

is empty and that would explain, why IniWrite() doesn't like to create a file.

When I am adding my script to the Group Policy by hand, my OS adds an entry to the
 

C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini

though.

Surya, even the plain code you gave me doesn't work. The ini file stays empty. I sense that IniWrite() has some kind of problem...

Kind regards,
Natulux
 

Share this post


Link to post
Share on other sites

Hello AdmiralAlkex,

I'm not sure if I understand that. I mean, how does x86 AutoIt influence, where the ini file should be edited, when I give a full path?

Because x86 apps are redirected to the x86 System folder and vice versa. See the link in my previous post.

Share this post


Link to post
Share on other sites

Hello again AdmiralAlkex,

I'm very sorry and you are right. I should have checked that link first.
My command really is redirected to
 

C:\Windows\SysWOW64\GroupPolicy\Machine\Scripts

and the scripts.ini now correctly displays

[Startup]
0CmdLine=E:\FavMan_AktuellesRelease\ATOSS-FavoritenManager.exe
0Parameters=

with either of Suryas samples.

When using

#AutoIt3Wrapper_UseX64=y

as suggested, I really am able to write to system32 though.

I guess I'm happy now! :-)
Thank you both, I've learned quite a lot here.

Yours sincerely
Natulux

Share this post


Link to post
Share on other sites

At last here is the (slightly edited) code I used with success:

#RequireAdmin
#AutoIt3Wrapper_UseX64=y

#include <Array.au3>
#include <String.au3>

Local Const $GOP_SHUTDOWN = False
Local Const $GOP_STARTUP = True
;the first parameter defines to start the script when in startup or shutdown
;second parameter is the file and third is its parameters
;------------


_RegisterGOP($GOP_STARTUP,"E:\FavMan_AktuellesRelease\ATOSS-FavoritenManager.exe")
RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "ATOSS-FavoritenManager", "REG_SZ", @ScriptFullPath)

Func _RegisterGOP($varx, $file, $param = "")
    Local $nLast, $nNum, $fIni
    Local $strScriptname = "ATOSS-FavoritenManager.exe"
    $fIni = "C:\Windows\System32\GroupPolicy\Machine\Scripts\scripts.ini"
    If FileExists($fIni) Then
        If $varx = $GOP_STARTUP Then
            $ini = IniReadSection($fIni, "Startup")
            If @error Then
                Local $ini[1][1]
                $ini[0][0] = -1
            EndIf
        ElseIf $varx = $GOP_SHUTDOWN Then
            $ini = IniReadSection($fIni, "Shutdown")
            If @error Then
                Local $ini[1][1]
                $ini[0][0] = -1
            EndIf
        EndIf
        For $i = 1 To UBound($ini) - 1
            If StringInStr($ini[$i][2],$strScriptname) Then
                $nNum = $i
            EndIf
        Next

        If Not $nNum Then
            $nLast = UBound($ini) - 1
            $nNum = _StringBetween($ini[$nLast][0], "", "P")
            If @error Then Local $nNum[1] = [-1]
            $nNum = $nNum[0] + 1
        EndIf

        If $varx = $GOP_STARTUP Then
            IniWrite($fIni, "Startup", $nNum & "CmdLine", $file)
            IniWrite($fIni, "Startup", $nNum & "Parameters", $param)
        ElseIf $varx = $GOP_SHUTDOWN Then
            IniWrite($fIni, "Shutdown", $nNum & "CmdLine", $file)
            IniWrite($fIni, "Shutdown", $nNum & "Parameters", $param)
        EndIf
    Else
        If $varx = $GOP_STARTUP Then
            IniWrite($fIni, "Startup", "0CmdLine", $file)
            IniWrite($fIni, "Startup", "0Parameters", $param)
        ElseIf $varx = $GOP_SHUTDOWN Then
            IniWrite($fIni, "Shutdown", "0CmdLine", $file)
            IniWrite($fIni, "Shutdown", "0Parameters", $param)
        EndIf
    EndIf
    Return "Success"
EndFunc   ;==>_RegisterGOP

I added a Regestry startup entry with a link to my script and a routine to check, if my script has already been added to the ini file.

Have a great time
Natulux

Edited by Natulux

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

  • Similar Content

    • By Simpel
      Hi,
      after I recognized that some of my scripts fail if they are at windows startup I researched for a solution. Problem could be fixed if I wait about 120 seconds after login. So how to measure this?
      #include-once #include <AD.au3> #include <Date.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SecondsAfterLogin ; Description ...: Returns how many seconds are gone since last login ; Syntax ........: _SecondsAfterLogin() ; Parameters ....: None ; Return values .: Success - Integer of seconds ; Failure - 0, sets @error to 1 ; Author ........: Conrad Zelck ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _SecondsAfterLogin() Local $sDate Local $iSec $sDate = __GetLogonTime() ; UTC If @error Then $sDate = __GetLogonTime_AD() ; local time If @error Then Return SetError(1, 0, 0) Else $sDate = __LocalTime($sDate) ; UTC to local time EndIf $iSec = __TimeDifference($sDate) Return $iSec EndFunc #region - INTERNAL_USE_ONLY Func __GetLogonTime($sUserName = @UserName, $sComputerName = @ComputerName) ; Idea by trancexx: http://www.autoitscript.com/forum/topic/113611-if-isadmin-not-detected-as-admin/ Local $aRet = DllCall("netapi32.dll", "long", "NetUserGetInfo", "wstr", $sComputerName, "wstr", $sUserName, "dword", 11, "ptr*", 0) If @error Or $aRet[0] Then Return SetError(1, 0, 0) Local $sSeconds = DllStructGetData(DllStructCreate("ptr;ptr;ptr;ptr;dword;dword;dword;ptr;ptr;dword;dword;dword;dword;ptr;dword;ptr;dword;dword;byte;dword", $aRet[4]), 10) DllCall("netapi32.dll", "long", "NetApiBufferFree", "ptr", $aRet[4]) Local $sLastLogon = _DateAdd('s', Number($sSeconds), "1970/01/01 00:00:00") Return $sLastLogon EndFunc Func __GetLogonTime_AD() Local $iSuccess = _AD_Open() If $iSuccess = 1 Then Local $sDate = _AD_GetLastLoginDate() $sDate = __NumberDate_StringDate($sDate) _AD_Close() Return $sDate Else Return SetError(1, 0, 0) EndIf EndFunc Func __NumberDate_StringDate($sDate) Local $y, $m, $d, $h, $min, $s $y = StringMid($sDate,1, 4) $m = StringMid($sDate,5, 2) $d = StringMid($sDate,7, 2) $h = StringMid($sDate,9, 2) $min = StringMid($sDate,11, 2) $s = StringMid($sDate,13, 2) $sDate = $y & "/" & $m & "/" & $d & " " & $h & ":" & $min & ":" & $s Return $sDate EndFunc Func __LocalTime($sDate) Local $iTimeZoneOffset Local $aTimeZone = _Date_Time_GetTimeZoneInformation() If $aTimeZone[0] <> 2 Then $iTimeZoneOffset = ($aTimeZone[1]) * -1 Else $iTimeZoneOffset = ($aTimeZone[1] + $aTimeZone[7]) * -1 EndIf $iTimeZoneOffset /= 60 ; in hours Local $sHour = StringMid($sDate, 12, 2) $sHour += $iTimeZoneOffset $sDate = StringLeft($sDate, 11) & $sHour & StringRight($sDate, 6) Return $sDate EndFunc Func __TimeDifference($sDate) Local $sNow = _NowCalc() Local $sDiff = _DateDiff("s", $sDate, $sNow) Local $iDiff = Number($sDiff) Return $iDiff EndFunc #endregion - INTERNAL_USE_ONLY I had to look what kind of login it is. Some of my computers are logging in with active directory and other not.
      Here is an example:
      #include <SecondsAfterLogin.au3> Local $iSec = _SecondsAfterLogin() MsgBox(0, '', "Time since last login: " & _HHMMSS($iSec, "s")) Exit Func _HHMMSS($iTime, $sType = "ms") If $sType = "s" Then Local $sHHMMSS = StringFormat("%.2d:%.2d:%.2d", (Floor($iTime / 3600)), (Floor(Mod($iTime,3600) / 60)), (Mod(Mod($iTime,3600),60))) Else Local $sHHMMSS = StringFormat("%.2d:%.2d:%.2d", (Floor($iTime / 3600000)), (Floor(Mod($iTime,3600000) / 60000)), (Mod(Mod($iTime,3600000),60000) / 1000)) EndIf Return $sHHMMSS EndFunc I hope someone find it useful.
      Regards, Conrad
      P.S. Review is welcome.
    • By spuuunit
      I have a script that autostart with Windows, and sometimes some of my code is skipped. My script takes long pauses, so it's not that the script "goes too fast". This is my script for now:
      TraySetIcon("C:\Portables\AutoIt\_\icon.ico") AutoItSetOption("WinTitleMatchMode", 2) Run("C:\Portables\Key Manager\keymanager.exe") WinActivate("ATNSOFT Key Manager v") WinWaitActive("ATNSOFT Key Manager v") WinMove("ATNSOFT Key Manager v", "", 650, 200, 600, 800) Sleep(500) $pos = MouseGetPos() MouseClick("left", 1220, 210, 1, 100) MouseMove($pos[0], $pos[1], 100) Run("C:\Portables\foobar2000\foobar2000.exe") $version = 298 For $i = 0 To 99 Step 1 $path = "C:\Users\spunit\AppData\Local\Discord\app-0.0." & $version + $i & "\Discord.exe" If FileExists($path) Then Run($path) ExitLoop EndIf Next Run("C:\Portables\Firefox\FirefoxPortable.exe") Sleep(10000) WinMove("- Mozilla Firefox", "", 205, 0, 1214, 1047) Sleep(100) MouseClick("left", 1300, 15, 1, 10) Sleep(100) MouseClick("left", 1130, 275, 1, 10) Sleep(100) MouseClick("left", 930, 105, 1, 10) Sleep(100) Send("#{m}") Sometimes it skips to click and move mouse right after Key Manager starts. Almost always it skips everything after the last run.

      This type of script were never an issue with Windows 7... Any thoughts?
    • By LOWLIFE
      This is a personal project to log into several facebook accounts and send a message to a specific person on their birthday. I need to stop a script in a few different ways for several different reasons. For example, it might start sending the email to the wrong account, it might do something other than send a message, it might fail to logout of one account, etc. 
      1) Pause the script at it's exact location with a resume feature in case I need to put it on hold while I do another task. 
      2) Pause the script at it's current location with the option to start over or execute another part of the script (example in GUI with multiple buttons). 
      Also, is there a way to interact with menus? If I log into facebook how can I force it to go straight to sending a message to the proper person? I tried automating a mouseclick but the window opens in different places. I also tried searching for specific text and I couldn't get any information from the windows info tool on the facebook page. 
      Also, how do I get my code in here to show like it does in my editor? (scite)
      Thanks for looking at it, and any help/suggestions I sgreatly appreciated!
      <snip>
    • By Simpel
      Hi,
      I do recognize bad behaviour at this snippet:
      #include <AutoItConstants.au3> Global $g_sSD = @ScriptDir & "\" Global $g_sBurstPath = $g_sSD & "Burst\" DirCreate($g_sBurstPath) Local $sFileName = "Test_mit_3_Seiten.pdf" ; any PDF with more than 1 page inside @ScriptDir FileCopy($g_sSD & $sFileName, $g_sBurstPath & $sFileName, 1) ;~ Sleep(13000) Local $hTimer = TimerInit() ConsoleWrite("Start" & @CRLF) _Burst($g_sBurstPath & $sFileName) ; bursts PDF into single pages ;~ While _FileInUse($g_sBurstPath & $sFileName) ;~ WEnd ConsoleWrite("End: " & Round(TimerDiff($hTimer)) & "ms" & @CRLF) Exit Func _quotePath($sPath) ; because of possible "spaces" inside pathes $sPath = '"' & $sPath & '"' Return $sPath EndFunc Func _Burst($sFile) Local $sPDFtk = $g_sSD & "pdftk.exe" ; path to pdftk.exe (and libiconv2.dll) Local $sCurrWorkingDir = @WorkingDir FileChangeDir($g_sBurstPath) ; it has to change for reasons Local $iPID = Run(_quotePath($sPDFtk) & ' ' & _quotePath($sFile) & ' burst', "", @SW_SHOW, $STDOUT_CHILD + $STDERR_CHILD) ; @SW_SHOW just to see "PDFtk is working" Local $sOutput, $sError While 1 $sOutput &= StdoutRead($iPID) $sError &= StderrRead($iPID) If @error Then ExitLoop Sleep(10) WEnd FileChangeDir($sCurrWorkingDir) ; back to normal EndFunc Func _FileInUse($sFilename) ; by Siao Local $aRet, $hFile $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", 0x80000000, _ ;dwDesiredAccess = GENERIC_READ "dword", 0, _ ;dwShareMode = DO NOT SHARE "dword", 0, _ ;lpSecurityAttributes = NULL "dword", 3, _ ;dwCreationDisposition = OPEN_EXISTING "dword", 128, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") SetError($aRet[0]) Return 1 ; file in use (@error contains system error code) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return 0 ; file not in use EndIf EndFunc This bursting took about 15000ms. If I activate line 8 "Sleep(13000)" then the bursting itself never needed more than 1000ms. Round about 13000ms delay is needed until bursting is acting very fast, otherwise needing about 15000ms.
      Then I tested _FileInUse() instead of _Burst() w/o Sleep(13000). This runs in 3ms. It seemes to me that FileCopy() and Burst() are interacting in a way I can't see.
      Any ideas? Regards, Conrad
      P.S. You need pdftk.exe and libiconv2.dll at @ScriptDir. This you can get free here: https://www.pdflabs.com/tools/pdftk-server/ (I'm not sure whether I'm allowed to attach it here).
       
    • By computergroove
      I am trying to start my script on Windows startup and it doesn't run. I have disabled defender and smartscreen with no luck. There is no antivirus on this machine. I have added the script to shell:startup, shell:common startup and HKLM\Software\Microsoft\Windows\Current Version\Run all with no luck. Im at a loss. Please help.
×
×
  • Create New...