Jump to content

Employing WMIC


mr-es335
 Share

Go to solution Solved by mr-es335,

Recommended Posts

Good day,

I am porting all of my cmd/nircmd scripts to Autoit! and have the following that I could use some assistance with...as I have been unable to locate such information myself...

@echo off
:: -----------------------------------------------
wmic computersystem where caption="[existing computer name]" rename "[new computer name]"
:: -----------------------------------------------
wmic computersystem where name="%computername%" call joindomainorworkgroup name="[new domain name]"
:: -----------------------------------------------
wmic /namespace:\\root\default Path SystemRestore Call disable "C:\"
:: -----------------------------------------------
nircmd exitwin reboot ; Shutdown(2)

Thank you for any assistance one could provide.

Link to comment
Share on other sites

When I have to use WMIC.exe, I usually do the following:

$iPID = Run( @comspec & " /c %windir%\system32\wbem\wmic.exe [command arguments]" , "" , @SW_HIDE )
ProcessWaitClose ($iPID)

There are other methods too using:

ObjGet()

But it takes a bit more effort.

 

As for shutdown/reboot, have a look at the help file for:

Shutdown ( )
Edited by rsn
Link to comment
Share on other sites

Please have a look at Script-o-matic
It creates WMI commands in pure AutoIt for you.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Nothing I have tried myself. But when you search the forum for "joindomainorworkgroup" you will find some scripts describing how to add a computer.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

rsn and water,

Thank you both so very much for your assistance....very much appreciated!

water: I will consider Script-o-matic at a later point...just need to port all of my nircmds to autoit! at the moment. Thanks however for the tip...

nsr: Thank you for the sampling...I had to adjust the double-quotes to single-quotes...but other-than-that, all is working as it should! So again, "Thank you!"

For interest...here is the updated script...

#RequireAdmin
; -----------------------------------------------
; Previous: wmic computersystem where caption="[existing computer name]" rename "[new computer name]"
$iPID = Run( @comspec & " /c %windir%\system32\wbem\wmic.exe computersystem where caption='DESKTOP-7MLUNGI' rename 'RML_LABS_SYS'" , "" , @SW_HIDE)
ProcessWaitClose ($iPID)
; -----------------------------------------------
; Previous: wmic computersystem where name="%computername%" call joindomainorworkgroup name="[new domain name]"
$iPID = Run( @comspec & " /c %windir%\system32\wbem\wmic.exe computersystem where name='%computername%' call joindomainorworkgroup name='BETHEL'" , "" , @SW_HIDE)
ProcessWaitClose ($iPID)
; -----------------------------------------------
; Previous: wmic /namespace:\\root\default Path SystemRestore Call disable "C:\"
$iPID = Run( @comspec & " /c %windir%\system32\wbem\wmic.exe /namespace:\\root\default Path SystemRestore Call disable 'C:\'" , "" , @SW_HIDE)
ProcessWaitClose ($iPID)
Sleep(1000)
; -----------------------------------------------
; Previous: nircmd exitwin reboot
Shutdown(2)
; -----------------------------------------------

Thanks again...to you both!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...