My new WMI management DOS menu script

tweakradje

New member
Local time
11:52 PM
Messages
31
[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
...
 

Attachments

Last edited:

My Computer

OS
win7
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

Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
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:

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
HP Pavilion dv6-6c10us
OS
x64 (6.3.9600) Win8.1 Pro & soon dual boot x64 (6.1.7601) Win7_SP1 HomePrem
CPU
AMD A6-3420M APU with Radeon(tm) HD Graphics
Motherboard
Hewlett-Packard 1805
Memory
6.00 GB
Graphics Card(s)
AMD Radeon(TM) HD 6520G
Sound Card
(1) AMD High Definition Audio Device (2) IDT High Definiti
Monitor(s) Displays
HP W2072a 20" LCD (1600 x 900) @ 60 Hz
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
ST640LM0 00 HM641JI SATA Disk Device
Keyboard
Logitech k520 wireless KB
Mouse
Logitech m320 wireless mouse (bundled with KB)
Internet Speed
15/5 | 54 MB Wireless 'n'
Antivirus
Realtime: Defender or Avast | On-demand: Malwarebytes, ESET
Browser
IE 11 on Win8, IE 10 on win 7
Other Info
Media: [Gimp, Audacity, VLC] || Comm: [WEmail 2012, Skype] || Productivity: [OpenOffice,| Textpad] || Utils: [Sysinternals, cCleaner, Speccy, Defraggler]
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

OS
win7
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

OS
win7
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

Computer type
Laptop
Computer Manufacturer/Model Number
HP Elitebook 8540p
OS
Windows 7 Pro 32
CPU
Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Motherboard
Hewlett-Packard 1521
Memory
4,00 GB (Usable 2,98)
Graphics Card(s)
NVIDIA NVS 5100M
Sound Card
NVIDIA High Definition Audio
Screen Resolution
1600x900
Hard Drives
INTEL SSDSA2CW120G3
Antivirus
F-Secure Internet Security
Browser
IE, Firefox, Opera
Other Info
Sandboxie,
SRP (Software Restriction Policy),
EMET (Enhanced Mitigation Experience Toolkit),
WFC (Windows Firewall Control by BiniSoft),
Malwarebytes Premium
Latest version: 20141015-1

20141015-1: Fixed service dependency listing
 
Last edited:

My Computer

OS
win7
Back
Top