Chris,

Yeah looks like you were correct. Looks like he apparently used a combination of some of my code and some of your code which are not set the same, so he should have used your example instead of mixing them. Anyways... that said, if you would make a minor modification to your UDF then it would be able to handle the call better when a computer name is not supplied. Currently your method of the connection is using a UNC even on a local system which means a user must have Admin rights to access it. By making the call to the local namespace without the UNC a user without Admin rights can still run the script. It wouldn't complete the task if the user didn't have Admin rights (it would not be able to modify the service) but the WMI connection would work, so that if it was only a query it would complete.

Function fnWMIService($sService,$sMethod,Optional $sComputer)
Dim $objWMI,$objSrvc,$nul
If Not $sComputer $sComputer = ''
Else
$sComputer = '\\'+Join(Split($sComputer,'\'),'',3)+'\'
EndIf
$objWMI = GetObject("WinMgmts:{impersonationLevel=impersonate}"+$sComputer+"root\cimv2")
If @ERROR<0 Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$objSrvc = $objWMI.ExecQuery('Select * from Win32_Service WHERE Name = "'+$sService+'"')
For Each $objSrvc In $objSrvc
$nul=Execute("$"+"fnWMIService = $"+"objSrvc."+$sMethod)
Next
EndFunction


 

Here is his code re-worked that should work well. Not really sure what's up with checking a Display Name of one item and then setting another item. Don't have the product installed to confirm why.

 
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')


Dim $Remote,$sService,$SetService
$Remote = 'Citrix01'
$sService = 'AventailAutoSOCKS'
"Service Name: " fnWMIService('Aventail Connect','DisplayName',$Remote)
If @ERROR
@ERROR " | " @SERROR ?
Else
$SetService=fnWMIService($sService,'ChangeStartMode(Disabled)',$Remote)
? 'Change Startup Type Mode Error: ' + @ERROR + ' : ' + @SERROR
$SetService=fnWMIService($sService,'StopService',$Remote)
? 'Change Service Status Error: ' + @ERROR + ' : ' + @SERROR
EndIf


Function fnWMIService($sService,$sMethod,Optional $sComputer)
Dim $objWMI,$objSrvc,$nul
If Not $sComputer $sComputer = ''
Else
$sComputer = '\\'+Join(Split($sComputer,'\'),'',3)+'\'
EndIf
$objWMI = GetObject("WinMgmts:{impersonationLevel=impersonate}"+$sComputer+"root\cimv2")
If @ERROR<0 Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$objSrvc = $objWMI.ExecQuery('Select * from Win32_Service WHERE Name = "'+$sService+'"')
For Each $objSrvc In $objSrvc
$nul=Execute("$"+"fnWMIService = $"+"objSrvc."+$sMethod)
Next
EndFunction