I have this script and I need it to finish (auto-end or autokill itself and also close wscript.exe) after launching the .bat
On Error Resume next
If WScript.Arguments.Named.Exists("elevated") = False Then
'Launch the script again as administrator
CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
WScript.Quit
Else
'Change the working directory from the system32 folder back to the script's folder.
Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
End If
Dim Fso
Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
set objshell = createobject("wscript.shell")
homedrive = objshell.ExpandEnvironmentStrings( "%HOMEDRIVE%" )
SCRIPT = homedrive & "\test\bar.bat"
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
NewPath = objFSO.BuildPath(strFolder, SCRIPT)
set objshell = createobject("wscript.shell")
objshell.Run (script),0,True
Failed attempts:
- I tried with this code and it did not work
- WScript.Quit (at the end of the script) and it did not work
- Change "true" to "False" and it did not work
Any ideas?
Update: The main problem is that wscript.exe remains running after launching the .vbs (it can be seen in the task manager) and i can not use cmd commands inside the .vbs or inside .bat (taskkill /f /im "wscript.exe" /t) because the .bat and the .vbs are closed
If my question has no answer: I would appreciate someone telling me how to launch a .bat with a method that Windows recognizes natively (without installing dependencies). Please exclude the following methods:
- launch .bat directly
- Launch .bat with a shortcut
- Convert .bat to .exe
- Launch .bat with .vbs