Shayne
Thu Mar 20 21:48:38 CDT 2008
On Mar 20, 7:11=A0pm, Shayne <raz...@gmail.com> wrote:
> On Mar 19, 11:20=A0am, Tom Lavedas <tglba...@cox.net> wrote:
>
>
>
> > On Mar 19, 12:33 pm, Shayne <raz...@gmail.com> wrote:
>
> > > On Mar 19, 6:26 am, Tom Lavedas <tglba...@cox.net> wrote:
>
> > > > On Mar 19, 5:11 am, Shayne <raz...@gmail.com> wrote:
>
> > > > > I am trying to create a script that allows a user to start and sto=
p a
> > > > > service on a remote computer.
>
> > > > > I am having troubles with spaces in the command.
>
> > > > > Here is what I have so far.
> > > > > I am having troubles with line following Case "1" and Case "2"
>
> > > > > Any advice would be greatly appreciated.
>
> > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > > > > Option Explicit
>
> > > > > Dim objmenu, username, wshshell, fso
> > > > > Set WshShell =3D WScript.CreateObject("WScript.Shell")
> > > > > Set fso =3D CreateObject("Scripting.FileSystemObject")
>
> > > > > Username =3D InputBox("Enter your admin username (domain\username)=
",
> > > > > "Enter Username")
> > > > > 'create an object from the gui_menu class
> > > > > Set objmenu =3D New gui_menu
> > > > > 'start the application
> > > > > objmenu.getInput
>
> > > > > Class gui_menu
> > > > > =A0 =A0 private Input, quit, strText, cmd, arrMenu, i, return, str=
Prog
>
> > > > > =A0 =A0 Private Sub pickInput
> > > > > =A0 =A0 =A0 =A0 'if you add anything to the menu array below, make=
sure you
> > > > > add a corresponding entry here
> > > > > =A0 =A0 =A0 =A0 Select Case Input
> > > > > =A0 =A0 =A0 =A0 =A0 =A0 Case "1"
>
> > > > '
> > > > ' I believe this is what you need ...
> > > > =A0 cmd =3D " ""sc \\remotecomputer stop ""Service with spaces in
> > > > name"""""
> > > > ' Escape the quotes around the service name and then around the
> > > > ' whole command as well.> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 startProg =
cmd
> > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 WScript.Sleep(22000)
> > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 getInput
> > > > > =A0 =A0 =A0 =A0 =A0 =A0 Case "2"
>
> > > > '
> > > > ' I believe this is what you need ...
> > > > =A0 cmd =3D " ""sc \\remotecomputer start ""Service with spaces in
> > > > name"""""
> > > > ' Watch for word wrap. =A0The statement between the comments is all =
one
> > > > ' line of code
> > > > '
>
> > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 startProg cmd
> > > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 getInput
> > > > {snip}
> > > > > =A0 =A0 Private Sub startProg(cmd)
> > > > > =A0 =A0 =A0 =A0 =A0return =3D WshShell.Run("%windir%\system32\runa=
s.exe /user:" &
> > > > > username & cmd, 1, False)
> > > > > =A0 =A0 End Sub 'startProg
> > > > > End Class 'gui_menu
> > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > > > See comment inline above ...
>
> > > > Tom Lavedas
> > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://members.cox.net/tglbatch/wsh=
/-Hidequotedtext -
>
> > > > - Show quoted text -
>
> > > Thanks for the quick response.
>
> > > I would've thought that as well, but when I do that, the quotes are
> > > singling line termination or command termination.
> > > When I copy you command in, or put quotes between STOP and Service
> > > with Spaces
> > > I get
>
> > > Script: path to scritpt
> > > Line: 33
> > > Char 56
> > > Errror: Unterminated string constant
> > > Code: 800A0409
> > > Source: Microsoft VBScript compilation error
>
> > Ok, I just went and looked at the help for runas. =A0It uses a backslash=
> > as the escape character (JScript like). =A0The example was ...
>
> > =A0runas /env /user:u...@domain.microsoft.com "notepad \"my file.txt\""
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0note backslash^ =A0 =A0 =A0 =A0and ^
>
> > That means the string probably needs to be ...
>
> > =A0cmd =3D " ""sc \\remotecomputer start \"Service with spaces in name
> > \""""
>
> > I hope it doesn't also need to escape backslashes. =A0Another example
> > given suggests that it does NOT.
>
> > Also, AFAIK the user is still going to have to supply the proper
> > password - which might be problematic. =A0I don't use runas, but IIRC it=
> > does not accept redirection of the password and I don't remember the
> > WSHShell Run method's console window allowing user interaction. =A0I
> > don't *know* that is a problem (or have a solution to suggest), but
> > offer my tiny bit of information for what it's worth.
>
> > Tom Lavedas
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://members.cox.net/tglbatch/wsh/
>
> Thanks,
> I tried that.
> Here are the variations which by the way did not work.
>
> cmd =3D " ""sc \\servername stop \"VMware NAT Service\""""
> cmd =3D " ""sc \\servername stop "VMware NAT Service""""
> cmd =3D " ""sc \\servername stop \VMware NAT Service\"""
>
> Don't mind the service name, it is the only service I have with
> spaces, to experiment on.
>
> As for the password, I am trying to keep it somewhat secure, in the
> sense of not having it prefilled in the file. But yet having a user
> know it unfortunately.
Ok I figured it out.
With your input, I continued looking into it.
It wasn't so much that the vbs was wrong as it was the command I was
issuing was not working at all.
Here what I was trying to issue.
runas /user:domain\user sc \\servername stop "service with spaces in
name"
That fails if typed and ran from a command line.
So working with what you provided me, and another collegues input.
I toyed with the command in the command prompt till it worked.
which is.
runas /user:domain\user "sc \\servername stop \"service with spaces in
name"\"
So with that in mind, I figured out the line I needed in my script.
cmd =3D " ""sc \\serername stop \""service with spaces in name""\"" "
Thanks again for all the input!
Shayne.