Do not use on any
shared computer
July 24, 2008 01:38pm pdt
 
[x]
Attachment Details

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

Tags: VBScript
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?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
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"
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: FIM2003
Solution Provided By: newborn1281
Participating Experts: 2
Solution Grade: A
Views: 226
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by newborn1281
Expert Comment by newborn1281:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by newborn1281
Expert Comment by newborn1281:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by FIM2003
Author Comment by FIM2003:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by newborn1281
Expert Comment by newborn1281:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by FIM2003
Author Comment by FIM2003:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by newborn1281
Expert Comment by newborn1281:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by newborn1281
Accepted Solution by newborn1281:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Open Discussion
Open Discussion
 
Comment by RobSampson
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.
 
 
Comment by FIM2003
Thanks, Rob. I'll give that a try!
 
 
Comment by RobSampson
No worries....looks like I was too late, but oh well!  It's just more info....

Regards,

Rob.
 
 
20080723-EE-VQP-34 / EE_QW_2_20070628