Results 1 to 4 of 4

Thread: How to execute a command in a remote computer?

  1. #1
    Join Date
    Jul 2009
    Posts
    123

    How to execute a command in a remote computer?

    Hi,

    I have a shared folder on a server and I have to remotely execute a command on some files. What services must be running on the server to do the job? Essentials or System Center Configuration Manager. I want to consider methods that are available directly from the command line or script files, as well as not require pre-installation of agents. What are the way's to run a command on a remote computer?

  2. #2
    Join Date
    May 2008
    Posts
    390

    Re: How to execute a command in a remote computer?

    To solve this problem is a command line utility PsExec.exe. which you can freely download from Windows SysInternals. It does not require installation of the system, you can simply copy it into one of the folders contained in the environment variable% path%, and cause of any shell: Cmd, or PowerShell.

    Use PsExec very simple. For example, to execute ipconfig / flushdns on the computer main, sufficient to run the following command:

    psexec\\main ipconfig/flushdns

    Ipconfig command will be run on your computer under your main credentials. After completion ipconfig all text output will be transferred to your computer, and in addition will be returned to the team's exit code (error code). If the command is successful, it will be equal to 0.

    The -d tells PsExec unnecessary to wait for that command, but rather just run it and forget it. In this case, we do not receive the output from the console utility, but we can not wait for the completion of the previous command to run other. This is very useful if you need to run, for example, the installer program on multiple computers.

    By default PsExec executes commands in quiet mode, ie a system where the command is executed, will not show any windows or dialogs. However, it is possible to change this behavior by using a key-i. After that you can specify the number of sessions in which the display window, but you can not specify, then the interface will be displayed in a console session.

    Thus, to display a window with information about the operating system on the computer main, should run PsExec thus:

    psexec-i\\main winver.exe

    If you want to run on several computers, you will be useful to read their names from a text file list.

    psexec @ c:\comps.txt systeminfo.exe

    Well, one of the most useful abilities PsExec is the possibility of interactive input / output redirection between computers, allowing us to run, such as cmd.exe on a remote server, and give him commands and receive results on your computer.
    Attached Images Attached Images

  3. #3
    Join Date
    Dec 2007
    Posts
    263

    Re: How to execute a command in a remote computer?

    Windows Script Host also has the ability to run scripts on other computers. However, this function has not been very popular, and most likely due to the fact that demands too much of the preparatory activities and in return provides little opportunity. But I still talk about this method, because he might be useful.

    So, to run the script on another computer using WSH, we need to do the following:
    Administrator rights on the remote computer. It goes without saying, is
    1. required for nearly all other methods listed at the start of this article.
    2. Allow WSH Remote Scripting creating the registry string value Remote equal to "1" in the registry key HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows Script Host \ Settings
    3. Because of an error described in the Microsoft Knowledge Base article with the number 311269, on systems with Windows XP may need to execute the command wscript-regserver
    4. If you're using a firewall, then it should be allowed to access DCOM. And this must be done not only on the managed computer, but also on where you want to run the script.
    5. On Windows XP Service Pack 2 and above, you must change the security settings DCOM. This can be done using Group Policy. In node Computer Configuration \ Windows Settings \ Security Settings \ Local Policies \ Security Options should be set permissions as follows:

    • DCOM: Machine Access Restrictions in Security Descriptor Definition Language (SDDL) syntax
      By the Group to Anonymous Logon and Everyone permissions Allow Local and Allow Remote Access
    • DCOM: Machine Launch Restrictions in Security Descriptor Definition Language (SDDL) syntax
      Issue the Administrators group permission Allow Local Launch, Allow Remote Launch, Allow Local Activation, Allow Remote Activation
      Group Everyone - Allow Local Launch, Allow Local Activation


    Well, after all these procedures, you can try to run your script on another computer.

    A sample script that uses this technology:

    WSH remote scripting (VBScript)

    Code:
    Set objController = CreateObject ( "WshController") 
    Set objRemoteScript = objController.CreateScript ( "C: \test.vbs", "PC5") WScript.ConnectObject objRemoteScript, "remote_" 
    objRemoteScript.Execute 
    Do While objRemoteScript.Status <> 1 
    WScript.Sleep 1000 
    Loop 
    MsgBox "Script complete" 
    Sub remote_Error 
    Dim objError 
    Set objError = objRemoteScript.Error 
    WScript.Echo "Error - Line:" & objError.Line & _ 
    ", Char:" & objError.Character & vbCrLf & _ 
    "Description:" & objError.Description 
    WScript.Quit -1 
    End Sub
    In his second line, as parameters to the function CreateScript the path to the script file that will be executed on a remote computer and the actual name of this computer.

  4. #4
    Join Date
    Dec 2007
    Posts
    195

    Re: How to execute a command in a remote computer?

    You can try Windows PowerShell 2.0 on remote computer. Infrastructure PowerShell Remoting is based on WinRM version 2.0, and therefore inherits all the advantages of this technology, such as encryption of data transferred, and the opportunity to work on standard ports HTTP / HTTPS. But thanks to the rich possibilities of language Windows PowerShell, and his ability to work with objects, we have even more possibilities. At the moment the package WinRM2.0 also is in beta and available for download only for Windows Vista and Windows 2008. In Windows 7 and Windows Server 2008R2, he will be installed initially as PowerShell 2.0.

    Before you take all these advantages, PowerShell Remoting should be intensified on the management, and managed computers. To do this simply by running the cmdlet (command Windows PowerShell) Enable-PSRemoting. And if you add a key-Force is no evidence requested will not be. This cmdlet if necessary will winrs quickconfig, and create an exception in the firewall Windows, so no additional action is needed.

Similar Threads

  1. Execute GUI commands from the command line
    By dogonthehorizon in forum Windows Software
    Replies: 1
    Last Post: 21-07-2011, 03:50 AM
  2. How to execute a command without entering path on CentOS 5.5?
    By pREMAsAGAR in forum Operating Systems
    Replies: 5
    Last Post: 07-05-2011, 12:09 PM
  3. Execute a batch file on a remote computer?
    By Chris D in forum Windows Server Help
    Replies: 6
    Last Post: 20-01-2011, 11:09 PM
  4. Windows phone 7: How to execute the MVVM command?
    By Mishraji in forum Windows Software
    Replies: 3
    Last Post: 27-10-2010, 09:38 PM
  5. Execute dos command in java
    By Gillian Anderson in forum Software Development
    Replies: 4
    Last Post: 22-03-2010, 01:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,666,619.84821 seconds with 18 queries