搜尋此網誌

顯示具有 wmic 標籤的文章。 顯示所有文章
顯示具有 wmic 標籤的文章。 顯示所有文章

2018年3月16日 星期五

如何將user已安裝某個printer server的printer一次刪除Remove Multiple Network Printers at once

IT可能會遇到想要一次刪除在user端安裝的網路printer,尤其是換printer server時,例如ABC printer server(舊)換到XYZ printer server(新),想將user端之ABC printer server的printer一次刪除不用一個queue一個queue刪。
而且由系統端處理即可,不需動用到使用者,使用者只要登入系統即會處理,IT只要動個login script就好。

試了好多方式,最後有一個我認為不錯的方式,只改user login script,其它都不用動:

在user login script中加一行如下:
mic printer where "servername like "%%printer server name%%"" delete /nointeractive

例如: printer server name = ABC,指示要改成
mic printer where "servername like "%%ABC%%"" delete /nointeractive
只要一段日子大家都登入過,再將指令移除即可。

打完,收工。

但是~~~好像有些時候上述方式不work,原因待查,就試試vbs的方式看看~~~
=====================
' Remove all network printers     vbs

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
        ("SELECT * FROM Win32_Printer where Servername='\\\\printer'")

For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next
=======================

  • 存檔在c:\test\deleteprn.vbs
  • 在cmd中下cscript c:\test\deleteprn.vbs
這樣也OK的。

2011年4月27日 星期三

Delete Remote pc share folder with WMIC(利用WMIC取消遠端PC共用資料夾設定)

查詢遠端有什麼share folder

wmic /note:"test-pc"
share list
or
share list brief

wmic:root\cli>share list brief

Description  Name              Path
             Outlook Personal  C:\Documents and Settings\adminuser.INTRANET\Lo.....
遠端 IPC     IPC$
預設共用     D$                D:\
遠端管理     ADMIN$            C:\WINDOWS
預設共用     C$                C:\


看到想要刪除的share folder name。EX:Outlook Personal

wmic:root\cli>share where name="outlook personal" call delete
Execute (\\test-pc\ROOT\CIMV2:Win32_Share.Name="Outlook Personal")->delete() (Y/N/?)? Y
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ReturnValue = 0;

其它參考資訊
http://theinterw3bs.com/wiki/index.php?title=WMIC_Commands#Display_Shares
http://hi.baidu.com/99168/blog/item/2cb7580facf673276159f37c.html

2010年10月20日 星期三

利用wmic查看遠端電腦硬體主機板、cpu、cdrom、bios...等資訊

進入CMD

wmic
/node:"test-PC"

參數如下
BASEBOARD - 看主機板資訊
BIOS - 看BIOS資訊
BOOTCONFIG - Boot configuration
CDROM - 看該電腦裝了什麼CD-ROM,廠牌、是否可燒錄...等
COMPUTERSYSTEM - Computer system [CALL/SET]
可看到目前誰在登入(login name) & Ram有多少...
CPU - CPU
CSPRODUCT - Computer system product information from SMBIOS

2010年9月6日 星期一

利用wmic將遠端client Netbios關掉

利用wmic看看遠端網卡在第幾Index
wmic 
/node:"test-computer"
nicconfig get caption,index,TcpipNetbiosOptions
(找出網卡在第幾號Index,假設在第3 index) 

2010年8月17日 星期二

遠端控制的幾個好有的工具

psexec
wmic
mmc

softwarelist.vbs

psexec可以命令遠端電腦執行程式:
  • 執行遠端電腦cmd:
    如果您是管理者,可在本機端cmd中執行psexec \\test_romote cmd,如此即可開出遠端\\test_romote的cmd,您可在該視窗中下ipconfig /all,看到的回應是遠端的設定。
    也可下netstat -nb看看。
  • 遠端關機(如果您不是管理者,需下-u -p指令)
    PsExec.exe \\remotehost -u administrator -p xxxxx shutdown -r -t 0
    如果要一次關很多主機可用@file
  • 可以遠端移除程式:
    我們知道利用wmic --> product list出的是msi所Install的軟體,當然可用wmic的方式Uninstall,但有很多軟體是用setup.exe的方式安裝,wmic的方式就看不到裝了什麼?所以我先用一個vbscript將所有安裝在遠端電腦中的軟體list出或是到Remove Programs from the Add/Remove Programs List (All Windows) 
    System Key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall]
    Value Name: DisplayName, UninstallString
    看UninstallString是下什麼指示,即可利用該指示遠端uninstall software
    EX:於\\test_remote之regedit中查到a-squared HiJackFree之uninstallString是"C:\Program Files\a-squared HiJackFree\unins000.exe" /SILENT,所以我們就可以在Local端下
    C:\test>psexec \\test_remote "C:\Program Files\a-squared HiJackFree\unins000.exe"
     /SILENT
    一定要用有 /SILENT的,不然無法完成。
