Excel VBA automation Windows API and Reflection for regis -
im trying use windows api enter password reflection window pops up. problem can step through code using f8, , see password being entered , ok button pressed.
however, when run code, stops @ point password prompt window pops , cursor blinking waiting input.
what need make work please? have tried adding loop wait pop , tried application.ontime add delay before entering password both dont work.
i dont have experience using windows api, seems way go according colleagues, im communicating application outside excel. there api quirk causing this?
all appreciated.
the api declaration @ top is:
declare function findwindow lib "user32" alias "findwindowa" ( _ byval lpclassname string, _ byval lpwindowname string) long declare function setforegroundwindow lib "user32" ( _ byval hwnd long) long declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd long, byval wmsg long, byval wparam long, lparam any) long declare function setactivewindow lib "user32.dll" (byval hwnd long) long public declare function findwindowex lib "user32" alias "findwindowexa" _ (byval hwnd1 long, _ byval hwnd2 long, _ byval lpsz1 string, _ byval lpsz2 string) long
the password entered popup using function
function enterpassword() dim hdialog long, htextbox long, hbutton long, hok long dim hwnd long const wm_settext = &hc const bm_click = &hf5 hwnd = findwindow(vbnullstring, "reflection secure shell client") appactivate "reflection secure shell client" htextbox = findwindowex(hwnd, 0, "edit", "") sendmessage htextbox, wm_settext, byval 0, byval password hok = findwindowex(hwnd, 0, "button", "ok") setactivewindow hwnd sendmessage hok, bm_click, byval clng(0), byval clng(0) end function
in vba editor in excel, have added reference reflections object model, following vba code uses it.
sub changetype() dim rtcis_session new reflection4.session, long rtcis_session .visible = true .processdatacomm = false .connectiontype = connect_type .connectionsettings = "host " & connect_host .connectionsettings = "username " & connect_username .connect 'this loop not solve it!' until findwindow(vbnullstring, "reflection secure shell client") > 0 .wait 2 'wait 2 seconds' loop enterpassword 'line below not solve either!' application.ontime + timevalue("00:00:03"), "enterpassword"
Comments
Post a Comment