Solved

objetshell ipconfig causes multiple cmd promt windows to open

Posted on 2007-04-05
7
324 Views
Last Modified: 2012-05-05
I am writing scripts to run things like ipconfig and pathping and keep hitting same problem when trying to run them. The script below comes straight from microsoft http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1002.mspx when it runs all i get is hundreds and hundreds of cmd windows. I'm copying the text into notepad and saving it as ipconfig.vbs and I run it using cscript ipconfig.vbs. why won't it run propley it also does the same if I use pathping or objshell.exec Ive tried running it in cmd prompt and powershell still same result. Only way to stop them running is to log off machine while they are running. Im running XP pro SP2. If I run them in cmd prompt window no problems works fine.

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k ipconfig"

                           OR

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k pingpath 192.168.1.1"
0
Comment
Question by:carlpotter
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 18864077
did you try to change /k to /c ?


0
 
LVL 1

Author Comment

by:carlpotter
ID: 18865046
Yes I tried it both ways same result.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19114187
If you don't want to see the command prompts, while they will still be activating (but hidden), use:
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /k ipconfig", 0, True

The 0 states that it will be hidden, where 1 (default) is visible.  The True at the end tells the script to wait for the command prompt to finish it's task before continuing with the next statement.

Regards,

Rob.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 19256559
TheLearnedOne,

I just noticed an error in the method I posted, in that I used cmd /k instead of cmd /c, which means that multiple hidden instances of CMD.exe would have stayed running.

However, using
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% /c ipconfig", 0, True

will cause each command prompt to exit when finished (the /c) and not be displayed to the user (the zero).  Therefore, I believe my answer would satisfy the requirements of this problem.

Regards,

Rob.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now