wmic可以查run了什麼process、有什麼msi軟體...等

  • 先於cmd中輸入wmic
  • /node:"test_remote"
  • 查process
    直接下process即可
  • delete process
    EX:process where name='outlook.exe' call terminate
mmc可查看或設定遠端的很多東西,如啟動或停止服務,調整使用者...

2010年8月10日 星期二

如何使用指令列看遠端安裝什麼軟體及將遠端電腦軟體移除,用WMIC,Using a Command Line to Uninstall Software on Remote PCs

由xp(含)後均有內建WMIC,利用它可以得到遠端電腦所以資訊,例如硬體內容,安裝了什麼軟體,或是可以反安裝軟體(Uninstall software),其功能非常強大,IT人員應要好好研究,以下我就實作了一兩樣,看看它有多好用。
IT人員如果要在自己的位置上uninstall remote PC的軟體或要看遠端電腦安裝什麼軟體得話大多數的人應該是利用遠端桌面,用管理者登入去移除軟體吧?!
如此做,沒有什麼不好,但是需要使用者暫停作業,有時候會不方便。
利用內建的WMIC其實就可以做到不錯效果。
  • IT需要有管理者的角色
  • 如果HOST Name中有【-】或【/】等符號,需用""括起來
  • 在DOS window中keyin 【wmic】 
  • 輸入您要控制的電腦【/node:"586-test"】
  • 如果要看其安裝了什麼軟體可下【product】指令
    • product會list很多資料,所以您也可以這樣做
      【/node:ANOTHEREXAMPLE product where vendor="Apple Inc." get name,vendor】
    • 也可用通用字元【/node:ComputerXYZ product where "vendor like 'adobe%'" get name,version,identifyingNumber】
  • uninstall software
    • /node:EXAMPLE product where name="Java(TM) 6 Update 7" call uninstall
      接下來會問是否要移除:Execute (\\586-test\ROOT\CIMV2:Win32_Product.IdentifyingNumber="{3248F0A8-6813-11D6-A77B-00B0D0160070}",Name="Java(TM) 6 Update 7",Version="1.6.0.70")->Uninstall() (Y/N/?)?,請輸入y即可
    • 如果不要有互動可加參數【/nointeractive】ex:/nointeractive flag like /node:EXAMPLE product where name="MobileMe Control Panel" call uninstall /nointeractive 
    • 如果有一堆電腦要反安裝得話Call Uninstall for a List of Machines
      您可將computer's names stored in c:\computers.txt,下指令>/fastfail:on /node:@"c:\computers.txt" product where name="Acrobat.com" call uninstall /nointeractive
      參數fastfail:on其作用為可快速的跳過沒有反應(開機)的電腦
    • 如果想直接run得話,可下指令:
      wmic /fastfail:on /node:@"FILENAME.txt" product where "name like 'microsoft office professional edition 2003'" call uninstall /nointeractive
以上文件可參考
http://community.spiceworks.com/how_to/show/179
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/wmic_overview.mspx?mfr=true
ex:
product where "vendor like 'sun%'" get name,version
product where "vendor like 'sun%'" call uninstall /nointeractive
wmic /output:"C:\Export.txt" /node:workstation product
process where name='notepad.exe' call terminate

WMIC /locale:ms_409 OS 

WMIC OS LIST BRIEF

WMIC OS GET csname, locale, bootdevice

WMIC /locale:ms_409 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:@workstns.txt /failfast:on PROCESS call create "\\server\share\installer.cmd"