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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

newborn1281Commented:
try using oshell.exec
or oshell.run fith flag 2 which will minimize window
0
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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
newborn1281Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.