Only in VB...



  • I just found this code that somebody is recommending people to use to "automatically register ocx files programatically"... Brace yourself... This could only happen in VB...

    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10

    Private Sub Register(OCXName As String)
    SetCursorPos 32, Screen.Height / 15 - 10
    mouse_event MOUSEEVENTF_ABSOLUTE, 32, Screen.Height / 15 - 10, 1, 1
    mouse_event MOUSEEVENTF_LEFTDOWN, 32, Screen.Height / 15 - 10, 1, 1
    mouse_event MOUSEEVENTF_LEFTUP, 32, Screen.Height / 15 - 10, 1, 1
    SendKeys ("R")
    SendKeys ("regsvr32 " & OCXName)
    SendKeys (vbKeyReturn)
    End Sub

    Private Sub Form_Click()
    Register "blahblah.ocx"
    End Sub



  • this should've been on the front page :)



  • This is just wrong...

    I don't know what else to say.



  • Nice one. I've seen similar stuff done by a whole bunch of driver installers, from big companies even.

    How does this guy format a disk? Run notepad.exe and start sending zeroes?
    Actually moving the mouse pointer over the start button is kinda cute though, I would have never thought of that!



  • runs away, screaming



  • I would have submitted it for the front page, but it was a reply in a forum, not in production code



  • They need to embed SetCursorPos into a loop to actually move the cursor, not just jump it ;-)



  • Wow.... just... WOW.... not even sending WindowKey + R to open the run menu.... I really can't believe that large corporations do this though. There are code reviews correct? If this code was reviewed, and approved, then there are some serious issues. As Denis Leary would say, www.wtf.com!



  • Holy crap! That is horrible!



    On my work computer, this would probably do nothing but 'click' a
    random systray icon, and it would take me a few minutes to figure out
    wtf went wrong--and that's only if I'm RDPing in. (Taskbar is normally
    on left-hand side of right-hand display, with clock disabled.) Then of
    course I'd determine that I don't have time for this kind of idiocy and
    I'd go find some other tool to use.



    The author of this code should be flogged. Doesn't regsvr32.exe have command line switches?!




  • Oh for heaven's sake! I just realized that he's still expecting the
    user to click 'OK' and everything he supposedly did with those sendkeys
    could have been done with whatever VB has for exec().



    Forget flogging, excommunicate him.



  • @Brendan Kidwell said:

    Oh for heaven's sake! I just realized that he's still expecting the user to click 'OK' and everything he supposedly did with those sendkeys could have been done with whatever VB has for exec().

    Forget flogging, excommunicate him.

    Two things:

    The programmer of this atrocity did include a SendKeys(vbKeyReturn), which is equivalent to pressing (Enter), so the user wouldn't have to press OK.

    But yes, this could all have been accomplished by using Shell "regsvr32.exe ocxname"



  • @Albatross said:

    @Brendan Kidwell said:

    Oh for heaven's sake! I just realized that he's still expecting the user to click 'OK' and everything he supposedly did with those sendkeys could have been done with whatever VB has for exec().

    Forget flogging, excommunicate him.

    Two things:

    The programmer of this atrocity did include a SendKeys(vbKeyReturn), which is equivalent to pressing (Enter), so the user wouldn't have to press OK.

    But yes, this could all have been accomplished by using Shell "regsvr32.exe ocxname"


    The extra "OK" click I was referring to was for the "everything is fine; nothing is broken" alert that regsvr32.exe would produce.



  • Of course, the best way would be to LoadLibrary, then use GetProcAddress to get the entry point of DllRegisterServer, and then finally call DllRegisterServer. But that would just be too easy and portable for any VB coder.


  • ♿ (Parody)

    FYI -- I've posted this code today. Good stuff.



  • lol, yeah... had to recomment lol ;-)


Log in to reply