Wednesday, August 17, 2016

Handling print jobs

To delete printjobs of specific printer

wmic printer where name="HP LaserJet" call cancelalljobs

To see the list of jobs we have in the queues
wmic printjobs get

To delete printjob

wmic printjob where jobid=<jobnumber> delete
Pause a print job

wmic printjob where jobid=<jobnumber> pause

prints lot of details about each printer job
wmic printjob get jobid, document, jobstatus

Resuming a print job


wmic printjob where jobid=<jobnumber> resume

Handling print jobs

To delete printjobs of specific printer

wmic printer where name="HP LaserJet" call cancelalljobs

To see the list of jobs we have in the queues
wmic printjobs get

To delete printjob

wmic printjob where jobid=<jobnumber> delete
Pause a print job

wmic printjob where jobid=<jobnumber> pause

prints lot of details about each printer job
wmic printjob get jobid, document, jobstatus

Resuming a print job


wmic printjob where jobid=<jobnumber> resume

uninstall a program with command

To know the name of already installed software in your computer

wmic product get name

and to uninstall software by their name

wmic product where name="windows live writer" call uninstall

To terminate a running program without asking for save

wmic process where name="iexplore.exe" call terminate
wmic process where name="notepad.exe" call setpriority 64
wmic /node:steve-pc service list brief

Share printer with commnad on own or remote pc

We can use pstools to connect to remote pc command prompt,, download it from

https://download.sysinternals.com/files/PSTools.zip

extract pstools folder --> hold the shift key --> right click in the folder --> select command prompt
Start a CMD session on the remote machine using psexec by typing below commnad

psexec \\remote-pc cmd

After connecting, list the printers available on the machine:
c:\pstools\>wmic printer get name
printer1

  1. If you want to make printer1above shared:
    > rundll32 printui.dll,PrintUIEntry /Xs /n "printer1" Sharename "Printer1"
    > rundll32 printui.dll,PrintUIEntry /q /Xs /n "printer1" Attributes Shared
  2. Confirm the printer is available by going to \\remote-machine in Windows Explorer; you should see the printer available now.
To get printer shared or not or to know the sharename of the printer with command type the following : 

wmic /node:remote-pc printer get shared,sharename,caption,name,portname

To delete printer 
wmic printer where name='printer1' delete
wmic printer where local='false' delete

To list printer in brief

wmic printer list brief

wmic /node:steve-pc service list brief
wmic process where name="notepad.exe" call setpriority 64



Examples
WMIC OS 

WMIC OS LIST BRIEF

WMIC OS GET csname, locale, bootdevice

WMIC OS GET osarchitecture /value

WMIC OS GET localdatetime

WMIC LOGICALDISK where drivetype!=4 get deviceid, description

WMIC LOGICALDISK where description='Local Fixed Disk' get deviceid, volumename

WMIC NTEVENT where LogFile='system'

WMIC NTEVENT where "LogFile='system' and Type>'0'" 

WMIC SERVICE where (state=”running”) GET caption, name, state > services.tsv

WMIC SERVICE where caption='TELNET' CALL STARTSERVICE

WMIC PRINTER LIST STATUS

WMIC PRINTER where PortName="LPT1:" GET PortName, Name, ShareName
 
WMIC /INTERACTIVE:ON PRINTER where PortName="LPT1:" DELETE

WMIC PROCESS where name='evil.exe' delete

WMIC /output:"%computername%.txt" MEMORYCHIP where "memorytype=17" get Capacity

WMIC /node:remote_computer PROCESS call create "netstat.exe -ano > C:\output.txt"

WMIC /node:@workstns.txt /failfast:on PROCESS call create "\\server\share\installer.cmd"

Interactive mode:
C:> WMIC
wmic:root\cli> OS get csname
wmic:root\cli> quit



We can use pstools to connect to remote pc command prompt,, download it from

https://download.sysinternals.com/files/PSTools.zip

extract pstools folder --> hold the shift key --> right click in the folder --> select command prompt
Start a CMD session on the remote machine using psexec by typing below commnad

psexec \\remote-pc cmd

After connecting, list the printers available on the machine:
c:\pstools\>wmic printer get name
printer1

  1. If you want to make printer1above shared:
    > rundll32 printui.dll,PrintUIEntry /Xs /n "printer1" Sharename "Printer1"
    > rundll32 printui.dll,PrintUIEntry /q /Xs /n "printer1" Attributes Shared
  2. Confirm the printer is available by going to \\remote-machine in Windows Explorer; you should see the printer available now.
