Win32_Share on Remote Host Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Grendahl
Posts: 170
Joined: 30 Sep 2013, 08:21

Win32_Share on Remote Host

01 Dec 2016, 14:57

Please help me figure out how to alter this snippet, which works fine on my local machine, to be able to list shares on a remote host. It must be able to run WMI as a different username than the script is running under.

Simplest terms - this powershell command is what I want stored in an AHK variable/array/etc.
Get-WMIObject -Class Win32_Share -ComputerName "HostName" -Credential "HostLogin"

Code: Select all

;NOTE: Need to figure out how to pass -Credentials with the command, as well as to define a remote host name

;http://msdn.microsoft.com/en-us/library/aa394132%28v=vs.85%29.aspx
PropertyList := "Name,Path,Description"
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . A_ComputerName . "\root\cimv2")
WQLQuery = Select * From Win32_Share
colDiskDrive := objWMIService.ExecQuery(WQLQuery)._NewEnum
While colDiskDrive[objDiskDrive] 
	Loop, Parse, PropertyList, `,
		DiskDriveInfo  .= A_index = 1 ? objDiskDrive[A_LoopField] . "`n"  : "`t" . A_LoopField . ":`t" . objDiskDrive[A_LoopField] . "`n"
ListVars
MsgBox %DiskDriveInfo%
ExitApp

ESC::ExitApp
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Win32_Share on Remote Host  Topic is solved

01 Dec 2016, 16:10

I don't have multiple computers available to test, or actual WMI knowledge, but according to the Internet, replacing objWMIService := ... with the following might work:

Code: Select all

Server := "HostName"
User := "HostLogin"
Password := "HostPassword"

wmiLocator := ComObjCreate("WbemScripting.SWbemLocator")
objWMIService := wmiLocator.ConnectServer(Server, "root\cimv2", User, Password)
User avatar
Grendahl
Posts: 170
Joined: 30 Sep 2013, 08:21

Re: Win32_Share on Remote Host

01 Dec 2016, 16:25

That's perfect, thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Noitalommi_2, ulysim and 320 guests