Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


objShell.Run vs objShell.Exec

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,34590
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> objShell.Run vs objShell.Exec
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 objShell.Run vs objShell.Exec - 5/17/2006 4:42:23 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
Ya just have to love Microsoft for this one.
objShell.Run (window control)
objShell.Exec (NO window control)

If only one could use objShell.Exec and stop the command windows from coming up.
I'm scanning a subnet that has 254 addresses it does this very very fast!
The command window blink gives me a head ache, I have to turn away from the computer.

Anyone have a way to do this, running in the background or something.

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF
 
 
Post #: 1
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 4:52:51 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Why can't you use .Run? " I'm scanning a subnet that has 254 addresses it does this very very fast!" What do you mean by scanning? Could you post your code?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcds99)
 
 
Post #: 2
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 4:53:30 AM   
  Country73


Posts: 716
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Add this to the beginning of your code:

If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
   oShell.Run "cscript """ & WScript.ScriptFullName & """", 0, False
   WScript.Quit
End If


Change to 0 to a 1 if you want the CMD Window visible


(in reply to mcds99)
 
 
Post #: 3
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 4:57:29 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
If I run it as a cscript (why didn't I think of that before I posted)

Problem not solved within the script.
or can I call an external script from within a script and have it run in cscript?

Would be nice to make this work without changeing the default script type...

Would this be possible to do if I wrapped it with an HTA program?   hmmmm...

A batch file would work but... yuck

Any Ideas would be wonderful!

TIA

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to mcds99)
 
 
Post #: 4
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 5:01:01 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
The Code :-)

I know I only need 1 filesystem object it just helps me keep it all straight.


      

Added the "/" to enclose your code - [ / code ]

< Message edited by Country73 -- 5/17/2006 5:04:09 AM >


_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to mcds99)
 
 
Post #: 5
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 5:31:45 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
This is not valid:

objShell.Run command, command2

You must do it like this:

objShell.Run command, 0, True

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to mcds99)
 
 
Post #: 6
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 1:37:06 PM   
  netxman

 

Posts: 104
Score: 0
Joined: 8/1/2005
Status: offline
 
We have talked about this two functions.

No way to evade the command prompt window when using objShell.Exec.

Our solution is use a temp txtfile too.

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: objShell.Run vs objShell.Exec - 5/17/2006 11:34:26 PM   
  Country73


Posts: 716
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
So you're telling me that what I posted DOES NOT hide the command window when using objShell.Exec?

(in reply to netxman)
 
 
Post #: 8
 
 RE: objShell.Run vs objShell.Exec - 5/18/2006 3:10:07 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
I used a wrapper ;-)

first I created a file "file.cmd" in this file is "cscript script.vbs"

Then I created a shortcut and ran it minimized

it works

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to Country73)
 
 
Post #: 9
 
 RE: objShell.Run vs objShell.Exec - 5/21/2006 1:52:24 PM   
  netxman

 

Posts: 104
Score: 0
Joined: 8/1/2005
Status: offline
Country73, try mcds99's method.

(in reply to mcds99)
 
 
Post #: 10
 
 RE: objShell.Run vs objShell.Exec - 5/22/2006 12:35:25 AM   
  Country73


Posts: 716
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
???

(in reply to netxman)
 
 
Post #: 11
 
 RE: objShell.Run vs objShell.Exec - 5/23/2006 2:17:32 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
To hide the command prompt windows (stop them from flashing) I used a "wrapper".
Insted of running the script using wscript I use cscript.
To do this you need to create a text file myfile.bat or myfile.cmd
   I use .cmd as the filename extension because it runs in 32bit mode.
   That, and we have W2K3 64 bit and XP 64 bit machines (btw XP64 is the bomb!)
Most vbscripts will run at the command line "cscript" just fine
so the line in the file "cscript myscript.vbs" runs in 1 command prompt window (no flashing)
I use an Shortcut to supress the 1 command prompt window by running it minimized.

The myfile.cmd is wrapped around the myscript.vbs, or myscript.vbs runs from myfile.cmd




_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to Country73)
 
 
Post #: 12
 
 RE: objShell.Run vs objShell.Exec - 5/23/2006 8:59:54 AM   
  Country73


Posts: 716
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
That's fine; if you want to go through all of that, or you can just put those four lines that I posted, into your script and it forces it to run in cscript with no CMD window.

Whichever is your preference.

(in reply to mcds99)
 
 
Post #: 13
 
 RE: objShell.Run vs objShell.Exec - 8/24/2007 2:15:11 AM   
  jpook

 

Posts: 30
Score: 0
Joined: 3/7/2007
Status: offline
I'm new & you say put this at the start of the code?
=========================================================================
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
  oShell.Run "cscript """ & WScript.ScriptFullName & """", 0, False
  WScript.Quit
End If
=========================================================================

How would that work with this... Not looking for you to do it for me, but can you point me in the right direction.

=========================================================================
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
Dim localIP : localIP = ResolveIP(objNetwork.ComputerName) ' <span class="high">Get</span> local ip by calling function below
Dim arrIPOct : arrIPOct = Split(localIP, ".") ' create an array out of the IP

Select Case arrIPOct(2) ' look at the value for the network x.x.X.x
Case "105"
    WScript.Echo "location 1: x..105.x"
Case "107"
    WScript.Echo "location 2: x.x.107.x"
Case "106"
    WScript.Echo "location 3: x.x.106.x"
Case "104"
    WScript.Echo "location 4: x.x.104.x"
End Select

Function ResolveIP(computerName)

Dim objShell  :  Set objShell = CreateObject("WScript.Shell")
Dim objExec   :  Set objExec = objShell.Exec("ping " & computerName & " -n 1")
Dim RegEx     :  Set RegEx = New RegExp
RegEx.Pattern = "\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]"
RegEx.IgnoreCase = True
RegEx.Global = True
ResolveIP = RegEx.Execute(objExec.StdOut.ReadAll)(0).Submatches(0)
End Function
========================================================================

(in reply to Country73)
 
 
Post #: 14
 
 RE: objShell.Run vs objShell.Exec - 8/27/2007 6:54:03 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
ObjShell.Run does not do standard output like ObjShell.Exec.
If you want output you need to use ObjShell.Exec

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to jpook)
 
 
Post #: 15
 
 RE: objShell.Run vs objShell.Exec - 8/27/2007 7:11:14 AM   
  ehvbs

 

Posts: 2106
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
You could use DiGiTAL.SkReAM's function:

   http://www.visualbasicscript.com/fb.aspx?m=42892

(in reply to mcds99)
 
 
Post #: 16
 
 RE: objShell.Run vs objShell.Exec - 8/27/2007 11:22:23 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Another way to ping it using exec function


      

(in reply to ehvbs)
 
 
Post #: 17
 
 RE: objShell.Run vs objShell.Exec - 8/28/2007 7:52:36 AM   
  mcds99


Posts: 429
Score: 4
Joined: 2/28/2006
Status: offline
I've had odd results from the wmiPing, I think the script runs so fast it doesn't give the wmiping time to finish.

The regular ping takes a long time, I like the wmiPings speed.

+'s and -'s in everything.

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to gdewrance)
 
 
Post #: 18
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> objShell.Run vs objShell.Exec Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts