Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: My new WMI management DOS menu script

25 Sep 2014   #1
tweakradje

win7
 
 
[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
...





Attached Files
File Type: zip wmitool.zip (7.7 KB, 7 views)
My System SpecsSystem Spec
.
25 Sep 2014   #2
Tookeri

Windows 7 Pro 32
 
 

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 System SpecsSystem Spec
25 Sep 2014   #3
Slartybart

x64 (6.3.9600) Win8.1 Pro & soon dual boot x64 (6.1.7601) Win7_SP1 HomePrem
 
 

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)
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
.


My System SpecsSystem Spec
.

25 Sep 2014   #4
tweakradje

win7
 
 

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 System SpecsSystem Spec
25 Sep 2014   #5
tweakradje

win7
 
 

Quote   Quote: Originally Posted by Tookeri View Post
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 System SpecsSystem Spec
25 Sep 2014   #6
Tookeri

Windows 7 Pro 32
 
 

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 System SpecsSystem Spec
30 Sep 2014   #7
tweakradje

win7
 
 

Latest version: 20141015-1

20141015-1: Fixed service dependency listing
My System SpecsSystem Spec
Reply

 My new WMI management DOS menu script




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Context menu customization and management
Hi all, this is my first post in this forum and I hope to get some ideas here :) I have a Windows 7 64bit problem that disturbs me for some quite time, and by now I have found no real solution. It is about the context menu, and here primarily for explorer (e.g. when right-clicking on a...
Customization
Start Menu privacy tab management
When I click my start menu, the recently used programs do not load. I've read numerous articles saying to go into the properties, click on the "start menu" tab and then under the privacy section, check off what I want. That works all find and dandy if the privacy option is enabled, but mine is...
General Discussion
Computer Management - Missing the Properties Menu
I stumbled upon this thread, but it's pretty old, so I thought I'd start a new one. In XP in Computer Management, you could right click on the computer and get a Properties option. This was especially useful if you were connecting to a remote computer. For example, you could edit the environment...
Network & Sharing
Add Computer Management to Desktop Context Menu
@ Mark: Hello. Nice to meet you. I know this is an old thread, but I wanted to keep my question based on your initial post or instruction. I stumbled upon this thread in my searching for this very issue. THANK YOU for your dedication and work with this issue and your solution!!! My...
Customization
Computer Management - Add to Desktop Context Menu
How to Add or Remove "Computer Management" to Desktop Context Menu This tutorial will allow you to add or remove Computer Management from the desktop context menu for all users in Vista, Windows 7, and Windows 8. You must be logged in as an administrator to be able to add or remove this...
Tutorials
How Do I lock my Menu Bar? File Edit View Tools menu
I've noticed that Windows 7 doesn't seem to like the Menu bar and it hides it from users unless they hit *alt* which briefly brings it back. How do I lock this in place? I got to view and toolbars, but manu bar is not an option and there is no way to lock it there. please advise. (File Edit View...
Customization


Our Sites

Site Links

About Us

Find 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 11:19.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App