Reboot EXPLORER

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Reboot EXPLORER

Post by Kwai chang caine »

Hello at all :D

I search to reboot the explorer
So i have not found anothe way that kill it and run it after a delay
But unfortunately, that create strange behavior :shock:
Sometime, that crash the debugger, sometime that not run the explorer, etc ... even if i give a long delay :cry:

If someone have an anti-crash idea..... :wink:

Code: Select all

Procedure.l KillProcess(sfilename.s) ; ATTENTION casse sensible
 
 Protected snap.l
 Protected uProcess.PROCESSENTRY32
 Protected lkernel32.l
 Define phandle.i
 Define result.b = #False
  
 sfilename = GetFilePart(sfilename)
 lkernel32 = OpenLibrary (#PB_Any, "kernel32.dll")
 
 If lkernel32
 
  snap = CreateToolhelp32Snapshot_($2, $0)
 
  If snap <> 0
 
   uProcess\dwSize = SizeOf(PROCESSENTRY32)
 
   If CallFunction (lkernel32, "Process32First", snap, @uProcess)
 
    While CallFunction (lkernel32, "Process32Next", snap, @uProcess)
 
     If PeekS(@uProcess\szExeFile) = sfilename
      CloseHandle_(snap)
      CloseLibrary(lkernel32)
      Break
     EndIf
     
    Wend
    
   EndIf
   
   CloseHandle_(snap)
   
  EndIf
  
  CloseLibrary(lkernel32)
  
 EndIf
 
 If uProcess\th32ProcessID
  
  phandle = OpenProcess_($1, #False, uProcess\th32ProcessID)
  
  If phandle <> #Null
  
   If TerminateProcess_(phandle, 1)
    result = #True
   EndIf
  
   CloseHandle_(phandle)
  
  EndIf 
  
  ProcedureReturn result
  
 EndIf
 
EndProcedure

If KillProcess("explorer.exe")
 Delay(1000)
 RunProgram("explorer.exe")
 
 Delay(10000)
 End
EndIf
Have a good day
ImageThe happiness is a road...
Not a destination
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Reboot EXPLORER

Post by RSBasic »

KillProcess() is never a good idea.
You can close the window:

Code: Select all

EnableExplicit

Define Handle

Handle = FindWindow_("Progman", 0)

PostMessage_(Handle, #WM_QUIT, 0, 0)
Image
Image
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Reboot EXPLORER

Post by fryquez »

Yes, you can request explorer to close. Here's what I use for.
A delay of 1 second should be more than enough, if you want to restart it.

Code: Select all

Procedure CloseExplorer()
  
  Protected os.OSVERSIONINFOEX, hwnd, hwndxp
  
  os\dwOSVersionInfoSize = SizeOf(OSVERSIONINFOEX)
  GetVersionEx_(os)
  
  hwnd = FindWindow_("Shell_TrayWnd", 0)
  If hwnd
    
    
    If os\dwBuildNumber >= 6000 
      PostMessage_(hwnd, 1460, 0, 0)      
    Else
      hwndxp = FindWindow_("Progman", 0)
      PostMessage_(hwndxp, #WM_QUIT, 0, 0)
      PostMessage_(hwnd, #WM_QUIT, 0, 0)
    EndIf
    
  EndIf
  
EndProcedure

CloseExplorer()
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Reboot EXPLORER

Post by Dude »

Closing or killing "explorer.exe" is dangerous because sometimes it simply won't restart again. It's a risk you take. I had to remove that from one of my products because too many support requests were coming in saying that I broke their PC and that they had to reboot. I wouldn't use it unless for in-house purposes only (not for others).
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Reboot EXPLORER

Post by Thunder93 »

RSBasic is right, not a good idea to brute-force explorer.exe to close like taskkill or TerminateProcess. One reason why it isn't good idea because changes in the previous explorer session are only saved during a clean shutdown.

The suggested methods for gracefully closing explorer would be of an issue if you need to perform several tasks and explorer shell automatically restarted fairly quickly because of AutoRestartShell registry entry with default parameter set to automatically restart.

You would have to edit this registry entry before closing explorer, and afterwards ensure you undo registry changes. Therefore, keeping in mind with everything said, using Windows Restart Manager: https://msdn.microsoft.com/en-us/librar ... s.85).aspx would be the way to go.

Anyways closing explorer should only be necessary if you making installer and closing explorer and restarting it to show changes instead of a system restart.
Last edited by Thunder93 on Wed Apr 27, 2016 1:33 pm, edited 1 time in total.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Reboot EXPLORER

Post by Dude »

Thunder93 wrote:explorer shell automatically restarted fair quickly because of AutoRestartShell registry entry
In theory: yes. In reality: nope! I've had extensive tests of this where AutoRestartShell fails for myself and my users, even when we're logged in with admin rights (which is needed to edit this registry entry). You simply CAN'T rely on this to restart explorer.exe for you. Trust me. It WILL bite you in the ass.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Reboot EXPLORER

Post by Thunder93 »

You've missed the bigger picture. However anyways, throughout the many years with various Windows. Explorer Shell always re-launches itself... from my observations. People with issues usually those whom with security software far to restrictive and prevents explorer shell from relaunching. Registry corruption, or incorrect permissions set, or AutoRestartShell entry has been disabled. :wink:
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Reboot EXPLORER

Post by Thunder93 »

@Kwai chang caine: Alright, so using Restart Manager, would be something like... :wink:

Code: Select all

IncludeFile "Process_Set.pbi"
#RmRebootReasonNone = 0
#RmForceShutdown = 1

#RM_SESSION_KEY_LEN = SizeOf(GUID)
#CCH_RM_SESSION_KEY = #RM_SESSION_KEY_LEN * 2
#CCH_RM_MAX_APP_NAME = 255
#CCH_RM_MAX_SVC_NAME = 63

Structure RM_PROCESS_INFO
  Process.RM_UNIQUE_PROCESS
  strAppName.w[#CCH_RM_MAX_APP_NAME+1]
  strServiceShortName.w[#CCH_RM_MAX_SVC_NAME+1]
  ApplicationType.l ;RM_APP_TYPE
  AppStatus.l
  TSSessionId.l
  bRestartable.l
EndStructure

Prototype.l RmEndSession(dwSessionHandle.l)
Prototype.l RmGetList(dwSessionHandle.l, *pnProcInfoNeeded, *pnProcInfo, rgAffectedApps, lpdwRebootReasons.l)
Prototype.l RmRegisterResources(dwSessionHandle.l, nFiles.l, rgsFilenames.l, nApplications.l, rgApplications, nServices.l, *rgsServiceNames)
Prototype.l RmRestart(dwSessionHandle.l, dwRestartFlags.l, fnStatus.i)
Prototype.l RmShutdown(dwSessionHandle.l, lActionFlags.l, fnStatus.i)
Prototype.l RmStartSession(pSessionHandle, dwSessionFlags.l, strSessionKey)


Procedure.i RstrtMgr_LoadDLL()
  Shared hDLL_RstrtMgr.i
  
  hDLL_RstrtMgr = OpenLibrary(#PB_Any, "RstrtMgr.dll")
  If hDLL_RstrtMgr <> 0
    Global RmEndSession.RmEndSession = GetFunction(hDLL_RstrtMgr, "RmEndSession")
    Global RmGetList.RmGetList = GetFunction(hDLL_RstrtMgr, "RmGetList")
    Global RmRegisterResources.RmRegisterResources = GetFunction(hDLL_RstrtMgr, "RmRegisterResources")
    Global RmRestart.RmRestart = GetFunction(hDLL_RstrtMgr, "RmRestart")
    Global RmShutdown.RmShutdown = GetFunction(hDLL_RstrtMgr, "RmShutdown")
    Global RmStartSession.RmStartSession = GetFunction(hDLL_RstrtMgr, "RmStartSession")
    
    ProcedureReturn hDLL_RstrtMgr
  EndIf
  
  ProcedureReturn #False
EndProcedure


Procedure FinishExplorerRestart(RmSession.l, dwError.l)  ; Restarts the explorer
  
  If dwError = RmRestart(RmSession, 0, #Null)    
    Debug "RmRestart: Re-launched application successfully."
    ProcedureReturn 1
  Else
    Debug "RmRestart error: "+dwError
  EndIf
EndProcedure

Procedure BeginExplorerRestart()
  Protected.l PID, RmSession = -1, dwError, rebootReason, nProcInfoNeeded,nProcInfo = 10
  Dim rgApplications.RM_UNIQUE_PROCESS(0)
  Dim RmSessionKey.w(#CCH_RM_SESSION_KEY+1)
  Dim rgpi.RM_PROCESS_INFO(10)
  
  PID = ProcHandle2("explorer.exe", rgApplications())  
  
  If PID = 0 : Debug "ProcHandle2 Failed" : ProcedureReturn 0 : EndIf
  
  If RmStartSession(@RmSession, 0, @RmSessionKey()) = #ERROR_SUCCESS
    dwError = RmRegisterResources(RmSession, 0, #Null, 1, rgApplications(), 0, #Null)    
    
    dwError = RmGetList(RmSession, @nProcInfoNeeded, @nProcInfo, rgpi(), @rebootReason)
    
    If rebootReason = #RmRebootReasonNone           
      RmShutdown(RmSession, #RmForceShutdown, 0)  ; Shutdown explorer 
      Delay(5000)
      FinishExplorerRestart(RmSession, dwError)
    EndIf
    
    RmEndSession(RmSession)
    RmSession = -1
    RmSessionKey(0) = 0    
  EndIf 
EndProcedure



If RstrtMgr_LoadDLL()
  BeginExplorerRestart()
  
  CloseLibrary(hDLL_RstrtMgr)
EndIf

Process_Set.pbi

Code: Select all

Structure RM_UNIQUE_PROCESS
  dwProcessId.l
  ProcessStartTime.FILETIME
EndStructure

Prototype.l EnumProcesses(*pProcessIds, cb.l, *pBytesReturned)
Prototype.l GetProcessImageFileName(hProcess, lpImageFileName, nSize.l)

Procedure.i psapi_LoadDLL()
  Shared hDLL_psapi.i
  Protected cMode.s
  
  CompilerIf #PB_Compiler_Unicode : cMode = "W" : CompilerElse : cMode = "A" : CompilerEndIf  
  
  hDLL_psapi = OpenLibrary(#PB_Any, "psapi.dll")
  If hDLL_psapi <> 0
    Global EnumProcesses.EnumProcesses = GetFunction(hDLL_psapi, "EnumProcesses")
    Global GetProcessImageFileName.GetProcessImageFileName = GetFunction(hDLL_psapi, "GetProcessImageFileName"+cMode)
    ProcedureReturn hDLL_psapi
  EndIf
  
  ProcedureReturn #False
EndProcedure


Procedure ProcHandle2(ProcName$, Array Process.RM_UNIQUE_PROCESS(1))
  #NbProcessesMax = 1024
  Global Dim ProcessesArray.l(#NbProcessesMax)  
  
  Protected.l bytesReturned, cProcesses, PID, ImageName.s
  Protected.FILETIME ftCreate, ftExit, ftKernel, ftUser
  
  If psapi_LoadDLL() = 0 : ProcedureReturn -1 : EndIf
  
  EnumProcesses(@ProcessesArray(), #NbProcessesMax, @bytesReturned)  
  
  ; Calculate how many process identifiers were returned.  
  cProcesses = bytesReturned / SizeOf(LONG)  
  
  For i = 0 To cProcesses-1    
    hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION|#PROCESS_VM_READ, #False, ProcessesArray(i))
    If hProcess
      ImageName = Space(4096)
      If GetProcessImageFileName(hProcess, @ImageName, 4096) > 0        
        ImageName = LCase(GetFilePart(ImageName))
        If ProcName$ = ImageName
          If GetProcessTimes_(hProcess, @ftCreate, @ftExit, @ftKernel, @ftUser)
            If Process(0)\dwProcessId = 0
              Process(0)\ProcessStartTime = ftCreate
              Process(0)\dwProcessId = ProcessesArray(i)
              
            ElseIf CompareFileTime_(Process(0)\ProcessStartTime, @ftCreate) = -1
              Process(0)\ProcessStartTime = ftCreate
              Process(0)\dwProcessId = ProcessesArray(i)
              
            EndIf
          EndIf
        EndIf        
      EndIf      
      
      CloseHandle_(hProcess)
    EndIf    
  Next
  
  CloseLibrary(hDLL_psapi)
  
  ProcedureReturn Process(0)\dwProcessId  
EndProcedure


CompilerIf #PB_Compiler_IsMainFile
  Dim Process.RM_UNIQUE_PROCESS(0)
  
  ProcName$ = "notepad.exe"
  PID.l = ProcHandle2(ProcName$, Process.RM_UNIQUE_PROCESS())  
  If PID : Debug ProcName$+" PID: "+Str(PID) : EndIf 
  
CompilerEndIf
Last edited by Thunder93 on Sun May 01, 2016 12:53 am, edited 6 times in total.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Reboot EXPLORER

Post by Kwai chang caine »

Thanks a lot at all, for your numerous and very interesting answers :shock: 8)

In fact, i want restart the explorer for update the registry, i have see it's the better way for forcing it to refresh.
Before i have try other method without succes :|
With the reboot of explorer, not all the options is updated, but numerous of them 8)

They are some days, i'm attacked by LOCKY :?
Fortunately, it's just on a new pc, with a new W7 and i have just lost several files
Then... i have install a new windows, because obviously i not want to pay :?

And it's at this moment i have an idea :idea:
Before against Tchernobyl or others malwares, i use GHOST image and all is good :D
But since several years, i not updated my GHOST images, and even sometime not the time to create it :oops:

So my idea is create a software, who reproduce all my personal setting :

- Not ask for before delete file in trash
- See the file extensions
- See the file system
- Change the background color of the desktop
- Change the wallpaper
- Change the THEME of windows in CLASSIC
- See the ful path in the title of the windows
- Open automaticaly the last windows opened before reboot
- Put all my shortcut, in the same place
- Copy all my portables tools that i need (Winamp, PureBasic, Acdsee, Vlc, etc ...)
- etc .......

Finally, i have a virus, i reinstall a new windows, i run my program, and automaticaly all the new windows become like before in several minute, and i'm a new time like in my home 8)
I don't affraid for my personal datas, because never she is on the machine, always on a external drive (With 4 safe copy) :wink:

This is the new stupid idea of KCC :mrgreen:

@RsBasic, @Fryquez
Incredible !!!! never i think explorer is a simple window :shock:
It's the reason why, i think the only method to stop it is kill it :oops:
Thanks for your code 8)

@Thunder93
Thanks a lot for your impressive and full code :shock: 8) , and also thanks for the tips too :wink:

@Dude
Yes i have see sometime Explorer don't want restart :|

@All
Really again thanks
I'm so happy to have so much friends in all the world
Have all, the better day of the world 8)
ImageThe happiness is a road...
Not a destination
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Reboot EXPLORER

Post by Thunder93 »

We always happy to help. :mrgreen:
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Reboot EXPLORER

Post by Kwai chang caine »

Perhaps....but you are all so generous 8)
In fact, i'm always so surprising by the power of this forum :shock:

Often, i talk about you all, powerfull, full knowledge, nearly all the time a question = an answer
Furthermore, a quick answer....when i say : "With PB you put a question, worst tomorrow you have an answer" i see the big surprising eyes with person use another languages :shock:

Really, never i'm tired to say, PB is a wonderfull and powerfull language, but his most big power is you all 8)
I'm so proud to know you all 8)

For that, even if the friends is virtal, all the time i was young, INTERNET not exist, and i have dreamed to have so much friend alone in my bedroom :|
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Reboot EXPLORER

Post by Kwai chang caine »

So when i'm finally behind a PC, i have test your code on W7

The code of FRYQUEZ and RSBASIC works, EXPLORER will close
But

Code: Select all

RunProgram("explorer.exe")
not works after :|

After, i have try the Thunder code
The "GetPidByName(p_name$)" is missing
So i have copy it here in RASHAD code :
http://www.purebasic.fr/english/viewtop ... 22#p311422
and adding that

Code: Select all

Prototype.i PFNCreateToolhelp32Snapshot(dwFlags.i, th32ProcessID.i) ;
Prototype.b PFNProcess32First(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Prototype.b PFNProcess32Next(hSnapshot.i, *lppe.PROCESSENTRY32) ;

Procedure GetPidByName(p_name$)
    Protected hDLL.i, process_name$
    Protected PEntry.PROCESSENTRY32, hTool32.i
    Protected pCreateToolhelp32Snapshot.PFNCreateToolhelp32Snapshot
    Protected pProcess32First.PFNProcess32First
    Protected pProcess32Next.PFNProcess32Next
    Protected pid.i
   
    hDLL = OpenLibrary(#PB_Any,"kernel32.dll")
   
    If hDLL
        pCreateToolhelp32Snapshot = GetFunction(hDLL,"CreateToolhelp32Snapshot")
        pProcess32First = GetFunction(hDLL,"Process32First")
        pProcess32Next = GetFunction(hDLL,"Process32Next")
    Else
        ProcedureReturn 0
    EndIf
   
    PEntry\dwSize = SizeOf(PROCESSENTRY32)
    hTool32 = pCreateToolhelp32Snapshot(#TH32CS_SNAPPROCESS, 0)
    pProcess32First(hTool32, @PEntry)
    process_name$ = Space(#MAX_PATH)
    CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
   
    If  UCase(process_name$) = UCase(p_name$)
        ProcedureReturn PEntry\th32ProcessID
    EndIf
   
    While pProcess32Next(hTool32, @PEntry) > 0
        process_name$ = Space(#MAX_PATH)
        CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
       
        If  UCase(process_name$) = UCase(p_name$)
            ProcedureReturn PEntry\th32ProcessID
        EndIf
   
    Wend
   
    CloseLibrary(hDLL)
   
    ProcedureReturn 0
EndProcedure
The code run now, Explorer close correctly, but not run
They are an error at this line :

Code: Select all

 dwError = RmRestart(RmSession, 0, #Null)
in

Code: Select all

; Restarts the explorer
Procedure FinishExplorerRestart()
  Protected dwError.l
  
  dwError = RmRestart(RmSession, 0, #Null)
  If dwError = #ERROR_SUCCESS
    Debug "Re-launched successfully Explorer"
    RmEndSession(RmSession)
    RmSession = -1
  Else
    Debug "RmRestart error: "+dwError : ProcedureReturn 0
  EndIf
EndProcedure
ImageThe happiness is a road...
Not a destination
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Reboot EXPLORER

Post by Thunder93 »

Hi. The Include file, I didn't clean it up good enough for posting. I left some remnants .. like GetPidByName(p_name$) which isn't required. I've updated the code in the include Process_Set.pbi section.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Reboot EXPLORER

Post by Thunder93 »

Just made minor change to hopefully address your problem with FinishExplorerRestart() procedure.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Reboot EXPLORER

Post by RASHAD »

Hi KCC
I did the next snippet long time back to refresh window without restart
Amazing it still work with windows 10 x64
Remember I am not going to do any more coding for such staff
So take it or leave it :P

Code: Select all

sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Software\Microsoft\Windows\CurrentVersion\Explorer"
sValueName.s = "EnableAutoTray"

Procedure.l QueryValueEx(lhkey.l, szValueName.s) 
    Shared vValue.s 
    cch = 255 
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch) 
        
    Select lType 
        Case #REG_DWORD 
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @lValue, @cch) 
            If lrc = 0
              vValue = Str(lValue) 
            EndIf 
        Default 
            lrc = -1 
    EndSelect 
    ProcedureReturn lrc 
EndProcedure

Procedure SetValue(lTopLevelKey.l, sKeyName.s, sValueName.s, vValue.s, lType.l, sRemMachName.s) 
 
  If sRemMachName.s = "" 
    GetHandle = RegOpenKeyEx_(lTopLevelKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, lTopLevelKey, @lhRemoteRegistry) 
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey) 
  EndIf 

   If GetHandle = #ERROR_SUCCESS     
    Select lType 
      Case #REG_SZ 
        GetHandle = RegSetValueEx_(hkey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1) 
      Case #REG_DWORD 
        lValue = Val(vValue) 
        GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4) 
    EndSelect 
      
    RegCloseKey_(hkey) 
    SetValue = 1 
   Else 
    RegCloseKey_(hKey)
    SetValue = 0 
  EndIf
  ProcedureReturn SetValue
EndProcedure 
 

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle) 
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey) 
lRetVal = QueryValueEx(lhkey, sValueName) 
RegCloseKey_(lhkey) 

If Val(vValue) = 0
    SetValue(lTopLevelKey, sKeyName, sValueName.s, "01", #REG_DWORD, "")
Else
    SetValue(lTopLevelKey, sKeyName, sValueName.s, "00", #REG_DWORD, "")
EndIf

Procedure PPid(Process$)
    Protected PE.PROCESSENTRY32, hTH.i
    
    hLib = OpenLibrary(#PB_Any,"kernel32.dll") 
    
    If hLib 
        pCreateToolhelp32Snapshot = GetFunction(hLib,"CreateToolhelp32Snapshot") 
        pProcess32First = GetFunction(hLib,"Process32First") 
        pProcess32Next = GetFunction(hLib,"Process32Next") 
    Else 
        ProcedureReturn 0 
    EndIf 
    
    PE\dwSize = SizeOf(PROCESSENTRY32) 
    hTH = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0) 
    Process32First_(hTH, @PE) 
    PName$ = Space(#MAX_PATH) 
    CopyMemory(@PE\szExeFile,@PName$,#MAX_PATH) 
    
    If  UCase(PName$) = UCase(Process$) 
        ProcedureReturn PE\th32ProcessID 
    EndIf 
    
    While Process32Next_(hTH, @PE) > 0 
        PName$ = Space(#MAX_PATH) 
        CopyMemory(@PE\szExeFile,@PName$,#MAX_PATH) 
        
        If  UCase(PName$) = UCase(Process$) 
            ProcedureReturn PE\th32ProcessID 
        EndIf 
    
    Wend 
    
    CloseLibrary(hLib) 
    
    ProcedureReturn 0 
EndProcedure

ProcessID = PPid("explorer.exe")
Process = OpenProcess_(#PROCESS_ALL_ACCESS, 0, ProcessID)
ReturnValue = TerminateProcess_(Process, 0)
Egypt my love
Post Reply