Commands Being Run via VBS Script. How to prevent cmd windows?

I am making a VBS script that will run three commands to open ports necessary for Remote Assistance. When this VBS script is run, three cmd windows popup for a few seconds and disappear. Is there any way to prevent the window from popping up?
set oShell  = WScript.CreateObject("WScript.shell")
 
oShell.run "netsh firewall add allowedprogram  c:\windows\system32\sessmgr.exe 
 
sessmgr ENABLE"
 
oShell.run "netsh firewall add allowedprogram 
 
c:\windows\PCHEALTH\HELPCTR\Binaries\helpsvc.exe helpsvc ENABLE"
 
oShell.run "netsh firewall add portopening TCP 135 RemoteAssistance"

Open in new window

FIM2003Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
newborn1281Connect With a Mentor Commented:
set oShell  = WScript.CreateObject("WScript.shell")
 
oShell.run "netsh firewall add allowedprogram  c:\windows\system32\sessmgr.exe sessmgr ENABLE", 2
oShell.run "netsh firewall add allowedprogram c:\windows\PCHEALTH\HELPCTR\Binaries\helpsvc.exe helpsvc ENABLe", 2
 
oShell.run "netsh firewall add portopening TCP 135 RemoteAssistance", 2






it will minimize windows
0
 
newborn1281Commented:
try using oshell.exec
or oshell.run fith flag 2 which will minimize window
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
FIM2003Author Commented:
I changed it to Exec and include the cmd.exe /k as you and the article specified and three cmd windows still popup for a few seconds.
set oShell  = WScript.CreateObject("WScript.shell")
 
oShell.Exec "cmd.exe /k netsh firewall add allowedprogram  
 
c:\windows\system32\sessmgr.exe sessmgr ENABLE > testing.txt"
 
oShell.Exec "cmd.exe /k netsh firewall add allowedprogram 
 
c:\windows\PCHEALTH\HELPCTR\Binaries\helpsvc.exe helpsvc ENABLE"
 
oShell.Exec "cmd.exe /k netsh firewall add portopening TCP 135 RemoteAssistance"

Open in new window

0
 
newborn1281Commented:
They will popup because you lounch cmd.exe
in command oshell.Exec "cmd.exe /k"
try without cmd.exe as you do not need  reference to command prompt
0
 
FIM2003Author Commented:
Oh. I have removed the "cmd.exe /k" and the windows still come up.
set oShell  = WScript.CreateObject("WScript.shell")
 
oShell.Exec "netsh firewall add allowedprogram  c:\windows\system32\sessmgr.exe 
 
sessmgr ENABLE > testing.txt"
 
oShell.Exec "netsh firewall add allowedprogram 
 
c:\windows\PCHEALTH\HELPCTR\Binaries\helpsvc.exe helpsvc ENABLE"
 
oShell.Exec "netsh firewall add portopening TCP 135 RemoteAssistance"

Open in new window

0
 
newborn1281Commented:
there is a possibility that netsh will be opening comamnd promp window how about minimizing them if you would use

oshell.run (your command, 2)
0
 
FIM2003Author Commented:
That will do the trick. Thanks!
0
 
RobSampsonCommented:
Hi guys,

The Exec method of the Shell object can not force hidden windows. It's advantage is that you can read the output from a command prompt.  The Run method, as stated, does have a parameter that allows the window to be displayed in any form, including hidden.  It actually has three parameters:
http://msdn2.microsoft.com/en-us/library/d5fk67ky.aspx

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

You can see in the link above the 10 window styles that can be used, including a zero, which puts the application that is to be run in a hidden state.

The third parameter tells the rest of the script to wait until the command being run has finished, before it continues executing more code.

So, you can run the following command hidden:
Set oShell  = CreateObject("WScript.shell")
strCommand = "cmd /c netsh firewall add allowedprogram  c:\windows\system32\sessmgr.exe sessmgr ENABLE > testing.txt"
oShell strCommand, 1, True

to have the cmd program run in a normal window style.  If you use
oShell strCommand, 0, True

the cmd program runs hidden.

Now, for testing, to see cmd window output, you can use:
Set oShell  = CreateObject("WScript.shell")
strCommand = "cmd /k netsh firewall add allowedprogram  c:\windows\system32\sessmgr.exe sessmgr ENABLE > testing.txt"
oShell strCommand, 1, True

Where I've put cmd /k, not cmd /c.  This is usually used for testing, so the command window stays open when the command has finished.  You should notice that you must *not* use cmd /k with a zero window style, because then you'll have an open command prompt, which is hidden, and you have to kill it via the task manager.

Hope that helps,

Regards.

Rob.
0
 
FIM2003Author Commented:
Thanks, Rob. I'll give that a try!
0
 
RobSampsonCommented:
No worries....looks like I was too late, but oh well!  It's just more info....

Regards,

Rob.
0
All Courses

From novice to tech pro — start learning today.