Solved

How to Make Wshell.Run "cmd.exe ..." Execute in a Hidden Window

Posted on 2004-10-01
9
19,846 Views
Last Modified: 2012-05-05
I need the following VBS code to start cmd.exe in either a minimized window or a hidden window:

Wshell.Run "cmd.exe /C" & chr(34) & "reg.exe query " & regPath & " /s >>" & filePath & chr(34),1,True

I tried adding vbHide to the end of the line, but Wshell.Run doesn't like it. I also tried adding some extra perameters to the cmd.exe call, but those didn't help either.
0
Comment
Question by:Grime121
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:untarded
Comment Utility
Call Shell("cmd.EXE" /s [commands here], vbHide)
0
 
LVL 1

Expert Comment

by:untarded
Comment Utility
If you are trying to register a .dll then use

Call Shell("REGSVR32.EXE /s [path]", vbHide)

you can view this by replacing vbHide with vbNormalFocus and/or receive a confirmation message by removing the /s (silent) command.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
Here's a version that uses the Wscript.Shell object to do this.

    Dim objShell As New WshShell
    x = objShell.Run("Cmd /C Dir", vbHidden)

I think the problem is that you both used vbHide instead of vbHidden.
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
reg.exe query is for getting information from the registry. It's then getting put into a text file. I can't seem to get call shell to work. Here's what I've been trying:

call shell("cmd.exe" /S & chr(34) & " reg.exe query " & regPath &  " /s >>" & filePath & chr(34),1,True,vbHide)

the error is type mismatch '[string:"cmd.exe"]'

I don't know a whole lot about VB scripts :(
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:Grime121
Comment Utility
that one isn't for VB script I don't think, bluedevilfan. It's not liking the 'As New WshSell' line.
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
Ok, I've got it. All I had to do was remove the ,1,True and put ,vbHidden instead. That was easy enough :P

Wshell.Run "cmd.exe /C /S " & chr(34) & " reg.exe query " & regPath &  " /s >>" & filePath & chr(34),vbHidden
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Doh!  Sorry, I keep forgetting to remove VB things from VBScript posts.
0
 
LVL 1

Expert Comment

by:untarded
Comment Utility
This will work in VB or VBA I don't know about VB script.

'READ FROM WINDOWS REGISTRY

Dim b As Object
On Error Resume Next
Set b = CreateObject("wscript.shell")
r = b.RegRead([Value]

Is this a web app?
0
 
LVL 1

Author Comment

by:Grime121
Comment Utility
no, it makes a software inventory by reading the displayname values under the uninstall registry key into a file seperated by commas. Then we have an SQL script that is going to read the files and add the info to a table. That way we can bring up a computer's info by doing a query on a php webpage, and we won't have to mess with manually entering the data.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

11 Experts available now in Live!

Get 1:1 Help Now