WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: wlodekd on October 12, 2015, 06:40:36 AM

Title: Restarting process
Post by: wlodekd on October 12, 2015, 06:40:36 AM
I am trying to restart process explorer.exe in order to restart taskbar. I am stopping process as below, but I had no luck to start it again.

Thank you for the help.

proclist=tlistproc()
;Get pointers to proc-name and proc-id
procptr=StrIndexNc(proclist,"explorer",1,@FWDSCAN)
if procptr==0 then exit

pipeptr=StrIndexNc(proclist,"|",procptr,@FWDSCAN)
tabptr=StrIndexNc(proclist,@tab,pipeptr,@FWDSCAN)
;handle if process is at end of string
if  tabptr == 0 then tabptr=strlen(proclist)
procname=StrSub(proclist,procptr,pipeptr-procptr)
procid=StrSub(proclist,pipeptr+1,tabptr-pipeptr)

if Procid!=""
   hProcess=tOpenProc(procid,3);PROCESS_TERMINATE
        if hProcess
           tKillProc(hProcess)
                tcloseproc(hProcess) 
           Message("tKillProc","%procname% is terminated")
        endif
else
  Message("tKillProc","Need a valid process id")
endif
Title: Re: Restarting process
Post by: td on October 12, 2015, 08:05:18 AM
Use one of the Run* functions or ShellExecute on the executable 'explorer.exe'.  Note that task bar notification area applications that launch from the 'Starup' folder will not restart when you restart the shell (explorer.exe.)   
Title: Re: Restarting process
Post by: wlodekd on October 12, 2015, 08:28:36 AM
I tried that. With that method taskbar is not present at all. Is there any other way to restart explorer as it would be started with "run" command from taskmanager menu?
Title: Re: Restarting process
Post by: td on October 12, 2015, 09:14:36 AM
It would have been helpful to mention what you had tried.  In this case I did a quick check using Windows 7 and a single line script using either the Run function or the ShellExecute function and both started the shell with the task bar (minus the Startup folder notification area applications but with notification area applications started by via other methods.)   
Code (winbatch) Select
Run("c:\windows\explorer.exe","")
It would appear that you are not actually starting the shell, so the next questions are which version of Windows are you attempting to restart the shell on and what is the UAC status and account type of the script your are using to start the shell?

Also, the 'taskmanager menu' 'run' calls the same kernel APIs used by the above WIL functions.
Title: Re: Restarting process
Post by: wlodekd on October 12, 2015, 11:07:54 AM
I apologize for not being more descriptive of my efforts. The only difference is that I was using Run("explorer.exe","").
I do not understand why Run("c:\windows\explorer.exe","") is resetting task manager bar as I was trying to achieve, but Run("explorer.exe","") is opening Libraries folder instead?

Can you please explain difference between Run("c:\windows\explorer.exe","") and Run("explorer.exe","")??

Thank you very much for your help

BTW, computer is WIN7 but I want to try this script on WIN10 as the taskbar is not auto-hiding after some time and had to be reset.
Title: Re: Restarting process
Post by: td on October 12, 2015, 02:48:43 PM
Quote from: wlodekd on October 12, 2015, 11:07:54 AM
Can you please explain difference between Run("c:\windows\explorer.exe","") and Run("explorer.exe","")??

It is caused by file redirection and how MSFT decided to handle 32-bit applications attempting to start Explorer.exe.  You will have to ask them the why.

That it is a file redirection problem is demonstrated by running the following with 32-bit WinBatch on a 64-bit system without the shell running.
Code (winbatch) Select

oldvalue = IntControl( 92, "disable", 0, 0, 0 )
Run("explorer.exe","")
IntControl( 92, "revert", oldvalue, 0, 0 )