October 31, 2025, 08:12:53 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


How to Stop and Restart explorer

Started by Andy, January 19, 2010, 01:13:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi Everybody,

Happy new year to you all !

Just a quick question, does anybody know how to stop and then restart explorer.exe - currently I have my Ebasic programs create a VB script file and then run it.

The VB script does exactly what I want but I would like to do this from Ebasic, does anyone have an example ?

PS if anybody wants the code I have please let me know and I will post it in this thread.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Copex


try this ;-) you may have to add a pause between the system commands.


SYSTEM "taskkill.exe" , " /f /IM explorer.exe"
SYSTEM "explorer.exe"

QuoteSyntax

SYSTEM(command as STRING, OPT param as STRING)

Description

Runs another executable.

Parameters

command - Executable to run.

param - Parameter for executable.

Return value

None

Remarks

Command must be full pathname to executable or the executable needs to be in the system path.

Example usage

.SYSTEM "notepad.exe" , "c:\\mydocs\\prog.txt"
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

Andy

Thanks for the quick reply but I cannot find any system program called 'Taskkill.exe' i'm using XP home edition but found out on the home editions you have to use 'TSKILL' instead so will give it a go and post the results.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Copex

hi

i run win7, i have tryed the taskkill command on a win xp (pro) virtual P.C and it works. it must be one of those thing MS removed from xp home.

only other thing you could do is post the vb script and see if it can be converted to E.B
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

Andy

Thanks for taking the time to reply again, taskkill does work on xp pro and later but I need to cover all xp, vista and 7 machines so I think for now i'll stick wit this script.

Please see attached program and please use it if it helps you all


'Compile this as a Windows target - enjoy.

DEF myfile:file
DEF X$,Y$,Z$:string

X$ = CHR$(34)  ' The " character
Y$ = CHR$(39)  ' The ' character
Z$ = CHR$(92)  ' The \ character

'Create the VB script file
'You can change the "C:\\windows\\restart.vbs" to what ever you want but file name must end with .vbs

IF OPENFILE(myfile, "C:\\windows\\restart.vbs", "W") = 0
WRITE myfile , "Option Explicit"
WRITE myfile , "Dim objWMIService, objProcess, colProcess, MyBox"
WRITE myfile , "Dim strComputer, pstop"
WRITE myfile , "Dim jobfunc, jobfunc2,ttl"
WRITE myfile , "strComputer = "+X$+"."+X$+""

'Set the name of the .exe you want to stop and restart
WRITE myfile , "pstop = "+X$+Y$+"explorer.exe"+Y$+X$+""

'Prepare a message for later
WRITE myfile , "jobfunc = "+X$+"Thank You, Your desktop has been restarted."+X$+" "
WRITE myfile , "ttl = "+X$+"Finished"+X$+" "

WRITE myfile , "Set objWMIService = GetObject("+X$+"winmgmts:"+X$+" _"
WRITE myfile , "& "+X$+"{impersonationLevel=impersonate}!"+Z$+Z$+X$+" _"
WRITE myfile , "& strComputer & "+X$+"\root\cimv2"+X$+")"

'Stop Explorer.exe
WRITE myfile , "Set colProcess = objWMIService.ExecQuery _"
WRITE myfile , "("+X$+"Select * from Win32_Process Where Name = "+X$+" & pstop )"
WRITE myfile , "For Each objProcess in colProcess"
WRITE myfile , "objProcess.Terminate()"
WRITE myfile , "Next"

'Restart Explorer.exe
WRITE myfile , "Dim objShell"
WRITE myfile , "Set objShell = CreateObject("+X$+"WScript.Shell"+X$+")"
WRITE myfile , "objShell.Run "+X$+"explorer.exe"+X$+""
WRITE myfile , "Dim starttime, exittime, x, strFilePath, objFSO"

'Time delay before the message is displayed if preferred - just remove the ' characters
'WRITE myfile , "x = 0"
'WRITE myfile , "starttime = timer"
'WRITE myfile , "exittime = starttime + 10"
'WRITE myfile , "do while timer < exittime"
'WRITE myfile , "x= x + 1"
'WRITE myfile , "loop"

'Show the confirmation message - delete this line if you don't want a message
WRITE myfile , "Mybox = MsgBox(jobfunc & "+X$+" "+X$+", 4096, ttl)"

'This script will delete itself when finished
WRITE myfile , "DeleteOff"
WRITE myfile , "Sub DeleteOff()"       
WRITE myfile , "Dim objFSO"
WRITE myfile , "Set objFSO = CreateObject("+X$+"Scripting.FileSystemObject"+X$+")"
WRITE myfile , "objFSO.DeleteFile WScript.ScriptFullName"
WRITE myfile , "Set objFSO = Nothing"
WRITE myfile , "End Sub"

WRITE myfile , "WScript.Quit"
CLOSEFILE myfile
ENDIF

SYSTEM "C:\\windows\\restart.vbs"
END

Regards,
Andy
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.