In the past few days, the company is engaged in a standalone exercise edition (ASP Program In order to encapsulate the program, netbox2.8. over the past years of experience, the pressure on technical support is quite high. we set a port by ourselves. When we get to the user, this port may have been occupied. the boss talked to me last week and asked me to solve the problem this week, so that this problem will not occur in this year's standalone practice version. as netbox has stopped development, there is no technical support. so I only studied it myself. it is found that the netbox language is very similar to VB. It can be said that it is the VB syntax, and netbox's own object is added. after yesterday's solution, I optimized it again today. I think there should be no problems. sent here to help colleagues who have been or are still suffering from this problem.
If you think or find other problems, you can leave a message to solve them together.
Dim Httpd
Dim Path
Dim SERVERPORT
Dim B _createport
Path = Netbox. applicationpath
Netbox. configfile = Path & " Main. ini "
SERVERPORT = Netbox. config ( " Server " , " Port " )
Set Httpd = Netbox. Createobject ( " Netbox. httpserver " )
If SERVERPORT = "" Then
SERVERPORT = 80
Netbox. config ( " Server " , " Port " ) = SERVERPORT
End If
Shell . Service. icon = Path & Netbox. config ( " Config " , " Icon " )
Shell . Service. runservice " Nbweb " , " Netbox Web Server " , " Netbox HTTP Server Sample "
Sub createport () Sub Createport ()
SERVERPORT = 0
Do While (SERVERPORT < 1025 Or SERVERPORT > 65535 )
If Httpd. Create ( "" , 0 ) = 0 Then
If Httpd. localport > 1024 And Httpd. localport < 65535 Then
SERVERPORT = Httpd. localport
End If
End If
Loop
End sub
Sub onservicestart () Sub Onservicestart ()
Set Service = Shell . Service
If Httpd. Create ( "" , SERVERPORT) = 0 Then
If B _createport = True Then
Dim B _saveconfig
B _saveconfig = Shell . Msgbox ( " The exercise system detects the currently allocated port [ " & SERVERPORT & " ] It Can Be Used. Do you want to save it? " , " Save Port " , 33 )
If B _saveconfig = 1 Then
Netbox. config ( " Server " , " Port " ) = SERVERPORT
End If
End If
Set Host = Httpd. addhost ( "" , " \ " )
Set Host1 = Host. addfolder ( " Webexam " , " \ Webexam " )
Host1.enablescript = True
Host1.adddefault " Default. asp "
Host1.adddefault " Default.htm "
Httpd. Start
Shell . Execute " "" " & Netbox. sysinfo ( " Folder_programfiles " ) & " \ Internet Explorer \ iexplore. EXE "" http: // localhost: " & SERVERPORT & " /Your app "
Else
Shell . Msgbox " The exercise system detects the port to be used [ " & SERVERPORT & " ] The port is occupied by another program. The system will reassign the port! Click OK to continue " , " Prompt information " , 64
B _createport = True
Createport
Onservicestart
End If
End sub
Sub onservicestop () SubOnservicestop ()
Httpd. Close
Shell. Halt0
Shell. Quit0
End sub
Sub onservicepause () SubOnservicepause ()
Httpd. Stop
End sub
Sub onserviceresume () SubOnserviceresume ()
Httpd. Start
End sub