Page 1 of 3 123>
Topic Options
#162266 - 2006-05-23 04:09 PM Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Hey,

I know remote execution has been discussed a lot in the forum. I have seen udf’s RemoteExec() and fnRemoteExec()…

So I decided to use the methods to execute commands on a remote client.
Something likes Radimus’s REM. Some remote DOS console which could execute commands on the remote machine.
Due to the fact remoteexec process has no network permissions, I followed the suggestion to include the commands in a batch file, copy it to the remote machine and then execute the batch file using remoteexec.

The Environment is W2K Sp4 on both local and remote client.
Same user with local admin right is logged on both clients.
Client are member of AD domain.
The Kix 4.52

Code:


$computer = "172.60.10.10"
$RemotePath = \\172.60.10.10\C$\Winnt\Temp\

Copy "C:\Script\dir.bat" $RemotePath /C

sleep 3

$rc = RMTEXEC($computer, 'C:\Winnt\Temp\dir.bat')

Function RMTEXEC($computer, $command)
Dim $Connect
$Connect = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer/root/cimv2:Win32_Process")
$RMTEXEC = $Connect.Create($Command)
Exit @error
$Connect = 0
EndFunction




Well, the batch file was copied, but nothing seems happen after that 
I was hopping a CMD windows was pop up on the remote client and performed the content of the batch file.

What could be wrong or missing?

Top
#162267 - 2006-05-23 04:23 PM Re: Executing batch files on remote client
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
it runs within the system-account, and therefore nothing pops up.
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#162268 - 2006-05-23 04:32 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
OK,

Now I changed the RMTEXEC with fnRemoteExec and provided domain user and password.

Code:


$rc = fnRemoteExec('C:\Winnt\Temp\dir.bat', $computer, $User , $Passwd)




Function fnRemoteExec($sCommand,Optional $sComputer,Optional $sUser,Optional $sPwd)
Dim $objLocator,$objSvc,$objSet
$objLocator = CreateObject("WbemScripting.SwbemLocator")
$objSvc = IIf($sComputer='',$objLocator.ConnectServer(),$objLocator.ConnectServer($sComputer,,$sUser,$sPwd))
If @ERROR Exit @ERROR EndIf
$objSet = $objSvc.Get("Win32_Process")
If @ERROR Exit @ERROR EndIf
$fnRemoteExec = $objSet.Create($sCommand)
Exit @ERROR
EndFunction





Should this work? Cause it don’t!
Same behavior, no action nothing happens.

If I want it to pop up, what should I do then?

Top
#162269 - 2006-05-23 05:51 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Seems that i missed something..
I found this comment by Radimus:

The remoteExec acct is SYSTEM, so it has local admin, but doesn't interact with the user at all ...
If you want a method of starting apps or files remotely in the user context, the best bet is to make a client script the starts from STARTUP or HKCU\...\run (runs as current user) that monitors a special folder, where you can remotely push commands / scripts

If I have understood this right it means that the RemoteExe is limited to some local & silent commands... like "net send".

If so, then is it possible to remotely change/create a process on remote client to interact with user/desktop, and then use the remotexe?

Could you explain what/how this means, any sample?
"...that monitors a special folder, where you can remotely push commands / scripts"

Top
#162270 - 2006-05-24 12:25 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Appreciate if some could put attention on this…
Top
#162271 - 2006-05-24 01:04 PM Re: Executing batch files on remote client
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
what you would want to do is make a "special folder" on the user's machine.

make a script that is launched from HKCU\..\run on the user's pc that monitors that folder for the presence of a specificaly named bat file (pushed.bat or whatever). If exist, run the bat then delete the contents of the special folder.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#162272 - 2006-05-24 02:57 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Ok, I got it. Although it’s not a remote execution procedure.

Radimus your comment that the RemotExe() udf is limited to local & silent commands...

Is there any list of which command could be performed by remotexe() udf?

Top
#162273 - 2006-05-24 06:10 PM Re: Executing batch files on remote client
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
it can do any command. The issue is whether the command requires interaction, which it cannot receive nor will the current user see or interact with it. If you are passing a name and password, it can have access to network resources, otherwise the resources must be local.

When you remoteexec, it is then running in a seperate user context and as such will have it's own environment (think of a terminal server session).

The issue is what you are trying to make it do.

To be of more help, what is it that you are trying to do?

Are you trying to make the user respond to a prompt of some sort? Or are you trying to run a command that requires input from the user.


Edited by Radimus (2006-05-24 06:16 PM)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#162274 - 2006-05-25 04:10 AM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Glad to have your response Rad.

My early intention was to create a console which could remotely execute any DOS/Batch command on remote client.

This could be very useful. It could remotley execute setup or uninstalling procedure for software on remote client.

e.g. sending and executing this would run the uninstall for ASE

"C:\Program Files\iTripoli\AdminScriptEditor\unins000.exe"

Ofcurse uninstall window would pop up and user have to choose to continue uninstalling or abort it.

Or deliver a batch file containing necessary data for software setup, then remotely execute the batch file on remote client.

Or creating a local account on remote client using “net localgroup”, adding it to local admin group etc…

