i need to make a batch file that have a hidden process and window for the users
i have already my batches file and want to make one of them hidden
vbs can't make that or any programming language ?
here you can find multiple ways to do this : https://stackoverflow.com/questions/28284876/what-are-the-different-ways-to-start-a-hidden-process-with-batch-file-and-what-a
Probably the best is with Win32_ProcessStartup as it returns also the pid of the started process.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\file.bat" & Chr(34), 0
Set WshShell = Nothing
with Vbs and call the bat file this is the way
Use the start command:
start /b my.bat
Refer to: https://technet.microsoft.com/en-us/library/cc770297(v=ws.11).aspx
Related
This question already has an answer here:
Prevent VBscript app from showing Console Window
(1 answer)
Closed 2 years ago.
I am working on shell script/ .vbs extension file, and I want to run a batch file hiddenly or in background from shell script. I am mentioning my code but its not executing a batch file. I have saved my file with a name test.vbs.
Set WshShell = CreateObject()
WshShell.Run chr(34) & "%USERPROFILE%\AppData\Local\RE.bat" & Chr(34), 0
Set WshShell = Nothing
Thanks in advance.
when you write CreateObject(), you have to mention in those circle brackets. Your code looks fine just add WScript.shell in circle brackets like this.
Set WshShell = CreateObject("WScript.shell")
You need CreateObject("WScript.Shell"), not CreateObject():
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run Chr(34) & "%USERPROFILE%\AppData\Local\RE.bat" & Chr(34), 0
Otherwise VBScript wouldn't know what you want to create! So it can't know you want the shell object that has the Run method...
I'm trying to run a batch file hidden. I have read many threads here but I still can't get it working. Win7 - I have created a new toolbar in the taskbar that shows me all .enc files in a specific folder. I want to click to select one of those filenames and have it sent to the vbs script that will run a batch file hidden with that filename as the first argument for the batch file. I am using total commander and have set up a file association of the below for .enc files -
hidebat.vbs %1
That is supposed to take the filename I selected and send it to the script.
This is the script hidebat.vbs -
CreateObject("Wscript.Shell").Run "G:\test\clipTest.bat" WScript.Arguments(0), 0, True
That is from another thread on this topic to run batch files hidden but with my addition of the WScript.Arguments(0) part. Supposedly that grabs the first argument to the vbs script.
When I try this out I get a window stating that the filename I selected is not a valid win32 application. Is it obvious what's wrong?
If it all could be done within the vbs script, all the better. I'm only doing two things in the batch file -
1. echo|set /p=%1|clip (echoing that filename to the clipboard)
2. start "" "g:\test\Process.lnk" (running this shortcut)
You forgot the & as well as a space between the script and your argument.
Try this:
CreateObject("Wscript.Shell").Run "G:\test\clipTest.bat " & WScript.Arguments(0), 0, True
Try the following. Chr(34) resolves to a quote, in case your paths contain spaces:
CreateObject("Wscript.Shell").Run chr(34) & "G:\test\clipTest.bat" & chr(34) & " " & chr(34) & WScript.Arguments(0) & chr(34), 0, True
I had to change my file association line to -
wscript "g:\path\to\hidebat.vbs" "%1"
Now it works, thanks!
Soo
#echo off Turn off command echoing and don't echo the command turning it off. But how to make bat file do not call CMD at all ?
This makes so little sense. If you're asking how to stop a batch file from showing the command prompt window, you cannot.
You can however use a VBScript file to launch the batch file silently. The script would look something like:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path-to-batch-file\batchfile.bat" & Chr(34), 0
Set WshShell = Nothing
I think what you're trying to do probably isn't a job for a batch file.
A batch file is a script, not a binary executable. A script always needs an interpreter to run. For batch scripts, the interpreter is cmd.exe, so you cannot avoid invoking cmd.exe at all. It makes no sense to run a script without its interpreter. This is true everywhere.
All you can do is hiding the console window that cmd.exe brings up when it's invoked, most easily done with the help of a VBScript:
CreateObject("Wscript.Shell").Run "C:\path\to\your.bat", 0, False
I was making a batch file that was able to create a vbs coded file I had already made but when I tried running the file it kept trying to run the vbs code as a command and not put it in the file the code that gave the errors are
set line5=set objWMIService = getobject("winmgmts://"_& strComputer & "/root/cimv2")
echo %line5% >>password.vbs
this one tried to run the strComputer as a command
set line20=strComputer = "."
echo %line20% >>password.vbs
this one tried to run the strComputer part but I have one like that and it works just fine
set line21=strExe = "explorer.exe"
echo %line21% >>password.vbs
in this one it is trying to load the strEXE as a command
set line49=WScript.echo "Created: " & strExe & " on " & strComputer
echo %line49% >>password.vbs
for this last one the program is trying to run " on " as the command
So if anyone reading does not understand my problem I will say it again what I am trying to do is save the vbs code into a file but the batch window keeps on trying to execute random commands that I am trying to put in the file which makes it not put them in and give me errors making the file not work correctly I am going to say this in advance thank you to anyone who tries to help
try this:
#echo off
cls
set line1=FirstLineOfCodeHere
set line2=SecondLineOfCodeHere
(echo %line1%
echo %line2%)>filename.vbs
UPDATE: Use '>' to overwrite the file. Use '>>' to write more on the original file.
I'm trying to run a .bat file using VBScript. I can get the VBScript to work when executed within the same folder as the .bat, however, I can't figure out how to make it successfully run when outside the folder.
Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "C:\Users\js\Desktop\createIndex\createindex.bat"
Going out on a limb I would suspect that the batch script requires its own parent folder to be the working directory. You can set the working directory accordingly by changing your code to this:
Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "C:\Users\js\Desktop\createIndex"
shell.Run "createindex.bat"
If the above doesn't help you need to provide more information about what should happen and what actually does happen. Running the external command/script in visible mode and without automatically closing CMD usually helps with debugging:
shell.CurrentDirectory = "C:\Users\js\Desktop\createIndex"
shell.Run "cmd /k createindex.bat", 1, True
I've 4 simple scripts for what kind of calls.
call.vbs
call_nowait.vbs
call_nowindow.vbs
call_nowindow_nowait.vbs
All the 4 has these lines of code in the beginning:
ReDim args(WScript.Arguments.Count-1)
For i = 0 To WScript.Arguments.Count-1
If InStr(WScript.Arguments(i), " ") > 0 Then
args(i) = Chr(34) & WScript.Arguments(i) & Chr(34)
ElseIf WScript.Arguments(i) = "" Then
args(i) = Chr(34) & WScript.Arguments(i) & Chr(34)
Else
args(i) = WScript.Arguments(i)
End If
Next
Set objShell = WScript.CreateObject("WScript.Shell")
' MsgBox Join(args, " ")
Plus the last line is different in all 4 scripts:
call.vbs
objShell.Run Join(args, " "), 1, True
call_nowait.vbs
objShell.Run Join(args, " "), 1, False
call_nowindow.vbs
objShell.Run Join(args, " "), 0, True
call_nowindow_nowait.vbs
objShell.Run Join(args, " "), 0, False
For example, the entire command line for the call_nowindow.vbs script looks like this:
call_nowindow.vbs "C:\Users\js\Desktop\createIndex\createindex.bat"
By the way, you can run anything by these scripts, not only just batch files.
This one will create an instance of notepad.exe with out window:
call_nowindow.vbs notepad
This one will create cmd console with current date and time, and leave the window open:
call_nowait.vbs cmd /k echo.%DATE% %TIME%
Use this script to set the directory to the current working directory of your script. That way whenever the script changes directories it will look for it there instead of hard rooting it to a specific directory.
scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
This will make any files that it is looking for in that directory available to the script.
Example : If the file were on the current users desktop.
C:\Users\[Username]\desktop\myfile.vbs
Will become:
scriptdir\myfile.vbs
and if you moved it to a subfolder "subfolder" it would remain
scriptdir\myfile.vbs
even if the script location is different. The "scriptdir" is a placeholder for the folder the active script is running from.