To get printer shared or not or to know the sharename of the printer with command type the following : 

wmic /node:remote-pc printer get shared,sharename,caption,name,portname


To delete printer according to crieteria 

wmic printer where name='printer1' delete
wmic printer where local='false' delete

Examples
WMIC OS 

WMIC OS LIST BRIEF

WMIC OS GET csname, locale, bootdevice

WMIC OS GET osarchitecture /value

WMIC OS GET localdatetime

WMIC LOGICALDISK where drivetype!=4 get deviceid, description

WMIC LOGICALDISK where description='Local Fixed Disk' get deviceid, volumename

WMIC NTEVENT where LogFile='system'

WMIC NTEVENT where "LogFile='system' and Type>'0'" 

WMIC SERVICE where (state=”running”) GET caption, name, state > services.tsv

WMIC SERVICE where caption='TELNET' CALL STARTSERVICE

WMIC PRINTER LIST STATUS

WMIC PRINTER where PortName="LPT1:" GET PortName, Name, ShareName
 
WMIC /INTERACTIVE:ON PRINTER where PortName="LPT1:" DELETE

WMIC PROCESS where name='evil.exe' delete

WMIC /output:"%computername%.txt" MEMORYCHIP where "memorytype=17" get Capacity

WMIC /node:remote_computer PROCESS call create "netstat.exe -ano > C:\output.txt"

WMIC /node:@workstns.txt /failfast:on PROCESS call create "\\server\share\installer.cmd"

Interactive mode:
C:> WMIC
wmic:root\cli> OS get csname
wmic:root\cli> quit


Monday, August 15, 2016

Computer Management open for remote system

Open run or cmd window and type the following
mmc c:\windows\system32\compmgmt.msc /computer:\\ComputerName

The aim for this Wiki is to promote using a command to open up commonly used applications without having to go through many mouse clicks - thus saving time on monitoring and troubleshooting Windows machines.
Answer entries need to specify
  • Application name
  • Commands
  • Screenshot (Optional)
Shortcut to commands

Restore point creation with command prompt

his method shows you how to open System Restore using Command Prompt
Please perform the following steps:
In the Command Prompt or in run windows type

systempropertiesprotection
Please press Enter to execute

OR

In the Command Prompt type the below command

wmic.exe /Namespace:\\root\default Path SystemRestore Call CreateRestorePoint "My Shortcut Restore Point", 100, 7

TIP : to view system icons if unable to see any icon in change icon settings then go to following path
C:\Windows\System32\imageres.dll
ok

System Restore is implemented using the Volume Shadow Copy Service (Volume Snapshot Service, VSS). As such, you can use vssadmin in an elevated command prompt to list all of the restore points:
vssadmin List Shadows
Note that Windows Backup also uses VSS, with shadow copies stored on both the system and backup drives, so if your backup drive is connected, the shadow copies stored on the backup drive corresponding to these backups will be listed as well. Add /for=C: to specify the volume you want to list the shadow copies for, replacing C: with the volume letter of your choice if it is not C:.
While this isn't the easiest way to work with restore points, you can use the creation date and time and shadow copy ID listed in the output from the above command to delete specific restore points, using the vssadmin Delete Shadows command. You can also create restore points with vssadmin Create Shadow and change the amount of space available to restore points with vssadmin Resize ShadowStorage.
  • vssadmin list shadowstorage - This command lists all connected hard drives and their used, allocated and maximum shadow copy storage space.
  • vssadmin list shadows - This command lists all existing shadow copies on the system
  • vssadmin delete shadows /for=c: /oldest - This command deletes the oldest shadow copy on drive C
  • vssadmin delete shadows /for=d: /all - This command deletes all existing shadow copies on drive D
  • vssadmin delete shadows /for=c: /shadow=ID - Deletes the selected shadow copy. The IDs are listed when you use the list shadows command.
  • vssadmin resize shadowstorage /for=c: /maxsize=2GB - Sets the shadow storage for drive C to 2 Gigabyte. May delete existing restore points starting with the oldest if space is not sufficient to store all System Restore points
Run Powershell as an administrator. At the prompt:
Get-ComputerRestorePoint
This will list all the system restore points.
Powershell offers 4 Cmdlets to manage system restore and/or restore points:
  1. Disable-ComputerRestore
  2. Enable-ComputerRestore
  3. Get-ComputerRestorePoint
  4. Restore-Computer
For assistance with any of them, you can add get-help in front of the Cmdlet, i.e.
get-help Get-ComputerRestorePoint