lstPrograms.AddItem "Notepad" & " " & "is Not running"
End If
This works almost all the time, but I run into an error occassionally if I don't have rights to view the machine. I am the network admin so I have full rights to the system, but occassionally, the system will be unavailable.
How can I fix this so that if it can't check the computer, it will stop and let me know?
I keep getting the box saying "Retry" or "Switch" and locks up...
My program checks for a few different running processes.
When it gets to the For Each Process loop in the "IsProcessRunning" function, it hangs and gives me the error. After it cycles through the error several dozen times, it gives me err.number 462 - "Computer not available"
Since I am calling the function from a sub, if the function fails, it continues on within the sub (which calls the function several times)
I am in dire need of assistance with this.
This is the error I'm getting while it is cycling through:
Title -> Component Request Pending Text -> This application cannot be completed because the other application
is busy. Choose 'Switch To' to activate the busy application and correct the
problem. Options -> Switch To, Retry
But, when it does give me this error, it doesn't go to the Err: like I have it set to, it just keeps popping up this message.
I tried this with no success:
VB Code:
Private Sub cmdCheck_Click()
CheckRunning
End Sub
Function IsProcessRunning(strServer, strProcess)
On Error GoTo Err
Dim Process, strObject
IsProcessRunning = False
strObject = "winmgmts://" & strServer
For Each Process In GetObject(strObject).InstancesOf("win32_process") 'this is where it hangs and errors
If UCase(Process.Name) = UCase(strProcess) Then
IsProcessRunning = True
Exit Function
End If
Next
Exit Function
Err:
If Err.Number = 462 then
Exit Function
Else
Resume Next
End If
End Function
Public Sub CheckRunning()
On Error GoTo errhand
Dim strComputer, strProcess
lstPrograms.Clear
strComputer = lstComputers.Text
[I]'Check for notepad[/I]
strProcess = "notepad.exe"
If (IsProcessRunning(strComputer, strProcess) = True) Then
This isn't the method I am using though. It's not just finding out if the machine is available. I know how to do that.
Here's the scenario... I work for a company that has 80 locations connected via WAN. I am the network admin on 1 location. I do not have access to the other locations, although I can see their systems on the network. If I am running the function I listed above and click their machine, it crashes because I do not have rights to it. Same goes if the machine is off.
What I need is to know how to get it to stop trying to connect to it if I don't have rights or if the machine is off.
In other words, How do I code the function/sub above so that, upon an error...it will exit the sub. I tried the method in #11 above but couldn't get it to work.
Can someone please help me fix my code above so that it will stop executing upon an error?
I tried this and got a Bad Filename or number error when I wasn't connected, but after I connected, it wouldn't return anything either. Maybe you could map a drive?
VB Code:
Option Explicit
Private Sub Form_Load()
Dim str$
On Error GoTo badfile
str = Dir("\\192.168.1.100\c550\*.*")
MsgBox str
Exit Sub
badfile:
MsgBox Err.Description
End Sub
Hmm. It does work if I use a machine name instead of IP address. But doesn't crash if I substitute a server name that doesn't exist.
I get a "Permission denied" error from my W2K Workstation. Maybe it's NAV, I'm not sure. I have logged on. I think I'm an admin with this account. Have to check in the morning. I still think that trying to read the hard drive would be a trappable error if the machine is offline. It's a shame that it doesn't work with an IP address.
I'm willing to try this..but as I stated above, how do I code this so that when it tries connecting a machine that I do not have access to or that is off, it will stop the loop?
The code I listed to start with works perfectly, except under those conditions. I need to know how to get it to stop the function upon error.
Thank you everyone for your help, but I don't have a problem accessing the machine...I can do that just fine...I just need to know how to error trap my code above.
The problem I am also having is, the script I run to list all PC's on my network, lists the ones that are powered off as well.
This seems to be the problem. If it is listing machines that are off, then you have to check to see if the machine is off or not. It's been suggested that you try Pinging the machines, and I found that you can trap a Dir() error if you know the machine name. It takes a few seconds, but doesn't crash. If you can't read from a drive, then you should take the machine out of the list.
This seems to be the problem. If it is listing machines that are off, then you have to check to see if the machine is off or not. It's been suggested that you try Pinging the machines, and I found that you can trap a Dir() error if you know the machine name. It takes a few seconds, but doesn't crash. If you can't read from a drive, then you should take the machine out of the list.
Ok, I'm willing to try this. But it doesn't help with the second problem. As I stated, my network is part of a WAN. I have admin rights to my location, but not to others. The script lists all the pcs on the network, even the other locations because it does it via DNS.
How can I get this to halt if the machine is on, but I don't have access to it?
You can trap this error with an On Error statement, and take it out of the list if you cannot connect. Then run your script on the ones that you can connect to. Sorry if I didn't explain myself very well before.
FWIW, here is the script that scriptomatic2 wrote:
It doesn't crash if I use an invalid server. Maybe you can edit it to get what you need istead of using your script? I see that it adds a couple of flags.
VB Code:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("Laptop.") ' Comma delimited list of strings
You can trap this error with an On Error statement, and take it out of the list if you cannot connect. Then run your script on the ones that you can connect to. Sorry if I didn't explain myself very well before.
Thats the problem I've been trying to get solved. I have tried doing an On Error statement (look at #11 post on this thread) and it doesn't work.
This is what I've been asking for, someone to look at the code I have in #11 and tell me what I've done wrong. I just need to be able to do this:
On Error GoTo Err:
Err:
Exit function
'continue loop
The code you listed above is very similar to what I have. I will take a look at it and see if I can use it.
I tried the code you listed above with the same results. I figured out what is going on.
The attached picture shows the message I get if I do anything at all while the script is running. I found that if I let it sit there and process, it completes ok or at least stops running.
The code I originally listed works just fine as well.
Now what I need help with is, How can I present this so that it will not give me this message if the user decides to click around while it is processing?
I built that script using Scriptomatic2. I think they have a forum. Some M$ guys developed it, and have a few scripts on the web site. Maybe you can get some help there?