vb.net - Handling AD Error When Not Connected -
i'm using below code logge don user's logon name. works fine when connected network/domain. when offline, error on 3rd line:
principalserverdownexception unhandled
the server not contacted.
private sub form1_load(sender object, e eventargs) handles mybase.load dim currentaduser system.directoryservices.accountmanagement.userprincipal currentaduser = system.directoryservices.accountmanagement.userprincipal.current dim displayname string = currentaduser.givenname & " " & currentaduser.surname label5.text = displayname label4.text = getuserproperties() end sub
how can check, , return userful error user, such "not on network" or "not connected domain", exit? i've tried below, gives same error:
private sub form1_load(sender object, e eventargs) handles mybase.load dim currentaduser system.directoryservices.accountmanagement.userprincipal if system.directoryservices.accountmanagement.userprincipal.current nothing msgbox("network error: no connection domain") application.exit() else .... end if end sub
use try/catch
try dim currentaduser system.directoryservices.accountmanagement.userprincipal currentaduser = system.directoryservices.accountmanagement.userprincipal.current dim displayname string = currentaduser.givenname & " " & currentaduser.surname label5.text = displayname label4.text = getuserproperties() catch ex exception msgbox(...) end try
Comments
Post a Comment