Home All Groups Group Topic Archive Search About

how to check computername exists, before logon remotely

Author
9 Jan 2006 9:15 AM
James
vb.net 2003

i wrote a windows service that does threading. My codes  are

a) the service thread will read a list of machine from a text file
(machines.txt).
b) it then logon using the below
Dim returnValue As Boolean = LogonUser(m_ntid, m_domain, m_pwd,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, tokenHandle)

if returnvalue = true

    do part (c)

else

   write a event log that computers do not exists

end if

c) once logon successful, it will do a wmi search for hotfix

Dim searchstring As String = "SELECT * FROM Win32_QuickFixEngineering WHERE
HotFixID = " & "'" & m_kbhotfix & "'"

Dim searcher As New ManagementObjectSearcher("\\" + computer +
"\root\CIMV2", searchstring)

if hotfix is found, then write an event log to my pc that runs the services.

It works fine for the following scenarios

1) the logon id is a administrator of remote machines

I deliberately setup some bogus machines in my machines.txt. By right these
machines do not exists. However the returnvalue always go to "true", which
mean "false" machines the thread ignore and do not write any event log. How
can i check machine exists first or can the code generate some try/catch
that machines do not exist or i do not have permission ? all i want is that
returnvalue = false so that my eventlogs can write something ?

Author
9 Jan 2006 12:23 PM
Ken Tucker [MVP]
Hi,

List Computers in network with api
http://www.vb-tips.com/default.aspx?ID=0bacc0e6-1e52-4991-8a88-dad5ea63a743

List computers in network with active directory classes
http://www.vb-tips.com/default.aspx?ID=2b7d8d24-665f-43d4-9553-9c76953e41cf

Ken
----------------
Show quoteHide quote
"James" <jkk***@hotmail.com> wrote in message
news:eQKpSzPFGHA.208@tk2msftngp13.phx.gbl...
> vb.net 2003
>
> i wrote a windows service that does threading. My codes  are
>
> a) the service thread will read a list of machine from a text file
> (machines.txt).
> b) it then logon using the below
> Dim returnValue As Boolean = LogonUser(m_ntid, m_domain, m_pwd,
> LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, tokenHandle)
>
> if returnvalue = true
>
>    do part (c)
>
> else
>
>   write a event log that computers do not exists
>
> end if
>
> c) once logon successful, it will do a wmi search for hotfix
>
> Dim searchstring As String = "SELECT * FROM Win32_QuickFixEngineering
> WHERE HotFixID = " & "'" & m_kbhotfix & "'"
>
> Dim searcher As New ManagementObjectSearcher("\\" + computer +
> "\root\CIMV2", searchstring)
>
> if hotfix is found, then write an event log to my pc that runs the
> services.
>
> It works fine for the following scenarios
>
> 1) the logon id is a administrator of remote machines
>
> I deliberately setup some bogus machines in my machines.txt. By right
> these machines do not exists. However the returnvalue always go to "true",
> which mean "false" machines the thread ignore and do not write any event
> log. How can i check machine exists first or can the code generate some
> try/catch that machines do not exist or i do not have permission ? all i
> want is that returnvalue = false so that my eventlogs can write something
> ?
>
>
>
>
>
>
>
>
>
>
>
>