Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Newbie Question - Quotes within a objShell.exec

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Newbie Question - Quotes within a objShell.exec
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Newbie Question - Quotes within a objShell.exec - 3/10/2008 12:17:42 PM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Hi,

I'm trying to create a script that uses imagex, MS's image creating tool, but part of the script requires a path that has spaces in it.

Right now, i have objShell.Exec("X:\Imagex.exe /apply 'Y:\Operating Systems\Vista Reference Image\VistaImage.wim' 1 C:")

Now, the line when written normally would be

X:\Imagex.exe /apply "Y:\Operating Systems\Vista Reference Image\VistaImage.wim" 1 C:

Was i correct in my use of single quotes? or do i need to do it a different way?

Thanks,
Jason
 
 
Post #: 1
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 12:24:28 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Have you looked at the Frequently Asked Stuff post? ....towards the end of the post you'll find what you need...it is using the Run method, but the same applies to the Exec method.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 2
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 12:47:13 PM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Thanks dm_4ever. Actually i did. But the part that confused me was how it applies to switches eg: /apply etc...since they require seperate quotes, it seems a little more confusing than the simple execution string either using AddQuotes or using double quotes.

(in reply to GreatBarrier86)
 
 
Post #: 3
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 1:21:46 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
WScript.Echo "X:\Imagex.exe /apply " & AddQuotes("Y:\Operating Systems\Vista Reference Image\VistaImage.wim") & " 1 C:"

Function AddQuotes(strText)
   AddQuotes = Chr(34) & strText & Chr(34)
End Function

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 4
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 1:30:36 PM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Thanks, man that was confusing. So, do i not need parethesis around the entire statement? i thought the requirement was .exec(......)

< Message edited by GreatBarrier86 -- 3/10/2008 1:35:40 PM >

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 2:28:53 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Are you simply trying to run the command or is there an output you intend on catching and using in your script?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 6
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 3:17:51 PM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
I am just trying to run the command.

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 3:37:29 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
In that case I would suggest using the Run method

Dim objShell : Set objShell = CreateObject("WScript.Shell")
objShell.Run "X:\Imagex.exe /apply " & AddQuotes("Y:\Operating Systems\Vista Reference Image\VistaImage.wim") & " 1 C:"

Function AddQuotes(strText)
   AddQuotes = Chr(34) & strText & Chr(34)
End Function

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 8
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 4:34:29 PM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Ok. Why Run and not exec?

(in reply to dm_4ever)
 
 
Post #: 9
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/10/2008 11:30:23 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Look at this:

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

for a discussion of " in string literals.

I'd like to ask the question "Why .Run instead of .Exec?" too.

(in reply to GreatBarrier86)
 
 
Post #: 10
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 12:20:16 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Here is how I feel about .Run vs. .Exec. I always use .Run when possible because I can hide any command prompt window in the background. The exception is when I need to interact with the command prompt that is created. In that case I use .Exec.

_____________________________

"... 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 ehvbs)
 
 
Post #: 11
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 1:21:56 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
quote:


Exec Method:
Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams


Since GreatBarrier86 has no need to StdIn, StdOut, or StdErr then I don't see a need to use it...plus I agree with what ebgreen mentioned as well...you can easily hide the command prompt window with the Run method.  In the last two weeks or so there has been at least 2 people who have asked how they can hide the command prompt when they use the Exec method....in the end they both get the job done and it may be a matter of personal preference.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to GreatBarrier86)
 
 
Post #: 12
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 2:49:27 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
I actually like the double quotes concept. Less code required, if you think about it. So for the double quotes, this would work out?

objShell.Run("X:\Imagex.exe /apply ""Y:\Operating Systems\Vista Reference Image\VistaImage.wim"" 1 C:")

(in reply to GreatBarrier86)
 
 
Post #: 13
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 2:58:22 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi GreatBarrier86,

the quoting looks ok to me; but I don't like the wrong/misleading parameter list
() in your statement. You don't use parameter list (), if you call a Sub in VBScript.

