From: Firewalker82 on
Hi all,

I am trying to run a simple script that opens the cmd shell on a remote
computer. I have two scripts; the first script asks for the computer to run
the script on and the script to run on that remote computer and the second
script is the script that is run and called by script 1. below is script 1;

----------------------------------------------------------------------------------------
Dim Controller, RemoteScript, strcomputer, text1, wshshell, oexec 'Variables
Set Controller = WScript.CreateObject("WSHController")
text1 = "You did not enter a computer name!"
Set WshShell = CreateObject("WScript.Shell")
strscriptloc = "C:\scripts\cmdexec.vbs"

'Ask the user which computer that they would like to run the app on
strcomputer = inputbox("Please enter the computer that you would like to
open the command prompt on.","Open a command box on which computer??")

'If the user didn't enter anything, then close the app gracefully
If strcomputer = "" Then
WScript.Echo Text1
wscript.quit
end if

'check connectivity to the computer before running execution xp / 2003 only
wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer
& "'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)

For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
wscript.echo "Computer is not responding on the network, unable to
continue"
wscript.quit
end if
Next

set RemoteScript = Controller.CreateScript(strscriptloc, strcomputer)
RemoteScript.Execute

Do While RemoteScript.Status <> 2

WScript.Sleep 100
Loop

wscript.disconnectobject remotescript

Sub remotescript_Error
Dim theError
Set theError = remotescript.Error
WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line & ",
Char: " & theError.Character & vbCrLf & "Description: " & theError.Description
WScript.Quit -1
End Sub
--------------------------------------------------------------------------------------------

The second script is as follows;

--------------------------------------------------------------------------------------------

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

wshrun = wshshell.run ("cmd /k")

--------------------------------------------------------------------------------------------

Pretty simple really. The script works on my local machine perfectly, but
when I execute it on a remote machine, nothing, no error message, just
completes and doesnt do a thing. I have added and re-added the remote reg_sz
registry value in the registry with a 1(when I try and run it without a
remote registry value, I get the active x can't create object error, so I
know that the registry value is working correctly). I have registered the
wscript object on the remote machine wscript -regserver, but still no luck,
not even an error?? I am a domain admin and I have all the rights to perform
this script execution on the remote machine also.

can anybody help??

Many thanks
--
Firewalker82
From: Al Dunbar on

"Firewalker82" <Firewalker82(a)discussions.microsoft.com> wrote in message
news:D9853A2E-4132-4442-B774-55FDE958A279(a)microsoft.com...
> Hi all,
>
> I am trying to run a simple script that opens the cmd shell on a remote
> computer. I have two scripts; the first script asks for the computer to
> run
> the script on and the script to run on that remote computer and the second
> script is the script that is run and called by script 1. below is script
> 1;
>
> ----------------------------------------------------------------------------------------
> Dim Controller, RemoteScript, strcomputer, text1, wshshell, oexec
> 'Variables
> Set Controller = WScript.CreateObject("WSHController")
> text1 = "You did not enter a computer name!"
> Set WshShell = CreateObject("WScript.Shell")
> strscriptloc = "C:\scripts\cmdexec.vbs"
>
> 'Ask the user which computer that they would like to run the app on
> strcomputer = inputbox("Please enter the computer that you would like to
> open the command prompt on.","Open a command box on which computer??")
>
> 'If the user didn't enter anything, then close the app gracefully
> If strcomputer = "" Then
> WScript.Echo Text1
> wscript.quit
> end if
>
> 'check connectivity to the computer before running execution xp / 2003
> only
> wmiQuery = "Select * From Win32_PingStatus Where Address = '" &
> strComputer
> & "'"
> Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
> Set objPing = objWMIService.ExecQuery(wmiQuery)
>
> For Each objStatus in objPing
> If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
> wscript.echo "Computer is not responding on the network, unable to
> continue"
> wscript.quit
> end if
> Next
>
> set RemoteScript = Controller.CreateScript(strscriptloc, strcomputer)
> RemoteScript.Execute
>
> Do While RemoteScript.Status <> 2
>
> WScript.Sleep 100
> Loop
>
> wscript.disconnectobject remotescript
>
> Sub remotescript_Error
> Dim theError
> Set theError = remotescript.Error
> WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line & ",
> Char: " & theError.Character & vbCrLf & "Description: " &
> theError.Description
> WScript.Quit -1
> End Sub
> --------------------------------------------------------------------------------------------
>
> The second script is as follows;
>
> --------------------------------------------------------------------------------------------
>
> Dim WshShell, oExec
> Set WshShell = CreateObject("WScript.Shell")
>
> wshrun = wshshell.run ("cmd /k")
>
> --------------------------------------------------------------------------------------------
>
> Pretty simple really. The script works on my local machine perfectly, but
> when I execute it on a remote machine, nothing, no error message, just
> completes and doesnt do a thing. I have added and re-added the remote
> reg_sz
> registry value in the registry with a 1(when I try and run it without a
> remote registry value, I get the active x can't create object error, so I
> know that the registry value is working correctly). I have registered the
> wscript object on the remote machine wscript -regserver, but still no
> luck,
> not even an error?? I am a domain admin and I have all the rights to
> perform
> this script execution on the remote machine also.
>
> can anybody help??

Depends on what, precisely, it is you want to do here. If you think that you
are going to have cmd running on a remote system but running in a command
prompt window on your local system, I don't think that is going to happen
easily. IMHO, assuming the credentials allow it, a cmd.exe process has been
created on the remote machine, but it is stuck in some sort of limbo without
any kind of interface.

If you really want to do this, the simplest way would be to establish a
remote desktop connection to the remote machine.

If you simply want to execute commands against drives on the remote system,
try this command:

pushd \\remotesystem\C$

This will map the C:\ drive of the system noted as the next available local
drive letter.

/Al


From: Firewalker82 on
Al,

Thanks for your reply, although I think maybe I didnt make my original post
clear enough. I do want to open a command window on a remote machine, thats
it. I dont want to have a console on the local computer controlling the
remote computer console (id just use telnet, ssh for that!). I dont want to
use RDP as it isn't really a practical option as we have to view what our
users are experiencing and RDP hides this as it creates a new session (we use
VNC). Users are locked down and prevented from opening a CMD.exe process.
This is why I want to create this script, so that administrators can run it
against any computer under their admin credentials. I know that using
'runas' command on the local computer via a shortcut is an option, but it
involves several tasks and I think that the remote shell vbs script would be
far more efficient. Im hoping to open this up to running many different apps
on the remote computer, but I cant get this to work. Is their any component
security that could be causing a problem with this. Microsoft make it sound
SO EASY, DONT THEY!!

Any further suggestions??
--
Firewalker82


"Al Dunbar" wrote:

>
> "Firewalker82" <Firewalker82(a)discussions.microsoft.com> wrote in message
> news:D9853A2E-4132-4442-B774-55FDE958A279(a)microsoft.com...
> > Hi all,
> >
> > I am trying to run a simple script that opens the cmd shell on a remote
> > computer. I have two scripts; the first script asks for the computer to
> > run
> > the script on and the script to run on that remote computer and the second
> > script is the script that is run and called by script 1. below is script
> > 1;
> >
> > ----------------------------------------------------------------------------------------
> > Dim Controller, RemoteScript, strcomputer, text1, wshshell, oexec
> > 'Variables
> > Set Controller = WScript.CreateObject("WSHController")
> > text1 = "You did not enter a computer name!"
> > Set WshShell = CreateObject("WScript.Shell")
> > strscriptloc = "C:\scripts\cmdexec.vbs"
> >
> > 'Ask the user which computer that they would like to run the app on
> > strcomputer = inputbox("Please enter the computer that you would like to
> > open the command prompt on.","Open a command box on which computer??")
> >
> > 'If the user didn't enter anything, then close the app gracefully
> > If strcomputer = "" Then
> > WScript.Echo Text1
> > wscript.quit
> > end if
> >
> > 'check connectivity to the computer before running execution xp / 2003
> > only
> > wmiQuery = "Select * From Win32_PingStatus Where Address = '" &
> > strComputer
> > & "'"
> > Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
> > Set objPing = objWMIService.ExecQuery(wmiQuery)
> >
> > For Each objStatus in objPing
> > If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
> > wscript.echo "Computer is not responding on the network, unable to
> > continue"
> > wscript.quit
> > end if
> > Next
> >
> > set RemoteScript = Controller.CreateScript(strscriptloc, strcomputer)
> > RemoteScript.Execute
> >
> > Do While RemoteScript.Status <> 2
> >
> > WScript.Sleep 100
> > Loop
> >
> > wscript.disconnectobject remotescript
> >
> > Sub remotescript_Error
> > Dim theError
> > Set theError = remotescript.Error
> > WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line & ",
> > Char: " & theError.Character & vbCrLf & "Description: " &
> > theError.Description
> > WScript.Quit -1
> > End Sub
> > --------------------------------------------------------------------------------------------
> >
> > The second script is as follows;
> >
> > --------------------------------------------------------------------------------------------
> >
> > Dim WshShell, oExec
> > Set WshShell = CreateObject("WScript.Shell")
> >
> > wshrun = wshshell.run ("cmd /k")
> >
> > --------------------------------------------------------------------------------------------
> >
> > Pretty simple really. The script works on my local machine perfectly, but
> > when I execute it on a remote machine, nothing, no error message, just
> > completes and doesnt do a thing. I have added and re-added the remote
> > reg_sz
> > registry value in the registry with a 1(when I try and run it without a
> > remote registry value, I get the active x can't create object error, so I
> > know that the registry value is working correctly). I have registered the
> > wscript object on the remote machine wscript -regserver, but still no
> > luck,
> > not even an error?? I am a domain admin and I have all the rights to
> > perform
> > this script execution on the remote machine also.
> >
> > can anybody help??
>
> Depends on what, precisely, it is you want to do here. If you think that you
> are going to have cmd running on a remote system but running in a command
> prompt window on your local system, I don't think that is going to happen
> easily. IMHO, assuming the credentials allow it, a cmd.exe process has been
> created on the remote machine, but it is stuck in some sort of limbo without
> any kind of interface.
>
> If you really want to do this, the simplest way would be to establish a
> remote desktop connection to the remote machine.
>
> If you simply want to execute commands against drives on the remote system,
> try this command:
>
> pushd \\remotesystem\C$
>
> This will map the C:\ drive of the system noted as the next available local
> drive letter.
>
> /Al
>
>
>
From: Pegasus (MVP) on
If you want to open a command window on a remote machine,
why not use psexec.exe from www.sysinternals.com?


"Firewalker82" <Firewalker82(a)discussions.microsoft.com> wrote in message
news:7C654025-30D6-4C87-9582-18E404829494(a)microsoft.com...
> Al,
>
> Thanks for your reply, although I think maybe I didnt make my original
> post
> clear enough. I do want to open a command window on a remote machine,
> thats
> it. I dont want to have a console on the local computer controlling the
> remote computer console (id just use telnet, ssh for that!). I dont want
> to
> use RDP as it isn't really a practical option as we have to view what our
> users are experiencing and RDP hides this as it creates a new session (we
> use
> VNC). Users are locked down and prevented from opening a CMD.exe process.
> This is why I want to create this script, so that administrators can run
> it
> against any computer under their admin credentials. I know that using
> 'runas' command on the local computer via a shortcut is an option, but it
> involves several tasks and I think that the remote shell vbs script would
> be
> far more efficient. Im hoping to open this up to running many different
> apps
> on the remote computer, but I cant get this to work. Is their any
> component
> security that could be causing a problem with this. Microsoft make it
> sound
> SO EASY, DONT THEY!!
>
> Any further suggestions??
> --
> Firewalker82
>
>
> "Al Dunbar" wrote:
>
>>
>> "Firewalker82" <Firewalker82(a)discussions.microsoft.com> wrote in message
>> news:D9853A2E-4132-4442-B774-55FDE958A279(a)microsoft.com...
>> > Hi all,
>> >
>> > I am trying to run a simple script that opens the cmd shell on a remote
>> > computer. I have two scripts; the first script asks for the computer
>> > to
>> > run
>> > the script on and the script to run on that remote computer and the
>> > second
>> > script is the script that is run and called by script 1. below is
>> > script
>> > 1;
>> >
>> > ----------------------------------------------------------------------------------------
>> > Dim Controller, RemoteScript, strcomputer, text1, wshshell, oexec
>> > 'Variables
>> > Set Controller = WScript.CreateObject("WSHController")
>> > text1 = "You did not enter a computer name!"
>> > Set WshShell = CreateObject("WScript.Shell")
>> > strscriptloc = "C:\scripts\cmdexec.vbs"
>> >
>> > 'Ask the user which computer that they would like to run the app on
>> > strcomputer = inputbox("Please enter the computer that you would like
>> > to
>> > open the command prompt on.","Open a command box on which computer??")
>> >
>> > 'If the user didn't enter anything, then close the app gracefully
>> > If strcomputer = "" Then
>> > WScript.Echo Text1
>> > wscript.quit
>> > end if
>> >
>> > 'check connectivity to the computer before running execution xp / 2003
>> > only
>> > wmiQuery = "Select * From Win32_PingStatus Where Address = '" &
>> > strComputer
>> > & "'"
>> > Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
>> > Set objPing = objWMIService.ExecQuery(wmiQuery)
>> >
>> > For Each objStatus in objPing
>> > If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
>> > wscript.echo "Computer is not responding on the network, unable
>> > to
>> > continue"
>> > wscript.quit
>> > end if
>> > Next
>> >
>> > set RemoteScript = Controller.CreateScript(strscriptloc, strcomputer)
>> > RemoteScript.Execute
>> >
>> > Do While RemoteScript.Status <> 2
>> >
>> > WScript.Sleep 100
>> > Loop
>> >
>> > wscript.disconnectobject remotescript
>> >
>> > Sub remotescript_Error
>> > Dim theError
>> > Set theError = remotescript.Error
>> > WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line &
>> > ",
>> > Char: " & theError.Character & vbCrLf & "Description: " &
>> > theError.Description
>> > WScript.Quit -1
>> > End Sub
>> > --------------------------------------------------------------------------------------------
>> >
>> > The second script is as follows;
>> >
>> > --------------------------------------------------------------------------------------------
>> >
>> > Dim WshShell, oExec
>> > Set WshShell = CreateObject("WScript.Shell")
>> >
>> > wshrun = wshshell.run ("cmd /k")
>> >
>> > --------------------------------------------------------------------------------------------
>> >
>> > Pretty simple really. The script works on my local machine perfectly,
>> > but
>> > when I execute it on a remote machine, nothing, no error message, just
>> > completes and doesnt do a thing. I have added and re-added the remote
>> > reg_sz
>> > registry value in the registry with a 1(when I try and run it without a
>> > remote registry value, I get the active x can't create object error, so
>> > I
>> > know that the registry value is working correctly). I have registered
>> > the
>> > wscript object on the remote machine wscript -regserver, but still no
>> > luck,
>> > not even an error?? I am a domain admin and I have all the rights to
>> > perform
>> > this script execution on the remote machine also.
>> >
>> > can anybody help??
>>
>> Depends on what, precisely, it is you want to do here. If you think that
>> you
>> are going to have cmd running on a remote system but running in a command
>> prompt window on your local system, I don't think that is going to happen
>> easily. IMHO, assuming the credentials allow it, a cmd.exe process has
>> been
>> created on the remote machine, but it is stuck in some sort of limbo
>> without
>> any kind of interface.
>>
>> If you really want to do this, the simplest way would be to establish a
>> remote desktop connection to the remote machine.
>>
>> If you simply want to execute commands against drives on the remote
>> system,
>> try this command:
>>
>> pushd \\remotesystem\C$
>>
>> This will map the C:\ drive of the system noted as the next available
>> local
>> drive letter.
>>
>> /Al
>>
>>
>>


From: Firewalker82 on
Pegasus,

thanks for your reply. Yes we use those tools, but I think that I have
probably misunderstood what wshremote can actually do. I read an article on
the ms site;

http://www.microsoft.com/technet/scriptcenter/topics/remote/rscripting.mspx#ECC

it mentions that;

"The script you deploy to the remote computer must not attempt to interact
with the user interface by using WScript.Echo, MsgBox, InputBox, or similar
functions. The deployed script will not run in an interactive desktop, so
there will be no way for someone to respond to dialog boxes."


I guess in a round-about way that means that you cannot open processes in
the current users environment, such as open applications etc.

I think I may have to resort to the pstools then. What would Microsoft do
without these third party tools?? I am disappointed, but I'll have to put
together something automated with pstools instead.

Thanks again!



"Pegasus (MVP)" wrote:

> If you want to open a command window on a remote machine,
> why not use psexec.exe from www.sysinternals.com?
>
>
> "Firewalker82" <Firewalker82(a)discussions.microsoft.com> wrote in message
> news:7C654025-30D6-4C87-9582-18E404829494(a)microsoft.com...
> > Al,
> >
> > Thanks for your reply, although I think maybe I didnt make my original
> > post
> > clear enough. I do want to open a command window on a remote machine,
> > thats
> > it. I dont want to have a console on the local computer controlling the
> > remote computer console (id just use telnet, ssh for that!). I dont want
> > to
> > use RDP as it isn't really a practical option as we have to view what our
> > users are experiencing and RDP hides this as it creates a new session (we
> > use
> > VNC). Users are locked down and prevented from opening a CMD.exe process.
> > This is why I want to create this script, so that administrators can run
> > it
> > against any computer under their admin credentials. I know that using
> > 'runas' command on the local computer via a shortcut is an option, but it
> > involves several tasks and I think that the remote shell vbs script would
> > be
> > far more efficient. Im hoping to open this up to running many different
> > apps
> > on the remote computer, but I cant get this to work. Is their any
> > component
> > security that could be causing a problem with this. Microsoft make it
> > sound
> > SO EASY, DONT THEY!!
> >
> > Any further suggestions??
> > --
> > Firewalker82
> >
> >
> > "Al Dunbar" wrote:
> >
> >>
> >> "Firewalker82" <Firewalker82(a)discussions.microsoft.com> wrote in message
> >> news:D9853A2E-4132-4442-B774-55FDE958A279(a)microsoft.com...
> >> > Hi all,
> >> >
> >> > I am trying to run a simple script that opens the cmd shell on a remote
> >> > computer. I have two scripts; the first script asks for the computer
> >> > to
> >> > run
> >> > the script on and the script to run on that remote computer and the
> >> > second
> >> > script is the script that is run and called by script 1. below is
> >> > script
> >> > 1;
> >> >
> >> > ----------------------------------------------------------------------------------------
> >> > Dim Controller, RemoteScript, strcomputer, text1, wshshell, oexec
> >> > 'Variables
> >> > Set Controller = WScript.CreateObject("WSHController")
> >> > text1 = "You did not enter a computer name!"
> >> > Set WshShell = CreateObject("WScript.Shell")
> >> > strscriptloc = "C:\scripts\cmdexec.vbs"
> >> >
> >> > 'Ask the user which computer that they would like to run the app on
> >> > strcomputer = inputbox("Please enter the computer that you would like
> >> > to
> >> > open the command prompt on.","Open a command box on which computer??")
> >> >
> >> > 'If the user didn't enter anything, then close the app gracefully
> >> > If strcomputer = "" Then
> >> > WScript.Echo Text1
> >> > wscript.quit
> >> > end if
> >> >
> >> > 'check connectivity to the computer before running execution xp / 2003
> >> > only
> >> > wmiQuery = "Select * From Win32_PingStatus Where Address = '" &
> >> > strComputer
> >> > & "'"
> >> > Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
> >> > Set objPing = objWMIService.ExecQuery(wmiQuery)
> >> >
> >> > For Each objStatus in objPing
> >> > If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
> >> > wscript.echo "Computer is not responding on the network, unable
> >> > to
> >> > continue"
> >> > wscript.quit
> >> > end if
> >> > Next
> >> >
> >> > set RemoteScript = Controller.CreateScript(strscriptloc, strcomputer)
> >> > RemoteScript.Execute
> >> >
> >> > Do While RemoteScript.Status <> 2
> >> >
> >> > WScript.Sleep 100
> >> > Loop
> >> >
> >> > wscript.disconnectobject remotescript
> >> >
> >> > Sub remotescript_Error
> >> > Dim theError
> >> > Set theError = remotescript.Error
> >> > WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line &
> >> > ",
> >> > Char: " & theError.Character & vbCrLf & "Description: " &
> >> > theError.Description
> >> > WScript.Quit -1
> >> > End Sub
> >> > --------------------------------------------------------------------------------------------
> >> >
> >> > The second script is as follows;
> >> >
> >> > --------------------------------------------------------------------------------------------
> >> >
> >> > Dim WshShell, oExec
> >> > Set WshShell = CreateObject("WScript.Shell")
> >> >
> >> > wshrun = wshshell.run ("cmd /k")
> >> >
> >> > --------------------------------------------------------------------------------------------
> >> >
> >> > Pretty simple really. The script works on my local machine perfectly,
> >> > but
> >> > when I execute it on a remote machine, nothing, no error message, just
> >> > completes and doesnt do a thing. I have added and re-added the remote
> >> > reg_sz
> >> > registry value in the registry with a 1(when I try and run it without a
> >> > remote registry value, I get the active x can't create object error, so
> >> > I
> >> > know that the registry value is working correctly). I have registered
> >> > the
> >> > wscript object on the remote machine wscript -regserver, but still no
> >> > luck,
> >> > not even an error?? I am a domain admin and I have all the rights to
> >> > perform
> >> > this script execution on the remote machine also.
> >> >
> >> > can anybody help??
> >>
> >> Depends on what, precisely, it is you want to do here. If you think that
> >> you
> >> are going to have cmd running on a remote system but running in a command
> >> prompt window on your local system, I don't think that is going to happen
> >> easily. IMHO, assuming the credentials allow it, a cmd.exe process has
> >> been
> >> created on the remote machine, but it is stuck in some sort of limbo
> >> without
> >> any kind of interface.
> >>
> >> If you really want to do this, the simplest way would be to establish a
> >> remote desktop connection to the remote machine.
> >>
> >> If you simply want to execute commands against drives on the remote
> >> system,
> >> try this command:
> >>
> >> pushd \\remotesystem\C$
> >>
> >> This will map the C:\ drive of the system noted as the next available
> >> local
> >> drive letter.
> >>
> >> /Al
> >>
> >>
> >>
>
>
>