Depended on what and how the remote execution is preformed, it would require user respond or input, or just silent without user notice anything.

Appreciate your feedback!

Top
#162275 - 2006-05-25 04:39 AM Re: Executing batch files on remote client
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
many of the installers today have silent switches for scripting purposes... for example MSI installers have uninstall commands in the uninstall key in HKLM\...\uninstall, append a "/q" or "/qb" to the cmd line and away it goes with no prompting.

So my point is, the remote execute works fine, it is the command that is executed that needs some work.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#162276 - 2006-05-25 07:34 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Ok, that’s what I’m trying to achieve.

I have done a simple test. Created a batch file continuing UninstallString from HKLM\...\uninstall:

MsiExec.exe /I{3248F0A8-6813-11D6-A77B-00B0D0150040}

This will generate the uninstall process for J2SE Runtime, which is installed on target machine.

I pushed the batch file to target machine C:\Winnt\Temp

Then I used remotexec to run the batch file remotely on that target machine.
If I understood your point, it won’t work because it wants to interact with user desktop on target. But it may work if it’s run silently using run MsiExec.exe "/q" or "/qb".

Or is it the batch file which must run under different circumstances?
How would you do to make it run on remote machine? Any samples?

Top
#162277 - 2006-05-25 07:40 PM Re: Executing batch files on remote client
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well looking here it would appear that others are having trouble silently removing JAVA as well.

http://forum.java.sun.com/thread.jspa?threadID=692662&messageID=4025805

Try searching Google or the Sun site to see if you can find any assistance on what command line to use.

It has noting to do with KiXtart or the RemoteExec UDF, they can only run the items for you, but you need to find the correct code to do the silent non-interactive removal process.

Top
#162278 - 2006-05-25 07:45 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Doc, thanks for your input.

That was only an example. I have tested this for other installed software too.
But same symptoms.

I need also figure out the possible ways to execute CMD commands on remote machine.

Top
#162279 - 2006-05-25 07:53 PM Re: Executing batch files on remote client
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hi Jazz,

I think maybe you're not seeing the overall bigger picture here. The RemoteExec UDF does not support ANY command that requires user interaction either physically or visibly.

If you have a list of 10 software titles that you want to remove then you have to find the EXACT proper code to perform the removal silently otherwise it will not work.

If you want to have some type of interaction then you might be able to use the tools from http://www.sysinternals.com but unless you have someone sitting on the other side to work with you it wouldn't work either. That is the whole idea of doing remote work is that you can do it on your own without user intervention.

Now, something that you "might" be able to do is use RemoteExec to create an INTERACTIVE scheduled application. Again though that sort of defeats the purpose of doing a remote admin script in the first place. If you're going to need interactive then why not just manually do the removal on your own while you're at the desktop.
 

Top
#162280 - 2006-05-25 08:21 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Thanks for your feedback Radimus and Doc.

I think/hope finally I begun understand the difference between interactive and none-interactive.
Once again I managed to make the subject unnecessary complex to understand the main point correctly.

But happy that I’m hopefully learned some about the difference of executing mode, and how it works.

Got admit that I found the “Remote exec” and “Remote install/uinstall” from Rads SIM project very attractive and useful.

Just thought, wow remotely executing whatever on an remote client… But now I now what the condition is for such operations.

However, if I missed something, happy to receive more of your feedback.

BR

Top
#162281 - 2006-05-25 08:27 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Btw, for some time ago I did a quick test of sysinternals PSEXEC. That was to remotely log of user... But I found using WMI more interesting...

Please do advice if you have done similar operations such remote execution, installing/uninstalling using psexec.

Top
#162282 - 2006-05-25 08:51 PM Re: Executing batch files on remote client
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
MsiExec.exe /I{3248F0A8-6813-11D6-A77B-00B0D0150040} /q

msiexec.exe /update OUTLOOKff.msp /qb-!

WindowsMedia10-KB911565-x86-enu /passive

J2SE_Runtime5.0_Update1.msi /qb-! WEBSTARTICON=0 SYSTRAY=0 JAVAUPDATE=0 IEXPLORER=0 REBOOT=Suppress

msiexec /x $setup\ess\setup.msi /qb-!
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#162283 - 2006-05-25 09:04 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Wow Rad,
That’s how the none-interactive silent mode could be executed remotley on remote machine. Have to test all these.

U R D Man

Top
#162284 - 2006-05-25 10:49 PM Re: Executing batch files on remote client
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
http://www.msfn.org/board/index.php?s=b9c8e180627730363494a2b7c02aa3cc&showforum=80

http://www.msfn.org/board/index.php?showtopic=20502
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#162285 - 2006-05-26 03:29 PM Re: Executing batch files on remote client
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Very useful links indeed, thanx a lot Rad….
The uninstall works very good, as it should….

I have one more silly Q:

Bellow will not work because the application to be installed on remote client, is located on network share.

Msiexec.exe /I \\Appserv\StandardApps\Acdsee\Acdess.msi /quiet

Will it work if the network share is mapped as network drive on remote machine
Any suggestion/recommendations?

Top
Page 1 of 3 123>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.077 seconds in which 0.026 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org