Results 1 to 12 of 12

Thread: how to launch VB6 from the task scheduler and fix the I/O and memory priority?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    how to launch VB6 from the task scheduler and fix the I/O and memory priority?

    Quote Originally Posted by dilettante View Post
    Sounds like a new thread to me.

    I don't see how this is a VB6 problem though. If you must use low-spec machines and want snappy performance there are a few things you might do.

    Do not use SSD or eMMC "drives" use a real hard drive. Don't use 64-bit Windows if at all possible, it just wastes RAM and CPU cache giving nothing in return. Have an adequate amount of RAM, 4GB will be plenty. Turn off features your users will be denied access to anyway, for example indexing the drives (Indexing Service). Uninstall optional Windows components, etc.

    But as I said that's another thread, and one for General PC not here.
    You are right, it is not related to VB6, in win10 the things changed.

    By example, running an app ONLOGON using the task scheduler, while in win7, the app will start and shown just 1 or 2 seconds after the desktop is shown, in win10 can be delayed from 10 seconds, up to 5 minutes for the app to show up!.

    We don't know the cause, but are tested in PCs with 16GB of RAM, and comparing 64bits vs 64bits, the only thing that makes the difference is if it is HDD or SSD or ISCSI. We watch the task manager looking for the process, it appears BUT the used RAM size seems weird.

    if the EXE is 1.21MB how much it will use in RAM just after loading?, in this case it show it is using 700K hold that size in RAM like ten seconds and then start to grow up (as I thinks it starts to load up its skin textures ramp up to 12MB). But 10 seconds just in 700 K? that is smaller than the EXE file, 500K smaller.

    TEST2:

    Task scheduler runs it just after logon.

    Appear the desktop and I inmediately watched the proces in the task manager, 4 seconds to get to that window and be able to watch.

    It is a vb6 EXE of 1.21MB

    Just when I start to see, the process in RAM show it is using 630KB, then 720KB, hold that like 10 seconds, then go to 1MB , 1.4MB, and then ramp up to 12MB. Takes 20 up to 30 seconds to do that.

    Now, I though maybe my code is delayed somewhere. So I inserted a lot of GetTickCount in the form load. Numbers are related to the first GetTickCount.

    CP1= 0, CP2= 31, CP3= 125, CP4= 250, CP5= 265, CP6= 265, CP7= 265, CP8= 296, CP9= 296, CP10= 1093, CP11= 1125, CP12= 1125, CP13= 1156, CP14= 1156

    This mean that it ran all the formload code in 1.15 seconds what is usual when we just run the EXE manually. It take 800ms in loading up just the required part of the skin, that happens between check poing 9 and 10. So, no wast of time in my code. And if it loaded all those PNGs in 800ms (like 30 small PNGs means no problem in disk speed at that time).

    It is hard to believe that just it to be win10 instead win7 it takes 20 seconds in LOADING up the 1.21MB EXE FILE on logon!. And this is ISCSI virtual disk (not HDD), in average HDD it can take minutes!. Only in SSD can take the expected 5 or 6 seconds as it is win10 a bit heavier of services than win7. Time measure between the desktop appear up to the app appearing. I am puzzled.

    MORE:

    Just watched references and components, in components it is just the MMControl and the MSWinsck. In refferences is an activeX which is instantiated later on demand and some well known GDI lib.
    Last edited by flyguille; Sep 22nd, 2018 at 04:35 PM.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: Best way to communicate between two known vb6 apps?

    this is the problem of all my headaches.

    Code:
      <Settings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>false</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <IdleSettings>
          <Duration>PT10M</Duration>
          <WaitTimeout>PT1H</WaitTimeout>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>false</RunOnlyIfIdle>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
        <Priority>7</Priority>
      </Settings>
    that is how Task scheduler runs taks.... notice that Priority = 7!......!!!! and not place in the command line or interface to change that.! My EXE change it in the firsts lines, but it can happen 30 seconds for my VB6 code to run that.! So, that is the reason why just loading VB6 core takes up to 30 seconds in ISCSI solutiones. Because it has the lower priority and so, very sensitive to everything else happening.

    And it is not new, is very old thing.

    https://bdbits.wordpress.com/2010/04...cess-priority/
    Last edited by flyguille; Sep 22nd, 2018 at 05:22 PM.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: Best way to communicate between two known vb6 apps?

    Another damage that does the Task Scheduler, is everything running from it get also DISK I/O priority = LOW (seen with procesexplorer).

    Doesn't matter that I set the :

    Code:
                                Dim hThread As Long, hProcess As Long
                                If IsVirtualDiskMode Then
                                    hThread = GetCurrentThread
                                    hProcess = GetCurrentProcess
                                
                                    SetPriorityClass hProcess, NORMAL_PRIORITY_CLASS
                                    SetThreadPriority hThread, THREAD_PRIORITY_NORMAL
                                Else
                                    hThread = GetCurrentThread
                                    hProcess = GetCurrentProcess
                                    
                                    SetPriorityClass hProcess, HIGH_PRIORITY_CLASS
                                    SetThreadPriority hThread, THREAD_PRIORITY_HIGHEST
                                End If
    Any option, it will STIL has "LOW" as disk i/o priority, and that is all the sources of my problem. Anything loading in foreground will just freeze the activity of the app. Include if as *activity* is just a DIR() each 500ms. No priority it will be frozen by minutes. A complete dissaster.

    and why I used the task scheduler? because are the only one thing authorized to run AS ADMIN apps. If you want to run as admin from regular registry keys, seen in msconfig, the EXE never will appear, (unless there is another way than using a manifest for request run as admin, I can't use those more normal methods to launch it on logon).


    and this also didn't work

    Code:
                                If IsVirtualDiskMode Then
                                    hThread = GetCurrentThread
                                    hProcess = GetCurrentProcess
                                
                                    SetPriorityClass hProcess, PROCESS_MODE_BACKGROUND_START
                                    SetPriorityClass hProcess, PROCESS_MODE_BACKGROUND_END
                                    SetThreadPriority hThread, THREAD_MODE_BACKGROUND_START
                                    SetThreadPriority hThread, THREAD_MODE_BACKGROUND_END
                                    SetPriorityClass hProcess, NORMAL_PRIORITY_CLASS
                                    SetThreadPriority hThread, THREAD_PRIORITY_NORMAL
                                Else
                                    hThread = GetCurrentThread
                                    hProcess = GetCurrentProcess
                                    
                                    SetPriorityClass hProcess, PROCESS_MODE_BACKGROUND_START
                                    SetPriorityClass hProcess, PROCESS_MODE_BACKGROUND_END
                                    SetThreadPriority hThread, THREAD_MODE_BACKGROUND_START
                                    SetThreadPriority hThread, THREAD_MODE_BACKGROUND_END
                                    SetPriorityClass hProcess, HIGH_PRIORITY_CLASS
                                    SetThreadPriority hThread, THREAD_PRIORITY_HIGHEST
                                End If
    Last edited by flyguille; Sep 22nd, 2018 at 08:52 PM.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: Best way to communicate between two known vb6 apps?

    resuming the two last years!

    1) customers with network problem, sockets dropped due to output buffer being full , the infamous "this operation will block on non blocking socket" <---- source of the problem, now know, LOW I/O priority!, which allow it to be full (then if it care about _sendComplete is better).
    2) if fly a fly in the foreground, our app will freeeze, againn source of the problem , LOW I/O priority!. Simptoms , disconnections/reconnections, unresponsiveness.



    all the source, TASK SCHEDULER, don't run networking apps from the task scheduler!

    But if not alternative because you want it to get privileges elevation.

    The FIX (atleast monitoring it with ProcessExplorer):

    Code:
    Private Sub Form_Load()
    Dim hprocess As Long
    Dim value As Long
    Dim l As Long
    
    hprocess = GetCurrentProcess
    
    'Debug.Print Hex$(NtQueryInformationProcess(hprocess, 33, value, 4, l))
    
    ' Low I/O priority
    value = 1
    
    Debug.Print Hex$(NtSetInformationProcess(hprocess, 33, value, 4&))
    
    ' Normal I/O priority.
    value = 2
    Debug.Print NtSetInformationProcess(hprocess, 33, value, 4&)
    
    
    End Sub


    Code:
    Public Declare Function NtSetInformationProcess Lib "ntdll.dll" (ByVal hprocess As Long, ByVal ProcessInformationClass As Long, ByRef pInformation As Long, ByVal InformationSize As Long) As Long
    
    Public Declare Function NtQueryInformationProcess Lib "ntdll.dll" (ByVal hprocess As Long, ByVal ProcessInformationClass As Long, ByRef pInformation As Long, ByVal InformationSize As Long, ByRef ReturnedSize As Long) As Long
    
    Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
    And.... touché

    Now to test it in the war field!.
    Last edited by flyguille; Sep 23rd, 2018 at 07:46 AM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: Best way to communicate between two known vb6 apps?

    ntSetInformationProcess is undocumented.

    But

    this was documented 10 days ago https://docs.microsoft.com/en-us/win...essinformation

    SetInformationProcess almost the same.

    Required to fix the "Memory Priority" , the Task scheduler left it in = 2. MEMORY_PRIORITY_LOW = 2.


    So, basically.

    Fixing the time priority of the process, then the thread, then the I/O priority, then the memory priority (this last one to avoid to be sweep by the paging file that is looking for things to page if inactivity is detected, when lower priority more targetted is the app (maybe it consider as *inactivity* a smaller period if it is lower priority).

    Code:
    Value = 5
    hres = NtSetInformationProcess(hProcess, 39, Value, 4&)
    And that last code is for restore the memory priority, 5 = normal..., task scheduler set it to 2 = LOW.

    But, only can load up the main program after setting that, so better do a little VB program to set that all up, and then it run the main EXE. Otherwise, memory pages already loaded area already marked as low.
    Last edited by flyguille; Sep 23rd, 2018 at 09:29 AM.

  6. #6
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,156

    Re: Best way to communicate between two known vb6 apps?

    https://blogs.msdn.microsoft.com/old...02-00/?p=93395
    https://blogs.msdn.microsoft.com/old...817-00/?p=9883

    "There have been a variety of approaches taken to mitigate the impact of auto-start programs. One trick was to run auto-start programs in a box that keeps them at low CPU and disk priority for 60 seconds."

    cheers,
    </wqw>

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: Best way to communicate between two known vb6 apps?

    Quote Originally Posted by wqweto View Post
    https://blogs.msdn.microsoft.com/old...02-00/?p=93395
    https://blogs.msdn.microsoft.com/old...817-00/?p=9883

    "There have been a variety of approaches taken to mitigate the impact of auto-start programs. One trick was to run auto-start programs in a box that keeps them at low CPU and disk priority for 60 seconds."

    cheers,
    </wqw>
    In this case was the intention to launch it with normal privilege, but from the task scheduler, for allow it to run as admin (elevation). And lock the desktop, screen, partially the keyboard as soon as possible, as it is its job.

    Other case, like running it from Run Key, Start programs menu, etc, it will two things.

    1) if the app is manifested for requesting RUN AS ADMIN ( aka elevation), the app won't be run.
    2) if the app EXE is not manifested, it will run as the user account without elevation, but if this program order to RUN another app which is manifested, the shell instruction will FAIL. (an non elevated can't run elevation).

    my knowledge about the topic, the only thing which can run automatically on logon and elevated is the task scheduler AND at the same time be able to INSTALL automatically, there is other way but IIRC the installer needs to know the credentials, which approach never investigated in deep by that reason.



    So, running with low I/O priorities, a simple 20K VB6 just the bare minimun (3 lines of code), in windows 10 booting from ISCSI or 1TB HDD (the average), just loading the VB6 runtime and the 20K exe files, will take 10 seconds!, measured from the desktop appearing up to the first line of VB6 is run.

    This is in the original Microsoft win10 1803, with all its junk tasks.

    now, the first 3 lines of VB6 what do, NORMALIZE priorities, and after that it just needs one second for loading up 1.21MB main exe and be able it to show the initial form.

    Now, get a pirate win10 naked of all the background taks, it will do all in 2 seconds, similar to what win7 was able to do on the same hardware.
    Last edited by flyguille; Sep 25th, 2018 at 01:10 PM.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: how to launch VB6 from the task scheduler and fix the I/O and memory priority?

    Task Scheduler is for batch jobs which shouldn't get higher priority than user-initiated interactive tasks. Screwing around trying to auto-run things elevated is always going to fight the headwinds of attempts to make Windows more secure.

    Maybe you want Configure kiosks and digital signs on Windows desktop editions instead?

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: how to launch VB6 from the task scheduler and fix the I/O and memory priority?

    Quote Originally Posted by dilettante View Post
    Task Scheduler is for batch jobs which shouldn't get higher priority than user-initiated interactive tasks. Screwing around trying to auto-run things elevated is always going to fight the headwinds of attempts to make Windows more secure.

    Maybe you want Configure kiosks and digital signs on Windows desktop editions instead?
    I thinks traditional kiosk just reemplace the explorer.exe shell key (since win 2000), by its own app. This doesn't seem to be the same thing. But looks interesting, it is a win10 thing only or also is present in win7?

  10. #10
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: how to launch VB6 from the task scheduler and fix the I/O and memory priority?

    Quote Originally Posted by flyguille
    that is how Task scheduler runs taks.... notice that Priority = 7!......!!!! and not place in the command line or interface to change that.!
    ...
    https://bdbits.wordpress.com/2010/04...cess-priority/
    That is because you (and article author) are doing it in incorrect way.
    By direct editing XML file you damage its signature. You can prove it yourself even in Win7 by opening "taskschd.msc" snap-in that will say to you that the task is damaged.
    Never edit it directly. Use appropriate interface.

    You need value 4 to make CPU, I/O, and page priority be a Normal when app started from the task:

    Code:
    pSettings.Priority = 4
    See example of code here: http://www.vbforums.com/showthread.p...Task-Scheduler
    (tested on Win10, 1803)

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    894

    Re: how to launch VB6 from the task scheduler and fix the I/O and memory priority?

    Quote Originally Posted by Dragokas View Post
    That is because you (and article author) are doing it in incorrect way.
    By direct editing XML file you damage its signature. You can prove it yourself even in Win7 by opening "taskschd.msc" snap-in that will say to you that the task is damaged.
    Never edit it directly. Use appropriate interface.

    You need value 4 to make CPU, I/O, and page priority be a Normal when app started from the task:

    Code:
    pSettings.Priority = 4
    See example of code here: http://www.vbforums.com/showthread.p...Task-Scheduler
    (tested on Win10, 1803)
    we avoid that solution because it require major work to automate the XML export file, like, order to export, modify , import. But it is a possibility, there is no way in the command line to set the priority. or in the interface.

  12. #12
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: how to launch VB6 from the task scheduler and fix the I/O and memory priority?

    we avoid that solution because it require major work to automate the XML export file, like, order to export, modify , import.
    What? Why do you need XML export/import? Is it something like Domain Controller?
    Do you have rights to execute arbitary program on destination PCs with admin. permissions? So, why don't you can execute ITaskScheduler interface methods there?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width