[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 20981
  • Last Modified:

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

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
Grime121
Asked:
Grime121
  • 4
  • 3
  • 2
1 Solution
 
untardedCommented:
Call Shell("cmd.EXE" /s [commands here], vbHide)
0
 
untardedCommented:
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
 
David LeeCommented:
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
Independent Software Vendors: 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!

 
Grime121Author Commented:
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
 
Grime121Author Commented:
that one isn't for VB script I don't think, bluedevilfan. It's not liking the 'As New WshSell' line.
0
 
Grime121Author Commented:
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
 
David LeeCommented:
Doh!  Sorry, I keep forgetting to remove VB things from VBScript posts.
0
 
untardedCommented:
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
 
Grime121Author Commented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now