English 中文(简体)
• 如何检查国家峰会特定港口的运行情况
原标题:How to check the process running on specific port in NSIS

Im利用国家空间学会开发一台安装装置供我使用。 我需要与这个安装厂商做的是检查80号港口是否可用,如果该港口没有向80号停靠的加工名称发出错误信息,则该港口是否可供使用。

我找到了一种办法,检查80港是否可用。 为此,我使用了Ports.nsh作为原始材料:

${If} ${TCPPortOpen} 80
 MessageBox MB_OK|MB_ICONSTOP "PORT 80 is already using by another program..."
 Abort
${EndIf}

但是,由于这一原因,我无法在该港口找到一个运行进程。 我需要发出错误信息,例如:

//Skype is running on port 80 and close Skype to continue with the installation. 

请允许我就此帮助我。 感谢。

问题回答

页: 1 我无法找到适当的方式,在我刚刚使用VBalle语来检查加工名称,并称其为正文。 Follwing是该守则。

页: 1

Dim WshShell, oExec, key
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("netstat -o -n -a")
key = "0.0:80"

Dim values
values = checkPortStatus(oExec, key)
portInUse = values(0)
input = values(1)

If portInUse Then
  x = InStrRev(input, " ")

  ProcessID = Mid(input, x+1)

  commandTxt = "tasklist /FI " & Chr(34) & "PID eq " & ProcessID & Chr(34)

Dim oExec2, key2
Set oExec2 = WshShell.Exec(commandTxt)
key2 = ProcessID

Dim values2
values2 = checkPortStatus(oExec2, key2)
Found = values2(0)
input2 = values2(1)

If Found Then
    y = InStr(input2, " ")
    ExeName = Left(input2, y-1)
        WScript.StdOut.WriteLine "Port 80 is using by " & ExeName
End If
End If
 ## If we explicitly set a Success code then we can avoid this.
WScript.Quit 512

Function checkPortStatus(oExec, key)
portInUse = false
input = ""
Do While True

     If Not oExec.StdOut.AtEndOfStream Then
          input = oExec.StdOut.ReadLine()
          If InStr(input, key) <> 0 Then 
          Found Port 80
                portInUse = true
                Exit DO
          End If
     Else
        Exit DO
     End If
     WScript.Sleep 100
Loop

Do While oExec.Status <> 1
 WScript.Sleep 100
Loop
Dim values(1)
values(0) = portInUse
values(1) = input

checkPortStatus = values

End Function

/Installer.nsi

${If} ${TCPPortOpen} 80
 GetTempFileName $0
     File /oname=$0 `TestPort80.vbs` 
     nsExec::ExecToStack `"$SYSDIRCScript.exe" $0 //e:vbscript //B //NOLOGO`
 Pop $0
 Pop $1
 MessageBox MB_OK|MB_ICONSTOP  $1 
 Abort
${EndIf}




相关问题
Correct place to install demostration projects?

With the new Windows 7 restrictions (well, new to Windows Vista anyways), we can no longer install demo projects to %ProgramFilesFolder%OurApplicationdemo since restricted users will not be able to ...

.deb package conffiles problem

I am distributing one of my applications using a .deb package, but have a problem relating to one of the files. The distribution includes a database file which is constantly updated by the app, on a ...

Closing an application using WiX

In creating my WiX installer I have run into an issue when trying to close an application before installing the upgrade. Below is an example of how I am attempting to do this. <util:...

VS 2005 Setup - HKCU

I am trying to fix an existing application that uses a Visual Studio 2005 setup project. We are requiring it to work on limited user accounts for XP, our app is written in C# for .Net 2.0. It writes ...

Do I want Publish or Release Build in VB.net?

I wrote a little (like 40 lines little) Winforms application with VB.net in Visual Studio 2010. Now I ve released the code as a Google Code project. It s easy for a developer to get the source but I d ...

configsource and installer

I have an project csproj, with app.config file, and logging Ent.Library section using configsource attribute. The logging section is in ahother file Configloggingconfiguration.config. I have a ...

热门标签