Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to add a variable to a shell command in a vbscript

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-04-2008
Dee
 
Posts: n/a
How to add a variable to a shell command in a vbscript

Hello

I'm trying to add a variable to a shell command in a vb scirpt.
(Newish to scripting)


I want to get the IP address, MasK and Gateway inputs and add them to the
shell command as in the below command.

CODE


Sub Manual_IP
ipAnswer = window.prompt("Please enter your IP address")
maskAnswer = window.prompt("Please enter the mask")
gatewayAnswer = window.prompt("Please enter the gateway IP address")
strIPHost=ipAnswer
strmaskHost=strAnswer
strgateway=gatewayAnswer
Set WShell = CreateObject("WScript.Shell")
WShell.exec("netsh interface ip set address local static strIPHost
strmaskHost strgateway 1")

end sub


My question is can this be done, or am I missing thre syntax for putting the
variables into the command.

any suggestions?

Thanks
D

--
Dee

Reply With Quote
  #2  
Old 28-04-2008
Pegasus \(MVP\)
 
Posts: n/a
Re: How to add a variable to a shell command in a vbscript


"Dee" <Dee@discussions.microsoft.com> wrote in message
news:95294E76-9BDA-4E5C-A235-A15BE9AFE8A6@microsoft.com...
> Hello
>
> I'm trying to add a variable to a shell command in a vb scirpt.
> (Newish to scripting)
>
>
> I want to get the IP address, MasK and Gateway inputs and add them to the
> shell command as in the below command.
>
> CODE
>
>
> Sub Manual_IP
> ipAnswer = window.prompt("Please enter your IP address")
> maskAnswer = window.prompt("Please enter the mask")
> gatewayAnswer = window.prompt("Please enter the gateway IP address")
> strIPHost=ipAnswer
> strmaskHost=strAnswer
> strgateway=gatewayAnswer
> Set WShell = CreateObject("WScript.Shell")
> WShell.exec("netsh interface ip set address local static strIPHost
> strmaskHost strgateway 1")
>
> end sub
>
>
> My question is can this be done, or am I missing thre syntax for putting
> the
> variables into the command.
>
> any suggestions?
>
> Thanks
> D
>
> --
> Dee


In VB Script you can obtain user input like so:

strIP = InputBox("Please enter your IP address")

The user's input is now stored in strIP. Might be a good
idea to download script56.chm for the basic stuff.


Reply With Quote
  #3  
Old 28-04-2008
Tom Lavedas
 
Posts: n/a
Re: How to add a variable to a shell command in a vbscript

On Apr 28, 10:52 am, Dee <D...@discussions.microsoft.com> wrote:
> Hello
>
> I'm trying to add a variable to a shell command in a vb scirpt.
> (Newish to scripting)
>
> I want to get the IP address, MasK and Gateway inputs and add them to the
> shell command as in the below command.
>
> CODE
>
> Sub Manual_IP
> ipAnswer = window.prompt("Please enter your IP address")
> maskAnswer = window.prompt("Please enter the mask")
> gatewayAnswer = window.prompt("Please enter the gateway IP address")
> strIPHost=ipAnswer
> strmaskHost=strAnswer
> strgateway=gatewayAnswer
> Set WShell = CreateObject("WScript.Shell")
> WShell.exec("netsh interface ip set address local static strIPHost
> strmaskHost strgateway 1")
>
> end sub
>
> My question is can this be done, or am I missing thre syntax for putting the
> variables into the command.
>
> any suggestions?
>
> Thanks
> D
>
> --
> Dee


As shown, the problem with the Exec statement is that the command is a
string literal. It needs to be constructed as a mixture of literal
strings and the contents of your string variables, something like
this ...

WShell.exec "netsh interface ip set address local static " _
& strIPHost & " " & strmaskHost & " " & strgateway & " 1"

Personally, I would use the Run method in place of the Exec, as you
can avoid the command console window flashing on the screen. Since
you are not trying to actively control underlying application, it
seems like a little cleaner approach ...

WShell.Run "netsh interface ip set address local static " _
& strIPHost & " " & strmaskHost & " " & strgateway & " 1", 0, True

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Reply With Quote
  #4  
Old 28-04-2008
Dee
 
Posts: n/a
Re: How to add a variable to a shell command in a vbscript

Thats great, many thanks for your help

D
--
Dee


"Tom Lavedas" wrote:

> On Apr 28, 10:52 am, Dee <D...@discussions.microsoft.com> wrote:
> > Hello
> >
> > I'm trying to add a variable to a shell command in a vb scirpt.
> > (Newish to scripting)
> >
> > I want to get the IP address, MasK and Gateway inputs and add them to the
> > shell command as in the below command.
> >
> > CODE
> >
> > Sub Manual_IP
> > ipAnswer = window.prompt("Please enter your IP address")
> > maskAnswer = window.prompt("Please enter the mask")
> > gatewayAnswer = window.prompt("Please enter the gateway IP address")
> > strIPHost=ipAnswer
> > strmaskHost=strAnswer
> > strgateway=gatewayAnswer
> > Set WShell = CreateObject("WScript.Shell")
> > WShell.exec("netsh interface ip set address local static strIPHost
> > strmaskHost strgateway 1")
> >
> > end sub
> >
> > My question is can this be done, or am I missing thre syntax for putting the
> > variables into the command.
> >
> > any suggestions?
> >
> > Thanks
> > D
> >
> > --
> > Dee

>
> As shown, the problem with the Exec statement is that the command is a
> string literal. It needs to be constructed as a mixture of literal
> strings and the contents of your string variables, something like
> this ...
>
> WShell.exec "netsh interface ip set address local static " _
> & strIPHost & " " & strmaskHost & " " & strgateway & " 1"
>
> Personally, I would use the Run method in place of the Exec, as you
> can avoid the command console window flashing on the screen. Since
> you are not trying to actively control underlying application, it
> seems like a little cleaner approach ...
>
> WShell.Run "netsh interface ip set address local static " _
> & strIPHost & " " & strmaskHost & " " & strgateway & " 1", 0, True
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>

Reply With Quote
  #5  
Old 28-04-2008
Dee
 
Posts: n/a
Re: How to add a variable to a shell command in a vbscript

Many thanks
D
--
Dee


"Pegasus (MVP)" wrote:

>
> "Dee" <Dee@discussions.microsoft.com> wrote in message
> news:95294E76-9BDA-4E5C-A235-A15BE9AFE8A6@microsoft.com...
> > Hello
> >
> > I'm trying to add a variable to a shell command in a vb scirpt.
> > (Newish to scripting)
> >
> >
> > I want to get the IP address, MasK and Gateway inputs and add them to the
> > shell command as in the below command.
> >
> > CODE
> >
> >
> > Sub Manual_IP
> > ipAnswer = window.prompt("Please enter your IP address")
> > maskAnswer = window.prompt("Please enter the mask")
> > gatewayAnswer = window.prompt("Please enter the gateway IP address")
> > strIPHost=ipAnswer
> > strmaskHost=strAnswer
> > strgateway=gatewayAnswer
> > Set WShell = CreateObject("WScript.Shell")
> > WShell.exec("netsh interface ip set address local static strIPHost
> > strmaskHost strgateway 1")
> >
> > end sub
> >
> >
> > My question is can this be done, or am I missing thre syntax for putting
> > the
> > variables into the command.
> >
> > any suggestions?
> >
> > Thanks
> > D
> >
> > --
> > Dee

>
> In VB Script you can obtain user input like so:
>
> strIP = InputBox("Please enter your IP address")
>
> The user's input is now stored in strIP. Might be a good
> idea to download script56.chm for the basic stuff.
>
>
>

Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to add a variable to a shell command in a vbscript"
Thread Thread Starter Forum Replies Last Post
Change shell variable on Linux mint Athreya Operating Systems 3 11-01-2011 06:55 PM
Retrieve the result of a DOS command in a variable Kieran Operating Systems 3 30-01-2010 05:53 AM
Affected shell variable in awk John Wilson Software Development 5 23-12-2009 01:04 PM
How to suppress command prompt in vbscript vivekmohan Software Development 2 14-07-2009 10:30 AM
autorun.inf - shell\..\command with command line parameter doesn'twork kakii Windows XP Support 1 18-05-2007 01:24 AM


All times are GMT +5.5. The time now is 07:50 AM.