My new WMI management DOS menu script


  1. Posts : 31
    win7
       #1

    [CMD] My new WMI management menu script


    Dear Board,

    I have been busy with some DOS scripting and exploring the possibilities of using WMI for remote and local management: from a DOS box :)

    I wil past a copy of the current script here. The up-to-date script can be found on my website and look
    for wmitool.

    Kind Regards.

    Code:
    @echo off
    Color 17
    
    SET VERSION=20140925-1
    SET WMICOMP=%COMPUTERNAME%
    SET WMIACCOUNT=%USERNAME%
    SET WMIPW=
    SET WMIAD=WORKGROUP
    
    For /F %%d in ('"WMIC OS GET LocalDateTime|Findstr ."') Do SET TODAY=%%d
    If Defined TODAY set TODAY=%TODAY:~0,-17%
    
    :MAINMENU
    Title WMI Main menu on %WMICOMP% Version %VERSION%
    cls
    SET CHOICE=-
    Echo.
    Echo       WMI Main Menu on %WMICOMP%
    Echo.
    Echo    1  Select computer  [%WMICOMP%]
    Echo    2  Select remote account  [%WMIACCOUNT%]
    Echo    3  Computer Menu
    Echo    4  Hardware Menu
    Echo    5  Services menu
    Echo    6  Software menu
    Echo    7  Processes menu
    Echo    8  Accounts menu
    Echo    9  Troubleshoot menu
    Echo.
    Echo    0  Exit
    Echo.
    Set /P CHOICE=Make your choice: 
    Cls
    Set CREDENTIALS=
    If Not %WMICOMP%==%COMPUTERNAME% Set CREDENTIALS=/user:'%WMIACCOUNT%'
    If Not %WMICOMP%==%COMPUTERNAME% If Defined WMIPW Set CREDENTIALS=%CREDENTIALS% /password:'%WMIPW%'
    If %CHOICE%==0 Goto BYE
    If %CHOICE%==1 Echo. & Set /P WMICOMP=Computer Name or IP or @computerlist.txt [%WMICOMP%]: 
    If %CHOICE%==2 Echo. & Set /P WMIACCOUNT=Enter the remote account [%WMIACCOUNT%]: 
    If %CHOICE%==2 Echo. & Set /P WMIPW=Enter the remote password []: 
    If %CHOICE%==3 Goto COMPUTERMENU
    If %CHOICE%==4 Goto HARDWAREMENU
    If %CHOICE%==5 Goto SERVICESMENU
    If %CHOICE%==6 Goto SOFTWAREMENU
    If %CHOICE%==7 Goto PROCESSMENU
    If %CHOICE%==8 Goto ACCOUNTSMENU
    If %CHOICE%==9 Goto TROUBLEMENU
    Goto MAINMENU
    
    :COMPUTERMENU
    Title WMI Computer menu on %WMICOMP%
    cls
    SET CHOICE=-
    SET YESNO=-
    SET MYCMD=
    Echo.
    Echo       WMI Computer Menu on %WMICOMP%
    Echo.
    Echo    1  List Computer info
    Echo    2  Log Off the user
    Echo    3  Reboot PC
    Echo    4  Power Down PC
    Echo    5  List a folder
    Echo    6  List Printers
    Echo    7  Add a Printer
    Echo    8  Remove a Printer
    Echo.
    Echo    0  Main menu
    Echo.
    Set /P CHOICE=Make your choice: 
    If %CHOICE%==0 Goto MAINMENU
    Cls
    If %CHOICE%==1 Echo Computer Info: & wmic /node:%WMICOMP% %CREDENTIALS% COMPUTERSYSTEM Get /VALUE
    If %CHOICE%==2 Echo. & Set /P YESNO=Really Log Off current user on %WMICOMP% [Y/N]? 
    If %CHOICE%==2 If %YESNO%==y wmic /node:%WMICOMP% %CREDENTIALS% OS Where Primary="TRUE" Call Win32Shutdown 0
    If %CHOICE%==2 If %YESNO%==Y wmic /node:%WMICOMP% %CREDENTIALS% OS Where Primary="TRUE" Call Win32Shutdown 0
    If %CHOICE%==3 Echo. & Set /P YESNO=Really reboot system %WMICOMP% [Y/N]? 
    If %CHOICE%==3 If %YESNO%==y wmic /node:%WMICOMP% %CREDENTIALS% OS Where Primary="TRUE" Call Win32Shutdown 2
    If %CHOICE%==3 If %YESNO%==Y wmic /node:%WMICOMP% %CREDENTIALS% OS Where Primary="TRUE" Call Win32Shutdown 2
    If %CHOICE%==4 Echo. & Set /P YESNO=Really power off system %WMICOMP% [Y/N]? 
    If %CHOICE%==4 If %YESNO%==y wmic /node:%WMICOMP% %CREDENTIALS% OS Where Primary="TRUE" Call Win32Shutdown 8
    If %CHOICE%==4 If %YESNO%==Y wmic /node:%WMICOMP% %CREDENTIALS% OS Where Primary="TRUE" Call Win32Shutdown 8
    If %CHOICE%==5 Echo. & Set /P MYCMD= Enter a drive and foldername (like C:\temp): 
    If %CHOICE%==5 If Defined MYCMD Call :WHEREDRIVEPATH "%MYCMD%"
    If %CHOICE%==5 If Defined MYCMD Echo Folders:
    If %CHOICE%==5 If Defined MYCMD wmic /node:%WMICOMP% %CREDENTIALS% FSDIR Where %MYCMD% GET Archive,Compressed,Description,Hidden,LastAccessed,LastModified,System
    If %CHOICE%==5 If Defined MYCMD Echo Files:
    If %CHOICE%==5 If Defined MYCMD wmic /node:%WMICOMP% %CREDENTIALS% DATAFILE Where %MYCMD% GET Archive,Compressed,CreationDate,Description,FileSize,Hidden,LastAccessed,LastModified,System,Version
    If %CHOICE%==6 Echo Current Printers: & wmic /node:%WMICOMP% %CREDENTIALS%  PRINTER GET Caption,Comment,DetectedErrorState,DriverName,Location,PortName,ServerName
    If %CHOICE%==7 Echo. & Set /P MYCMD=Enter new printer name for %WMICOMP% (like \\server\printer): 
    If %CHOICE%==7 If Defined MYCMD wmic /node:%WMICOMP% %CREDENTIALS% PRINTER Call AddPrinterConnection "%WMICOMP%"
    If %CHOICE%==8 Call :BUILDMENU "wmic /node:%WMICOMP% %CREDENTIALS% PRINTER Get name /VALUE|FindStr =|Sort" "tokens=2 delims=="
    If %CHOICE%==8 If Not Defined MENUITEM Goto COMPUTERMENU
    If %CHOICE%==8 Call :DOUBLETHESLASH %MENUITEM%
    If %CHOICE%==8 Echo. & Set /P YESNO=Really delete printer %MENUITEM% [Y/N]? 
    If %CHOICE%==8 If %YESNO%==y wmic /node:%WMICOMP% %CREDENTIALS% PRINTER Where name="%MYCMD%" DELETE /nointeractive
    If %CHOICE%==8 If %YESNO%==Y wmic /node:%WMICOMP% %CREDENTIALS% PRINTER Where name="%MYCMD%" DELETE /nointeractive
    If Not %CHOICE%==- Pause
    Goto COMPUTERMENU
    
    :SERVICESMENU
    Title WMI Services menu on %WMICOMP%
    cls
    SET CHOICE=-
    SET YESNO=-
    SET MYCMD=
    Echo.
    Echo       WMI Services Menu on %WMICOMP%
    Echo.
    Echo    1  List Auto or Manual startup services 
    Echo    2  List Auto Startup services
    Echo    3  List all Running services
    Echo    4  List all Stopped services
    Echo    5  List all Disabled services
    Echo    6  Details of a service
    Echo    7  Start a service
    Echo    8  Stop a service
    Echo    9  Disable a service
    Echo.
    Echo    0  Main menu
    Echo.
    Set /P CHOICE=Make your choice: 
    If %CHOICE%==0 Goto MAINMENU
    Cls
    If %CHOICE%==1 Echo Enabled Services: & wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (startmode="auto" or startmode="manual") Get Name,DisplayName,State,Status,ExitCode,StartMode
    If %CHOICE%==2 Echo AutoStart Services: & wmic /node:%WMICOMP% %CREDENTIALS% SERVICE where startmode="auto" Get Name,DisplayName,State,Status,ExitCode,StartMode
    If %CHOICE%==3 Echo Running Services: & wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (state="Running") Get Name,DisplayName,State,Status,ExitCode,StartMode
    If %CHOICE%==4 Echo Stopped Services: & wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (state="Stopped") Get Name,DisplayName,State,Status,ExitCode,StartMode
    If %CHOICE%==5 Echo Disabled Services: & wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (StartMode="Disabled") Get Name,DisplayName,State,Status,ExitCode,StartMode
    If %CHOICE%==6 Call :BUILDMENU "wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Get displayname /VALUE|FindStr =|Sort" "tokens=2 delims=="
    If %CHOICE%==6 If Not Defined MENUITEM Goto SERVICESMENU
    If %CHOICE%==6 Echo Details of "%MENUITEM%" service: & wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (displayname="%MENUITEM%") LIST FULL
    If %CHOICE%==7 Call :BUILDMENU "wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (state="Stopped" AND Not StartMode="Disabled") Get displayname /VALUE|FindStr =|Sort" "tokens=2 delims=="
    If %CHOICE%==7 If Not Defined MENUITEM Goto SERVICESMENU
    If %CHOICE%==7 wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (displayname="%MENUITEM%") Call StartService
    If %CHOICE%==8 Call :BUILDMENU "wmic /node:%WMICOMP% %CREDENTIALS% SERVICE Where (state="Running") Get displayname /VALUE|FindStr =|Sort" "tokens=2 delims=="
    If %CHOICE%==8 If Not Defined MENUITEM Goto SERVICESMENU
    ...
    My new WMI management DOS menu script Attached Files
    Last edited by tweakradje; 11 May 2015 at 15:15. Reason: Attached latest version: 20150426-1
      My Computer


  2. Posts : 1,049
    Windows 7 Pro 32
       #2

    Very nice work! Took a look at your web site too. Haven't seen it before, only Rob's. Thanks for the link.

    My latest "DOS" project was published yesterday in a Tutorial. The coolest thing with it is downloading and parsing web pages (including creating and executing VB scripts). If you're interested you can find it here
      My Computer


  3. Posts : 6,458
    x64 (6.3.9600) Win8.1 Pro & soon dual boot x64 (6.1.7601) Win7_SP1 HomePrem
       #3

    This is very good. I played around with the same sort of command file, but not to the extent you have.

    I've attached the command file I created from your code box to make it easier for members to try.
    Due to the upload limitations of the forum - it is a batch file (WMImenu.bat)

    You might want to add a copyright statement to the code (I added it to the command file I created)
    © Copyright 2014 Tweakradje
    All Rights Reserved


    I'm not sure if it's required, but I ran it in an elevated command prompt

    Thanks,

    Bill
    .
    Last edited by Slartybart; 25 Sep 2014 at 19:11. Reason: fix echo in bat
      My Computer


  4. Posts : 31
    win7
    Thread Starter
       #4

    Thanks guys. Of course it is very easy to add more menu's and commands yourself. This is what I could think of over the past days. Still need to figure out how to add/remove users to local groups though.
    Feel free to use parts or bring suggestions.
      My Computer


  5. Posts : 31
    win7
    Thread Starter
       #5

    Tookeri said:
    Very nice work! Took a look at your web site too. Haven't seen it before, only Rob's. Thanks for the link.

    My latest "DOS" project was published yesterday in a Tutorial. The coolest thing with it is downloading and parsing web pages (including creating and executing VB scripts). If you're interested you can find it here
    Thanks. Didn't know it was possible to call with pointers to variables. Only the values with %VALUE%.
    I have learned again from your ToLowerCase. Thx.
      My Computer


  6. Posts : 1,049
    Windows 7 Pro 32
       #6

    I can't take credit for all tricks in the script. Some are cool stuff I've found somewhere and kept for future use. So we all learn from each other :)
      My Computer


  7. Posts : 31
    win7
    Thread Starter
       #7

    Latest version: 20141015-1

    20141015-1: Fixed service dependency listing
    Last edited by tweakradje; 15 Oct 2014 at 14:39. Reason: Attached latest version: 20141001-3 in OP
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:19.
Find Us