Immediate Solutions


Working with the MMC

Microsoft Management Console (MMC) is a multi-document interface (MDI) shell that hosts applications called snapins. Windows 2000/XP/2003 comes with many snapins, from Device Management to User Management. While by default most snapins connect to the local system, you can use the command line to connect a snapin to a remote system.

Opening the "Computer Management" MMC Snapin

To open the computer management MMC snapin for a remote system, start a command prompt and enter the following:

 mmc %windir%\system32\compmgmt.msc -s /computer:\  computer  

Here, computer is the name of the remote system.

Opening the "Event Viewer" MMC Snapin

To open the event viewer MMC snapin for a remote system, start a command prompt and enter the following:

 mmc %windir%\system32\eventvwr.msc /computer=\  computer  

Here, computer is the name of the remote system.

Tip  

The Local Users and Computers (lusrmgr.msc) and Services (services.msc) snapins also support the /computer= option.

Remote Management from the Command Line

Most local system management is performed through the MMC or the Control Panel on Windows 2000/XP/2003 systems. Although most of these tools include remote management capability, you can also use command-line utilities to create scripts for remote management.

Installing the Remote Console

Remote Console is a Windows 2000 resource kit utility that allows you to run a client/server command-prompt session between two systems, similar to a telnet session. To install the Remote Console, start a command prompt and enter the following:

 RSETUP \  computer  

Installing the Remote Command

Remote Command is a resource kit utility that allows you to run a program and a command prompt session on a remote computer from your local station. In essence, you call up a command prompt window on your machine that will run commands on the remote machine. To install the remote command service, start a command prompt and enter the following:

 RCMDSVC -INSTALL NET START "Remote Command Service" 

Executing Commands on a Remote System

You can start commands on a remote system using either the remote command (RCMD) or Remote Console utilities. The remote command utility allows you to start either a batch file or a program on a remote system. To start a command on a remote system using the remote command, start a command prompt and enter the following:

 RCMD \  computer program  

The Remote Console utility allows you to start a batch file on a remote system. To start a batch file on a remote system using Remote Console, start a command prompt and enter the following:

 RCLIENT \  computer  /RUNBATCH program 

Here, computer is the remote system to run the program on.

Listing Shares and Permissions

SRVCHECK.EXE is a resource kit utility to list shares and permissions on a remote system. To view the shares and permission on a remote system, start a command prompt and enter the following:

 SRVCHECK \  computer  

Here, computer is the name of the remote system.

Related solution:

Found on page:

Listing Shares

213

Creating Shares with Permissions

RMTSHARE.EXE is a resource kit utility to create shares with permissions on remote stations . To use RMTSHARE.EXE to create shares with permissions, start a command prompt and enter the following:

  RMTSHARE \  computer\name=path  /GRANT  guser  :  permission  /REMOVE  ruser   
Note  

The code above must be placed on one line.

Here, computer is the computer name to create the share on; name is the name of the share; path is the path to create the share to; guser is the username to grant permissions to; and ruser is the username to deny share access to.

Tip  

RMTSHARE.EXE also supports the same switches as the NET SHARE command.

Related solution:

Found on page:

Creating Shares with Permissions

176

Listing Processes

PULIST.EXE is a Windows 2000 resource kit utility that allows you to list running processes and their associated IDs on a remote system. To display remote processes, start a command prompt and enter the following:

 PULIST \  COMPUTER  

Terminating Processes

