I am trying to run a program (In this case Internet Explore) hidden/invisible from a VB script.
I found a simple script for making batch files hidden, and tried it. It didn't seem to work as the program just popped up as normal.
Here is my code so far:
CreateObject("Wscript.Shell").Run "iexplore.exe",0,True
This runs the program iexplore.exe, but doesn't run it hidden/invisible.
I am also running this VBS file from a batch file which is hidden.
The batch file simply does:
start Run.vbs
Codes of each script/batch file:
Batch File: Main file launching VBS file
#echo off
:start
start HideExecuteServerVBS.vbs (To Hide the ExecuteServerVBS.bat file when running)
timeout /NOBREAK /T 5
TASKKILL /IM iexplore.exe
timeout /NOBREAK /T 3
TASKKILL /IM iexplore.exe /F
timeout /NOBREAK /T 1800
goto start
HideExecuteServerVBS.vbs
CreateObject("Wscript.Shell").Run "ExecuteServerVBS.bat",0,True
ExecuteServerVBS.vbs
#echo off
C:\Windows\sysWOW64\csript.exe C:\Users\Admin\RunInternetProcess\vbscript.vbs
vbscript.vbs
Set ie = CreateObject("InternetExplorer.Application")
Is there a possible way to run a program invisible through a VB Script (Visual Basic Script)?
So here's the deal, if you are receiving an ActiveX error, you most likely are trying to run this vbscript under a server. Server with a 64bit platform with lack of support for direct execution of 32bit vbscripts? Yeah? If so, here's what you need to do.
Make a batch file:
ExecuteServerVBS.bat
C:\windows\sysWOW64\cscript.exe C:\path\to\your\vbscript.vbs
Put your vbscript code here:
vbscript.vbs
Set ie = CreateObject("InternetExplorer.Application")
'Go crazy
And BOOM. You're done.
UPDATE
update the file ExecuteServerVBS.vbs
#echo off
C:\Windows\sysWOW64\cscript.exe C:\Users\Admin\RunInternetProcess\vbscript.vbs > errorlog.log
update the file vbscript.vbs
On Error Resume Next
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
'Perform IE functions here......
If err.number <> 0 then wscript.echo err.number & ":" & err.description
You need to load it this way instead:
Set ie = CreateObject("InternetExplorer.Application")
' To make visible, uncomment the following line...
'ie.Visible = True
Have a look at these methods:
http://ss64.com/vb/run.html
http://ss64.com/vb/exec.html
http://ss64.com/vb/shellexecute.html
http://ss64.com/vb/syntax-elevate.html
Related
I'm having a hard time finding an answer to this question. I'm looking specifically to execute a command in a batch file only after a program is terminated - however, a program that wasn't launched by the batch file.
My problem is this - the program I am actually launching in the batch file I want to wait on is in turn launching another program, which in turn launches another. This probably doesn't make any sense - but it's because it's a game launcher. It is for Final Fantasy XIV. The normal program that is launched to start it is ffxivboot.exe, which in turn launches ffxivlauncher.exe. That is a login window, and once you login, it in turn launches ffxiv_dx11.exe. So while I originally wrote it to wait on ffxivboot.exe, that process doesn't stay running so I am unable to wait on it.
Here's my file (excluded paths for simplicity):
taskkill /im someprogram.exe
ffxivboot.exe
timeout /t 60 /nobreak
### ??? need to wait on ffxiv_dx11.exe to close before executing next command
someprogram.exe
I added a timer to wait so that it gives me plenty of time to login - because the ffxiv_dx11.exe process doesn't start until after logging in.
Is what I'm trying to do possible? It's hard to search for answers to this because I only get results regarding when you're waiting on a task to end that was started from the batch file. But like I said, that one launches another which in turn launches another - so the original process is no longer running.
Thanks for any help!
taskkill /im someprogram.exe
ffxivboot.exe
timeout /t 60 /nobreak
:repeat
::### ??? need to wait on ffxiv_dx11.exe to close before executing next command
tasklist /fi "imagename eq ffxiv_dx11.exe"|find /i "=========================" >nul 2>nul &&(
w32tm /stripchart /computer:localhost /period:10 /dataonly /samples:2 1>nul
goto :repeat
)
someprogram.exe
try this
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM Win32_ProcessStopTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
msgbox objReceivedEvent.ProcessName
If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then
Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus
WshShell.Run "c:\Windows\notepad.exe", 1, false
End If
Loop
This is a vbs file that needs to run elevated. It waits for any program to exit and checks if it's notepad and springs to life restarting it.
Type in a elevated command prompt taskkill /f /I'm wscript.exe to stop it.
Firstly I have created VBScript to run a batch file without a visible command prompt.
Following is the code:
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run Chr(34) & ("D:\Intouch_Printer_SW\spool12\spltotext.bat") & Chr(34), 0
Set WshShell = Nothing
Following is my batch file code to run a third party .exe file.
for %%f in (C:\WINDOWS\system32\spool\PRINTERS\*.SPL) do (
echo %%~nf
start "" D:\Intouch_Printer_SW\spool12\spool.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "Intouch Printer"
)
Whenever I run my .vbs code a console window pops up, I want to do all of it without a visible command prompt.
I think I am getting a black window due to this snippet:
start "" D:\Intouch_Printer_SW\spool12\spool.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "Intouch Printer"
start opens the command in a new window. It isn't required for running console applications, so you can simply remove it:
for %%f in (C:\WINDOWS\system32\spool\PRINTERS\*.SPL) do (
echo %%~nf
D:\Intouch_Printer_SW\spool12\spool.exe "C:\WINDOWS\system32\spool\PRINTERS\%%~nf.SPL" "Intouch Printer"
)
In addition I would recommend running the batch script synchronously from the VBScript (3rd argument to the Run method set to True), to avoid undesired side effects should anyone ever modify the VBScript.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """D:\Intouch_Printer_SW\spool12\spltotext.bat""", 0, True
I had a simple VB Script that would let me enter in the amount of minutes before I wanted my PC to turn off by itself, and then it would auto-shutdown. That worked fine. After I wiped my PC, the script no longer functions as intended, instead showing a blank cmd window after I enter the number of minutes before shutdown, and displays the inputbox again (asking for # of minutes before shutdown).
Any ideas on why this won't function correctly, and why it worked before but not now? Do I need a certain package from Microsoft that maybe I didn't reinstall?
Code:
Dim a
Dim oShell
a=inputbox("After how many minutes would you like to shut down your PC? Enter cancel to cancel a previous shutdown")
Set oShell = WScript.CreateObject ("WScript.Shell")
if a = "cancel" then
oShell.run "cmd.exe /c shutdown /a"
elseif a = "" then
MsgBox"Please enter after how many minutes you would like to turn off this PC",0+16,"Enter a number"
elseif a = "0" then
b=msgbox("Are you sure you want to shut down this PC immediately?",4+32,"Shut down immediately?")
if b = "6" then
oShell.run "cmd.exe /c shutdown /s /f"
end if
else
oShell.run "cmd.exe /c shutdown /s /t " & (a * 60)
end if
EDIT: Running the script from its directory works as intended, but running the VBScript from a shortcut (as a I had been doing) doesn't work and yields the above results.
EDIT: Also the script itself won't run properly on my desktop, but runs fine in the folder I store my scripts.
You named the script shutdown.vbs and run it with the working directory set to the directory containing the script. By running oShell.Run "cmd.exe /c shutdown ..." your script is effectively calling itself.
If you call a command shutdown (without path and extension) the system is looking for a file with one of the extensions listed in %PATHEXT% in the directories listed in the %PATH% environment variable. The first match wins.
Since on Windows the current directory comes first in the %PATH% the file %CD%\shutdown.vbs is found before %windir%\system32\shutdown.exe.
Either rename your VBScript or change cmd.exe /c shutdown to cmd.exe /c shutdown.exe and the problem will disappear.
I am attempting to write code that will call a batch file, wait until it is complete and then move on to the next line of code in Visual Basic. The code I have does open the batch file, however it does not actually execute. It opens the cmd window and displays some non-code I've written, but does not execute. I've tested the batch file by clicking it and running through cmd and it works fine. Just doesn't run through VBS.
Dim objShell As Object
Set objShell = CreateObject("Wscript.Shell")
Wait = True
objShell.Run """C:\Users\wjones\Documents\Data Loader\Scheduler\process.bat""", 1, Wait
try this:
objShell.Run "cmd /c C:\Users\wjones\Documents\Data Loader\Scheduler\process.bat", 1, Wait
I've searched this and some pages came which weren't really useful or were too complicated (I am not a skilled batch file programmer!)! What I need is to run a batch file in hidden form (no console window). The batch file will not be called from external application or code. It will be clicked on by the client and then I want no console pages to be shown (only pages which are called by call command should be shown)! The batch file is exactly as follows:
#echo off
call setup.exe
IF EXIST "C:/caillog" goto tracking
IF NOT EXIST "C:/caillog" goto end
:tracking
call dotnet4.exe
call ClientService.msi
goto end
:end
I use VBScripts to open it hidden, like this:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%batchfile%"), 0, True
for e.g the bat file I want to run is run.bat then I'll do like this
objShell.Run("run.bat"), 0, True
Instead of running the batch file run the vb file.
Write it in notepad and save it as *.vbs
If your Windows system supports powershell you can place this infront of "#echo off":
cmd /c powershell -Nop -NonI -Nologo -WindowStyle Hidden "Write-Host"
As others have said, use VBS.
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\FilePath" & Chr(34), 0
Set WinScriptHost = Nothing
This is what I use.