Jump to content

My script cause an Application Error, help needed


Recommended Posts

I'm stuck at this error where i'll get an popup displaying: 

"The instruction at 0x053beaec referenced memory at 0x00000042. The memory could not be read.

Click on OK to terminate the program"

I'm using the libmysql.dll to execute queries to the database every once and a while to retrieve data - my logic tells me that the error might causes it.

My code is below this text

 

Thanks in advance!

func do_initialize()

   ; variables:
   local $reg_load_hive, $reg_unload_hive

   ; write to log:
   filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Started: OSDGUI 1.0" & @crlf)
   filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "WinPE Version: " & _
   regread("hkey_local_machine\software\microsoft\windows nt\currentversion", "currentversion") & "." & _
   regread("hkey_local_machine\software\microsoft\windows nt\currentversion", "currentbuild") & @crlf)
   filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "RootPath is '" & $root_path & "'" & @crlf)
   filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Bootserver is '" & iniread($osd_config, "server", "ip", "") & "'" & @crlf)

   ; read disk configs:
   global $sql_startup = _ezmysql_startup()
   sleep(250) ; pause script
   if not $sql_startup then

      filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
      filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
      msgbox(0x10, "OSDGUI", "Could not start SQL library, please check logs for errors.", 0, $osd_loader)
      run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

      endif

         global $sql_connect = _ezmysql_open(iniread($osd_config, "sqlserver", "ip", ""), _
                                             iniread($osd_config, "sqluser", "id", ""), _
                                             iniread($osd_config, "sqlpassword", "key", ""), _
                                             iniread($osd_config, "sqldb", "name", ""), _
                                             iniread($osd_config, "sqlport", "port", "") _
                                             )
            sleep(125) ; pause script
            if not $sql_connect then

               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
               filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
               msgbox(0x10, "OSDGUI", "No connection to SQL database, please check logs for errors.", 0, $osd_loader)
               run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

                  endif

                  global $sql_query = _ezmysql_query("SELECT disk_config_id FROM disk_config ORDER BY disk_config_id ASC")
                  sleep(125) ; pause script
                  if not $sql_query then

                     filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
                     filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
                     msgbox(0x10, "OSDGUI", "There was a problem executing an sql query, please check logs for errors.", 0, $osd_loader)
                     run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

                        endif

                        for $i = 1 to _ezmysql_rows()

                           local $disk_config_id = _ezmysql_fetchdata()
                           filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Reading DiskConfig '" & "DiskConfig" & $disk_config_id[0] & "'" & @crlf) ; write to log

                           next

                              _ezmysql_close()
                              guictrlsetdata($label_text, "")
                              sleep(80) ; pause script
                              guictrlsetdata($label_text, $label_array[0]) ; write process on screen

                                 ; get computer name from existing installation:
                                 filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Try to find computername from existing installation" & @crlf) ; write to log
                                 filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Launch process: 'reg.exe LOAD HKLM\osd ""d:\windows\system32\config\SYSTEM""'" & @crlf) ; write to log
                                 sleep(10) ; pause script

                                    ; load system hive and pull name:
                                    $reg_load_hive = runwait("reg.exe LOAD HKLM\osd " & """d:\windows\system32\config\system""", @systemdir, @sw_hide) ; execute reg.exe and load hive
                                    sleep(20) ; pause script
                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Exit code = " & $reg_load_hive & @crlf) ; write to log

                                    $reg_name = regread("hkey_local_machine\osd\controlset001\control\computername\computername", "computername")
                                    sleep(20) ; pause script

                                    if $reg_name then filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "System hive mounted from " & """d:\system32\windows\config\SYSTEM""" & @crlf) ; write to log
                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Pulled name= '" & $reg_name & "'" & @crlf) ; write to log

                                       ; unload system hive:
                                       filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Launch process: 'reg.exe UNLOAD HKLM\osd'" & @crlf) ; write to log
                                       sleep(10) ; pause script

                                       $reg_unload_hive = runwait("reg.exe UNLOAD HKLM\osd", @systemdir, @sw_hide) ; execute reg.exe and unload hive
                                       sleep(20) ; pause script

                                       filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Exit code = " & $reg_unload_hive & @crlf) ; write to log
                                       filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "System hive unmounted" & @crlf) ; write to log

                                          ; set computer name:
                                          filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Name pulled from BIOS= '" & @computername & "'" & @crlf) ; write to log
                                          if $reg_name = "" then

                                             $reg_name = @computername
                                             filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "NewComputerName= '" & $reg_name & "'" & @crlf) ; write to log

                                             else

                                                filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "NewComputerName= '" & $reg_name & "'" & @crlf) ; write to log

                                                endif

                                                   sleep(500) ; pause script
                                                   guictrlsetdata($label_text, $label_array[1]) ; write process on screen
                                                   sleep(20) ; pause script

                                                      ; create osdgui:

                                                      $osd_gui = guicreate("", 582, 459, -1, -1, $ws_popup + $ws_dlgframe)
                                                      $osd_btn_settings = guictrlcreateicon("logo.ico", "", 9, 8, 64, 64)
                                                      $osd_btn_install = guictrlcreatebutton("Install", 210, 415, 162, 35)
                                                      guictrlsetcursor($osd_btn_settings, 0)

                                                      ; gui elements:
                                                      $label_title = guictrlcreatelabel("Windows OS Deployment", 110, 7, 362, 22)
                                                      $label_description = guictrlcreatelabel("Specify the required information to install a operating" & @crlf _
                                                                                            & "system and click Install to begin deployment of the" & @crlf _
                                                                                            & "selected image", 110, 32, 362, 53)
                                                      local $label_function[6] = [guictrlcreatelabel("ComputerName", 110, 92, 362, 22) _
                                                                               ,  guictrlcreatelabel("Operating system", 110, 148, 362, 22) _
                                                                               ,  guictrlcreatelabel("Disk configuration", 110, 204, 362, 22) _
                                                                               ,  guictrlcreatelabel("Username", 110, 275, 362, 22) _
                                                                               ,  guictrlcreatelabel("Password", 110, 331, 175, 22) _
                                                                               ,  guictrlcreatelabel("Confirm password", 297, 331, 175, 22)]

                                                      global $input_computer_name = guictrlcreateinput($reg_name, 110, 117, 362, 24)
                                                      guictrlsetlimit($input_computer_name, 15, 0)
                                                      guictrlsetstyle($input_computer_name, $es_uppercase)
                                                      global $combo_select_os = guictrlcreatecombo("", 110, 172, 362, 120, $cbs_dropdownlist)
                                                      global $combo_select_disk = guictrlcreatecombo("", 110, 228, 362, 120, $cbs_dropdownlist)
                                                      global $input_username = guictrlcreateinput("", 110, 299, 175, 24)
                                                      global $input_password1 = guictrlcreateinput("", 110, 355, 175, 24, $es_password)
                                                      global $input_password2 = guictrlcreateinput("", 297, 355, 175, 24, $es_password)

                                                      ; font properties:
                                                      guictrlsetfont($label_title, 12, 700, 0, "arial", 1)
                                                      guictrlsetfont($label_description, 10, 400, 0, "arial", 1)

                                                      for $i = 0 to ubound($label_function[5]) +5

                                                         guictrlsetfont($label_function[$i], 10, 700, 0, "arial", 1)

                                                         next

                                                            guictrlsetfont($input_computer_name, 10, 400, 0, "arial", 1)
                                                            guictrlsetfont($combo_select_os, 10, 400, 0, "arial", 1)
                                                            guictrlsetfont($combo_select_disk, 10, 400, 0, "arial", 1)
                                                            guictrlsetfont($input_username, 10, 400, 0, "arial", 1)
                                                            guictrlsetfont($input_password1, 10, 400, 0, "arial", 1)
                                                            guictrlsetfont($input_password2, 10, 400, 0, "arial", 1)
                                                            guictrlsetfont($osd_btn_install, 10, 400, 0, "arial", 1)

                                                               ; read and enumerate wim files and disk configs from database:
                                                               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "ImagesFolder is '" & $wim_path & "'" & @crlf) ; write to log
                                                               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Folder was found" & @crlf) ; write to log
                                                               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Enumerating files" & @crlf) ; write to log

                                                               $sql_connect = _ezmysql_open(iniread($osd_config, "sqlserver", "ip", ""), _
                                                                                            iniread($osd_config, "sqluser", "id", ""), _
                                                                                            iniread($osd_config, "sqlpassword", "key", ""), _
                                                                                            iniread($osd_config, "sqldb", "name", ""), _
                                                                                            iniread($osd_config, "sqlport", "port", "") _
                                                                                            )
                                                               sleep(250) ; pause script
                                                               if not $sql_connect then

                                                                  filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
                                                                  filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
                                                                  msgbox(0x10, "OSDGUI", "No connection to SQL database, please check logs for errors.", 0, $osd_loader)
                                                                  run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

                                                                     endif

                                                                        $sql_query = _ezmysql_query("SELECT image_id, image_name FROM images ORDER BY image_id ASC")
                                                                        sleep(125) ; pause script
                                                                        if not $sql_query then

                                                                           filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
                                                                           filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
                                                                           msgbox(0x10, "OSDGUI", "There was a problem executing an sql query, please check logs for errors.", 0, $osd_loader)
                                                                           run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

                                                                              endif

                                                                                 for $i = 1 to _ezmysql_rows()

                                                                                    global $row = _ezmysql_fetchdata()
                                                                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Found a WIM File" & @crlf) ; write to log
                                                                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Add image: '" & $row[0] & ". " & $row[1] & "'" & " to list" & @crlf) ; write to log
                                                                                    guictrlsetdata($combo_select_os, $row[0] & ". " & $row[1])

                                                                                    next

                                                                                       if $row[0] & $row[1] = "" then

                                                                                          filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "ImagesFolder= ''" & @crlf) ; write to log
                                                                                          filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Folder not found" & @crlf) ; write to log

                                                                                          endif
                                                                                          sleep(75) ; pause script

                                                                                             $sql_query = _ezmysql_query("SELECT disk_config_id, disk_config_name FROM disk_config ORDER BY disk_config_id ASC")
                                                                                             sleep(125) ; pause script
                                                                                             if not $sql_query then

                                                                                                filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
                                                                                                filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
                                                                                                msgbox(0x10, "OSDGUI", "There was a problem executing an sql query, please check logs for errors.", 0, $osd_loader)
                                                                                                run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

                                                                                                   endif

                                                                                                      for $i = 1 to _ezmysql_rows()

                                                                                                         $row = _ezmysql_fetchdata()
                                                                                                         guictrlsetdata($combo_select_disk, $row[0] & ". " & $row[1])

                                                                                                         next

                                                                                                            _guictrlcombobox_setcursel($combo_select_os, 0)
                                                                                                            _guictrlcombobox_setcursel($combo_select_disk, 0)
                                                                                                            sleep(20) ; pause script

                                                                                                               ; get client information:
                                                                                                               sleep(10) ; pause script
                                                                                                               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Gathering client information" & @crlf) ; write to log
                                                                                                               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Get Modelname" & @crlf) ; write to log
                                                                                                               filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Get Manufacturer" & @crlf) ; write to log
                                                                                                               sleep(10) ; pause script

                                                                                                                  ; get wmi object:
                                                                                                                  global $obj_wmi = objget("winmgmts:\\" & @computername & "\root\cimv2")
                                                                                                                  sleep(20) ; pause script
                                                                                                                  if not isobj($obj_wmi) then

                                                                                                                     msgbox(0x10, "Error", "No such object", 0, $osd_loader) ; display error
                                                                                                                     sleep(1000) ; pause script
                                                                                                                     guidelete($osd_loader) ; delete gui

                                                                                                                     else

                                                                                                                        ; get modelname and manufacturer:
                                                                                                                        local $get_computer_info = $obj_wmi.execquery("select * from win32_computersystem") ; execute query for wmi object
                                                                                                                        sleep(20) ; pause script

                                                                                                                        for $fetch_computer_info in $get_computer_info

                                                                                                                           global $computer_model = $fetch_computer_info.model ; modelname
                                                                                                                           sleep(10)
                                                                                                                           global $computer_vendor = $fetch_computer_info.manufacturer ; vendor

                                                                                                                           next

                                                                                                                              ; set computer name given to model and manufacturer to unknown if not found
                                                                                                                              if $computer_model = "" or $computer_model = "" then $computer_model = "Not Determined"

                                                                                                                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Modelname: '" & $computer_model & "'" & @crlf) ; write to log
                                                                                                                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Manufacturer: '" & $computer_vendor & "'" & @crlf) ; write to log
                                                                                                                                    filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Gathering client information done" & @crlf) ; write to log

                                                                                                                                       $sql_query = _ezmysql_query("INSERT INTO `computers` (`computer_name`, `ip_address`, `computer_model`)" & " VALUES " & "(" & _
                                                                                                                                       '"' & $reg_name & '", "' & @ipaddress1 & '", "' & $computer_model & '")')
                                                                                                                                       sleep(125) ; pause script
                                                                                                                                       if not $sql_query then

                                                                                                                                          filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "SQL ERROR: '" & _ezmysql_errmsg() & "'" & @crlf)
                                                                                                                                          filecopy("x:\program files\osd\*.log", "z:\logs\", 1)
                                                                                                                                          msgbox(0x10, "OSDGUI", "There was a problem executing an sql query, please check logs for errors.", 0, $osd_loader)
                                                                                                                                          run("cmd.exe /c" & "wpeutil Reboot", @systemdir, @sw_hide)

                                                                                                                                             endif
                                                                                                                                             sleep(125) ; pause script

                                                                                                                                                ; close connection to database:
                                                                                                                                                _ezmysql_close()

                                                                                                                                                sleep(1000) ; pause script
                                                                                                                                                guidelete($osd_loader) ; delete gui $osdloader
                                                                                                                                                sleep(80) ; pause script
                                                                                                                                                guisetstate(@sw_show, $osd_gui)
                                                                                                                                                hotkeyset("{F10}", "display_cmd")
                                                                                                                                                filewrite($log_file, _nowdate() & " " & _nowtime() & " " & "Ready" & @crlf) ; write to log

         endif

endfunc
Edited by doestergaard
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...