The Windows 2000 resource kit provides a service called RKILLSRV.EXE that allows you to view and terminate processes on a remote PC. Unfortunately, not all of us are lucky enough to have the time or authority to install any services we like. PSKILL.EXE is a free utility from Sysinternals (http://www.sysinternals.com) that allows you to terminate a process or a remote station without having to add any additional services or configuration. To terminate a process on a remote system, start a command prompt and enter the following:

 PSKILL \  computer  -U  username  -P  password process  

Here, computer is the name of the remote system, username and password are the administrative credentials for the remote system, and process is the name or process ID to terminate. Here is a quick example to terminate a user running Notepad:

 PSKILL \  computer  -U  username  -P  password  notepad 

Listing Services

SCLIST.EXE is a Windows 2000 resource kit utility that allows you to list running services on a remote system. To display remote services, start a command prompt and enter the following:

 SCLIST \  computer parameters  

Here, computer is the name of the remote system to display services. The available parameters for SCLIST are as follows :

  • /M ”Displays all services

  • /R ”Displays running services

  • /S ”Displays stopped services

Alternatively, you can use the resource kit utility NETSVC to list services:

 NETSVC /LIST 

Managing Services

NETSVC is a Windows 2000 resource kit utility that allows you to manage services on remote systems. The basic syntax for NETSVC is:

 NETSVC  parameter service  \  computer  

Here, parameter is the action to perform; service is the specific service to work with; and computer is the remote system to manage. Here is a list of available NETSVC parameters:

  • /CONTINUE ”Restarts a service

  • /LIST ”Lists services, do not specify a service name

  • /PAUSE ”Pauses a service

  • /QUERY ”Displays the status of a service

  • /START ”Starts a service

  • /STOP ”Stops a service

Related solution:

Found on page:

Managing Services from the Command Line

155

Connecting to a Remote System through "Remote Desktop"

Remote Desktop allows you to access and control a remote Windows 2000 Server/XP Professional/2003 system. To connect to a remote system through remote desktop, proceed as follows:

  1. For Windows 2000 only, download and install the latest version of Remote Desktop Connection Software from http://www.microsoft.com.

  2. Start a command prompt and enter the following:

 %windir%\system32\mstsc.exe /F /V:  computer  

Here, the /F option specifies fullscreen mode and the /V option is used to connect to a remote system, computer .

Note  

You must enable remote control functionality on the remote system before connecting with remote desktop. See the Microsoft Knowledge Base article Q306624 for Windows 2000/ 2003 server and Q315328 for Windows XP Professional.

Connecting to a Remote System through VNC

VNC (Virtual Network Computing) is a free, remote control software, similar to pcAnywhere. To connect to a remote system through VNC, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download the latest version of VNC from http://www.realvnc.com, to the new directory.

  3. Install and configure VNC on the local and remote system.

  4. Start a command prompt and enter the following:

  installdir  \vncviewer.exe -FULLSCREEN  computer  

Here, installdir is the full path where VNC was installed on the local system. The FULLSCREEN option specifies fullscreen mode and computer is the name of the remote system.

Remote Management through WMI

WMI provides a standard scriptable interface to your local and network resources. Using WMI, you can monitor and manipulate many settings on any resource on your network.

Listing Shares

The Win32 _ Share class manages all shared resources on a system. These devices include directories, drives , printers, removable media, or any other shareable resource. To list all shares on a system using WMI, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next   Computer  = InputBox("Enter the computer name", "List Shares", "localhost")   Set  Shares  = GetObject("winmgmts:{impersonationLevel= impersonate}!\" &  Computer  & "\root\cimv2").ExecQuery ("select * from Win32_Share")  For each  Share  in  Shares   SList  =  SList  &  Share  .Caption & " = " &  Share  .Path & VBlf Next WScript.Echo "Shares:" & VBlf & VBlf &  SList  
Note  

The highlighted code above must be placed on one line.

Related solution:

Found on page:

Listing Shares

213

Creating a Share

The Create method for Win32_Share allows you to share a resource. To create a share using WMI, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com, to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the code shown on the next page.

 On Error Resume Next   Computer  = InputBox("Enter the computer name", "Create Share", "localhost")    SName  = InputBox("Enter the name of the share", "Share Name", "Temp")    SPath  = InputBox("Enter the path of the share", "Share Path", "C:\Temp")   TypeMenu  = "Choose a share type:" & VBlf & VBlf & _    "0 - Disk Drive" & VBlf & _    "1 - Print Queue" & VBlf & _    "2 - Device" & VBlf & _    "3 - IPC" & VBlf & _    "2147483648 - Disk Drive Admin" & VBlf & _    "2147483649 - Print Queue Admin" & VBlf & _    "2147483650 - Device Admin" & VBlf & _    "2147483651 - IPC Admin"  SType  = InputBox(TypeMenu, "Share Type", 0)   SMax  = InputBox("Enter the maximum number of users", "Maximum Users", 10)    SDescribe  = InputBox("Enter the description of the share", "Share Description", "Temp Share")    SPass  = InputBox("Enter the password to access the share", "Share Password", "Temp Password")   Set  Security  = GetObject("winmgmts:{impersonationLevel= impersonate,(Security)}!\" &  Computer  & "\root\cimv2")  Set  Share  = Security.Get("Win32_Share")  Set  Methods  =  Share  .Methods_("Create"). InParameters.SpawnInstance_()   Methods  .Properties_.Item("Description") =  SDescribe   Methods  .Properties_.Item("MaximumAllowed") =  SMax   Methods  .Properties_.Item("Name") =  SName   Methods  .Properties_.Item("Password") =  SPass   Methods  .Properties_.Item("Path") =  SPath   Methods  .Properties_.Item("Type") =  SType  Set  Complete  =  Share  .ExecMethod_("Create",  Methods  ) 
Note  

The highlighted code above must be placed on one line. The (Security) statement is necessary because this script modifies share access.

Related solution:

Found on page:

Adding Shares

159

Deleting a Share

The Delete method for Win32_Share allows you to delete a share from a manageable system. To delete a share using WMI, proceed as follows:

  1. Create a new directory to store all files included in this example.

  2. Download and install the latest version of Windows Script Host, from http://www.microsoft.com , to the new directory.

  3. Select StartRun and enter "cscript scriptfile .vbs."

Here, scriptfile is the full path and file name of a script file that contains the following:

 On Error Resume Next   Computer  = InputBox("Enter the computer name", "Delete Share", "localhost")    SName  = InputBox("Enter the name of the share", "Delete Share")   Set  Shares  = GetObject("winmgmts:{impersonationLevel= impersonate}!\" &  Computer  & "\root\cimv2").ExecQuery ("select * from Win32_Share where Name = 


Windows Admin Scripting Little Black Book
Windows Admin Scripting Little Black Book (Little Black Books (Paraglyph Press))
ISBN: 1933097108
EAN: 2147483647
Year: 2004
Pages: 89

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net