WMIC ClientSiteName help

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

WMIC ClientSiteName help

13 Oct 2016, 02:09

Hey,

Code: Select all

wmic NTDOMAIN get ClientSiteName
the above CMD command get and show the Site Name of your domain.

now, I try to use it into a ahk script but I fail to do it:

Code: Select all

objWMIService := ComObjGet("winmgmts:{NTDOMAIN get ClientSiteName}

If (objStatus.StatusCode="MR1_MisradRashi") 
MsgBox yes 
Else 
MsgBox no 
}
Would like to get some help into it,
Thanks!
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: WMIC ClientSiteName help

13 Oct 2016, 10:20

The main issue is with your objWMIService := ComObjGet("winmgmts:{NTDOMAIN get ClientSiteName} line. See the WMI Tasks COM with AHK_L post in the old forums for details.

Based on that old post and Microsoft's Win32_NTDomain class documentation, I created the following code that returns the ClientSiteName value...

Code: Select all

objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" A_ComputerName "\root\cimv2")
For objComputer in objWMIService.ExecQuery("Select * from Win32_NTDomain") {
   ClientSite := objComputer.ClientSiteName
}

Msgbox %  ClientSite
BuLLDoG
Posts: 10
Joined: 02 Jul 2015, 16:28

Re: WMIC ClientSiteName help

13 Oct 2016, 15:19

Code: Select all

objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . A_ComputerName . "\root\cimv2")
WMISettings := objWMIService.ExecQuery("Select * from Win32_NTDomain")._NewEnum
While WMISettings[strCSItem]
	{
	SiteName :=  strCSItem.ClientSiteName[0]
	}
Msgbox, % SiteName
	
User avatar
Tomer
Posts: 314
Joined: 21 Aug 2016, 05:11

Re: WMIC ClientSiteName help

13 Oct 2016, 15:20

Thanks guys!
JJohnston2
Posts: 193
Joined: 24 Jun 2015, 23:38

Re: WMIC ClientSiteName help

14 Oct 2016, 14:45

Does anyone know if there is any particular advantage, safety, code clarity, etc. by using the second implementation with ._NewEnum in a While loop, vs. the other code with the for loop?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Botsy, m1m3r, mikeyww, patilizer, sebbulon and 55 guests