If - later - you'll add a "how to show the window" and/or a "do I wait for the process
to terminate" parameter

  objShell.Run sCmd, 0, True

you'll come to grief with ().

Regards

ehvbs

(in reply to GreatBarrier86)
 
 
Post #: 14
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 3:51:14 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Ehvbs,

what do you mean? i was wondering that myself? I thought you had to use it.

I noticed that () does not work with MapNetworkDrive method.

(in reply to ehvbs)
 
 
Post #: 15
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 4:27:00 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi GreatBarrier86,

in many languages you'l have to enclose the list of arguments to a function (sub, method,
procedure, ..) in parameter list (). In VBScript such () are allowed only if you assign the
return value of the called code to a variable.

If you look at the "MapNetworkDrive Method" topic in the VBScript Docs, you'll see that
the first presentation

  object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword])

is wrong/misleading (probably because the documenters were in JScript mode). The sample is
correct:

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "E:", "\\Server\Public"

If you add those () here, you'll get a "Cannot use parentheses when calling a Sub" error.

This nasty peculiarity of VBScript syntax is blurred by

  (a) the Call keyword - if you use Call, you must use parameter list ()

  (b) the use of "pass me by value" parentheses: if you want to pass an argument
       by value, you put it in ():

        Dim WshNetwork : Set WshNetwork = WScript.CreateObject("WScript.Network")
         Dim sDrive : sDrive = "E:"
        WshNetwork.MapNetworkDrive (sDrive), "\\Server\Public"

      is syntactically correct (while not very useful/senseful).

         WShell.Run ( sCmd )

     
will 'work', but the () doesn't mean, what the unaware may think.

Putting those () in a Sub call is a F:requently D:one E:rror; that's why I use every
opportunity to point this out (I beg the pardon of regular readers/posters).

Thanks for your insistence on an explanation (and providing me with an
opportunity to be pedantic)

ehvbs

 

(in reply to GreatBarrier86)
 
 
Post #: 16
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 4:40:07 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Wow that really is misleading.

One last question. What is the difference between VBScript and Wsf? Is one newer? Is using VBScript old and out of date?

(in reply to ehvbs)
 
 
Post #: 17
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 4:48:01 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
WSF files are essentially a way to bundle your scripts together into one file. Since WSF files are script engine agnostic, you can put any script into them that you have a valid engine installed for. So in one WSF file you could have a VBSCript, a jscript, and a perl script (assuming you have perl installed) living side by side and you could execute any of them from the command prompt by calling the WSF file and giving it a parameter that indicates which script(s) to run. I do not know if WSF files support powershell or not, but I may try to find out if I have time.

_____________________________

"... 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 GreatBarrier86)
 
 
Post #: 18
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 4:52:37 AM   
  GreatBarrier86

 

Posts: 71
Score: 0
Joined: 3/10/2008
Status: offline
Oh i see. Well i dont think WSF files support PS. for that, i just use ps1, obviously. So, as i continue to develop vbscripts, what file extension is appropriate? WSF? I've heard VBScript isn't being developed anymore.

(in reply to ebgreen)
 
 
Post #: 19
 
 RE: Newbie Question - Quotes within a objShell.exec - 3/11/2008 5:01:12 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
I have confirmed that powershell is not currently supported in WSF files. I would expect that to change.

If you are writing VBS then use.vbs. The WSF file is XML that encapsulates VBS, Jscript, or Perl script. Just saving a file with a .wsf does not make it a WSF file. As for further VBScript development, there will not be a new version of the script engine unless one is required for critical bugs or security reasons. So basically no new development. If you have the ability to do so in your environment then I would recommend powershell. I do all new development that I can within my environment (we don't have it on all clients yet) in powershell.

_____________________________

"... 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 GreatBarrier86)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

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 >> Newbie Question - Quotes within a objShell.exec Page: [1] 2   next >   >>
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