REading a remote file using WMI; unable to connect to remote machi

REading a remote file using WMI; unable to connect to remote machi

Post by Q29yZXkgVG » Sun, 09 Mar 2008 07:39:01


ey Habib,

Try this function:

Function PingComputer(strComputer)
'Accepts computer name, returns bln = True or False

On Error Resume Next
'PingStatus = False 'Assume Failure
strWorkstation = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkstation &
"\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
For Each objPing In colPings
Select Case objPing.StatusCode
Case 0 PingComputer = True
Case Else PingComputer = False
End Select
Next
Set objWMIService = Nothing
Set colPings = Nothing
End Function

'==================================================================


To use:

strComputer = "remoteBox"

If PingComputer(strComputer) then
wscript.echo "Machine is on network"
else
wscript.echo "Machine is not on network"
end if


-Corey Thomas
MCSE/MCSA/MDBA

P.S. If you want more detail on the ping response, use the function below.

'==================================================================

Function PingStatus(strComputer)
'Accepts computer name, returns str = ping status

On Error Resume Next
strWorkstation = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkstation &
"\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
For Each objPing in colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Successful Ping"
Case 11001 PingStatus = "Buffer Too Small"
Case 11002 PingStatus = "Destination Net Unreachable"
Case 11003 PingStatus = "Destination Host Unreachable"
Case 11004 PingStatus = "Destination Protocol Unreachable"
Case 11005 PingStatus = "Destination Port Unreachable"
Case 11006 PingStatus = "No Resources"
Case 11007 PingStatus = "Bad Option"
Case 11008 PingStatus = "Hardware Error"
Case 11009 PingStatus = "Packet Too Big"
Case 11010 PingStatus = "Request Timed Out"
Case 11011 PingStatus = "Bad Request"
Case 11012 PingStatus = "Bad Route"
Case 11013 PingStatus = "TimeToLive Expired Transit"
Case 11014 PingStatus = "TimeToLive Expired Reassembly"
Case 11015 PingStatus = "Parameter Problem"
Case 11016 PingStatus = "Source Quench"
Case 11017 PingStatus = "Option Too Big"
Case 11018 PingStatus = "Bad Destination"
Case 11032 PingStatus = "Negotiating IPSEC"
Case 11050 PingStatus = "General Failure"
Case Else PingStatus = "Unable to determine cause of failure"
End Select
Next
Set objWMIService = Nothing
Set colPings = Nothing

End Function

'==================================================================

"HSalim[MVP]" wrote:

 
 
 

1. problems accessing remotes files when using remote desktop connect

2. Unable to connect via Remote Desktop (Remote Assistance)

I have a W2K3 server that I can't connect to using Remote Desktop for
administrative purposes. I can log in locally and I can log in to my other
servers via Remote Desktop. In the event log I get Event ID: 1219, "Logon
rejected for DOMAIN.COM\username. Unable to obtain Terminal Server User
Configuration. Error: Access is denied."

No one in the Domain Admin group can log in using Remote Desktop.

We are not using Terminal Services, this is for Remote Admin. services only.

Your assistance is appreciated.

Thank you.

3. Unable to connect to clients via Remote Assistance or Remote Desktop

4. Unable to delete a registry key on remote pc using WMI

5. connect to remote wmi using asp.net with imersonation

6. Connect to remote WMI using asp.net 2.0 with impersonating the cal

7. Remote Assistance fails to connect, remote remote host name could not be resolved

8. Read a file from a remote computer - WMI

9. Cannot connect to Remote Desktop from a remote client using VPN (but VPN tunnel is okay)

10. Users cannot connect to remote desktops by using the Remote Wo

11. Can connect using Remote Desktop but not Remote Desktop Web connec

12. Users cannot connect to remote desktops by using the Remote Workpl

13. Can connect using Remote Desktop but not Remote Desktop Web co