Solved

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

Posted on 2004-10-01
9
20,259 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
ID: 12201621
Call Shell("cmd.EXE" /s [commands here], vbHide)
0
 
LVL 1

Expert Comment

by:untarded
ID: 12201660
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
ID: 12201907
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Grime121
ID: 12201923
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
 
LVL 1

Author Comment

by:Grime121
ID: 12201951
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
ID: 12201981
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
ID: 12202013
Doh!  Sorry, I keep forgetting to remove VB things from VBScript posts.
0
 
LVL 1

Expert Comment

by:untarded
ID: 12202117
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
ID: 12202337
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

749 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