How do you execute a command-line program, and return the results into a variable? 
Author Message
 How do you execute a command-line program, and return the results into a variable?

Example:

I want to execute regread.exe (nt resource kit) from WshShell.Run, and have
it return the results into a variable.

Any help would be appreciated.  Thanks.



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
You might be better off using VBS's registry reading methods or the
REGOBJ.DLL fuctions.  You can find information at
http://cwashington.netreach.net

Good Luck,
Matt

Quote:
> Example:

> I want to execute regread.exe (nt resource kit) from WshShell.Run, and
have
> it return the results into a variable.

> Any help would be appreciated.  Thanks.



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
Well, I am running this script from one machine to poll information for
every computer in the domain.  WshShell.RegRead only returns values in the
context of the computer that executes the script.  The "regread.exe" utility
(nt reskit) allows me to issue a WshShell.Run("Regread.exe \\computername"),
and return the value.  This value is displayed in the command window, but I
need to forward the value into a variable.


Quote:
>You might be better off using VBS's registry reading methods or the
>REGOBJ.DLL fuctions.  You can find information at
>http://cwashington.netreach.net

>Good Luck,
>Matt



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
You'll need to create a temp workfile and

Shell.Run "%comspec% /c regread.exe " & machineandkey & " > workfile.txt",0,True

then read workfile.txt.

FWIW, RegObj.dll (the RegObj.Registry object) supports remote registry access.  It's an officially
unsupported MS download for VB but can be found at

Win32 Scripting [Clarence Washington]
http://cwashington.netreach.net
http://cwashington.netreach.net/script_repository/repository.asp
http://cwashington.netreach.net/script_repository/query.asp
http://cwashington.netreach.net/main_site/downloads
http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq
http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq

--
Michael Harris
MVP Scripting


Well, I am running this script from one machine to poll information for
every computer in the domain.  WshShell.RegRead only returns values in the
context of the computer that executes the script.  The "regread.exe" utility
(nt reskit) allows me to issue a WshShell.Run("Regread.exe \\computername"),
and return the value.  This value is displayed in the command window, but I
need to forward the value into a variable.


Quote:
>You might be better off using VBS's registry reading methods or the
>REGOBJ.DLL fuctions.  You can find information at
>http://cwashington.netreach.net

>Good Luck,
>Matt



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
Don't know anything about Regread.exe, but have you tried:

MyVar = WshShell.Run("Regread.exe \\computername")
MsgBox MyVar

--

Bill James
Microsoft MVPDTS

?Free Win9x VBScript Utilities?
http://home.earthlink.net/~wgjames/vbspage/

Quote:

> Well, I am running this script from one machine to poll information for
> every computer in the domain.  WshShell.RegRead only returns values in the
> context of the computer that executes the script.  The "regread.exe" utility
> (nt reskit) allows me to issue a WshShell.Run("Regread.exe \\computername"),
> and return the value.  This value is displayed in the command window, but I
> need to forward the value into a variable.



> >You might be better off using VBS's registry reading methods or the
> >REGOBJ.DLL fuctions.  You can find information at
> >http://cwashington.netreach.net

> >Good Luck,
> >Matt



Sun, 10 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
Hi,
sorry to interrupt, but I'm trying to solve pretty much the exact same
problem. I'm using Excel7.0's VBscript module to create a custom function.
Here's the content of my VBScript:

'***
Function MyFunc(num)
MyFunc = Shell("c:\jdk1.2.2\bin\java.exe Return " & num, 1)
End Function

Sub test()
MsgBox MyFunc(234)
End Sub
'***

Basically, Return is a java program that takes the parameter num.
I know this executes properly because I can see the DOSwindow pop up with
the right result. I, however, want to capture that result and store it in
MyFunc. (Right now the command I have returns stuff like -98263157, but I
think that has more to do with the shell itself than my program?). I tried,
as you suggested (modified for my purposes):

MyFunc = 3D WshShell.Run("c:\jdk1.2.2\bin\java.exe Return " & num)

but the Script editor highlights the 3D and tells me "Expected: End of
Statement"so I'm assuming it's not proper syntax.

I also tried just Shell.Run(...), to which it replied "arguments not
optional" [maybe I have the method signature wrong? what is it in that
case?].

I understand programming well, but am a novice at VB. Please Help, and
don't be afraid to get technical.

thanks,

-Yudes

p.s. also, I have posted other questions to Cnet, but nothing has ever
showed up  in my member database, let alone "Open Questions." Once I post
the questions, they disappear. What gives?!

Quote:

> Don't know anything about Regread.exe, but have you tried:

> MyVar =3D WshShell.Run("Regread.exe \\computername")
> MsgBox MyVar

> --=20

> Bill James
> Microsoft MVPDTS

> Free Win9x VBScript Utilities
> http://home.earthlink.net/~wgjames/vbspage/

--
Posted via CNET Help.com
http://www.help.com/


Fri, 22 Nov 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
dim wshelll, retval
set wshell = createobject("WScript.Shell")
retval = wshell.run ("regread.exe",,true)
msgbox "Regread returned " & cstr(retval)

hth

Brock Weaver
Web App Developer


Quote:
> Example:

> I want to execute regread.exe (nt resource kit) from WshShell.Run, and
have
> it return the results into a variable.

> Any help would be appreciated.  Thanks.



Thu, 19 Dec 2002 03:00:00 GMT  
 How do you execute a command-line program, and return the results into a variable?
hi Brock,

In the example you gave, what you are getting back is a "system error code"
which was set by the program, if any.  I suppose you could communicate with
your program by setting "system error codes", but then that is not the usual
practice.

If you are writing your own app, the most professional approach would be to
use ole automation, and have your app pass back results through an object's
methods and properties.

If the ole automation approach is not feasible, then the alternative
approach might be to write your results to a file.  Then you use fso the
connect to the file, read the results, parse out the info you want and stick
it into a variable.

cheers, jw


Quote:
> dim wshelll, retval
> set wshell = createobject("WScript.Shell")
> retval = wshell.run ("regread.exe",,true)
> msgbox "Regread returned " & cstr(retval)

> hth

> Brock Weaver
> Web App Developer



> > Example:

> > I want to execute regread.exe (nt resource kit) from WshShell.Run, and
> have
> > it return the results into a variable.

> > Any help would be appreciated.  Thanks.



Fri, 20 Dec 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. How do you execute a command-line program, and return the results into a variable

2. Execute command line program from VBScript

3. How to execute a command line command from a *.HTA

4. return the result text from a VB ADODB.Connection.Execute command

5. use the result of the VBS for other application under the command line

6. Piping results of command line call to file from ASP

7. Piping results of command line call to file from ASP

8. How do you execute a Command line App inside a VB program

9. executing vb programs using command line parameters

10. Executing command line program from VB 5 application under Windows XP environmen

11. Execute command line program from VB

12. How do I execute command line programs from within VB

 

 
Powered by phpBB® Forum Software