Color so Blog

Color's Blog Site !

在使用Jmeter的时候,发现没有可用的.exe可执行文件启动jmeter。
首先准备好相应的ico文件:favicon.ico

  1. 安装rsrc
    go get github.com/akavel/rsrc
    
  2. 创建manifest文件, 命名:main.exe.manifest :
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
            version="1.0.0.0"
            processorArchitecture="x86"
            name="controls"
            type="win32">
    </assemblyIdentity>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                    type="win32"
                    name="Microsoft.Windows.Common-Controls"
                    version="6.0.0.0"
                    processorArchitecture="*"
                    publicKeyToken="6595b64144ccf1df"
                    language="*">
            </assemblyIdentity>
        </dependentAssembly>
    </dependency>
        </assembly>
    
  3. 生成syso文件.
    rsrc -manifest main.exe.manifest -ico favicon.ico -o main.syso

  4. 将生成的main.syso文件拷贝到main.go同级目录

  5. 编译生成jmeter.exe
    go build -ldflags=”-H windowsgui” jmeter\

6.附上我的golang代码main.go:
package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main(){
    //cmdSys := "start"
    vstart := "cscript.exe"
    vbs := "D:/Program/apache-jmeter-5.1.1/apache-jmeter-5.1.1/bin/jmeter.vbs"
    //cmdPath := "D:/Program/apache-jmeter-5.1.1/apache-jmeter-5.1.1/bin/jmeter.bat"
    start := exec.Command(vstart,vbs)
    start.Stdout = os.Stdout

    err := start.Run()
    fmt.Println(err)
}

7.注意:D:/Program/apache-jmeter-5.1.1/apache-jmeter-5.1.1/bin/jmeter.bat是解压安装jmete的路径中的启动批处理命令文件。
8.vbs文件用于启动时关闭cmd窗口jmeter.vbs:
Set ws = CreateObject(“Wscript.Shell”)
ws.run “cmd /c D:/Program/apache-jmeter-5.1.1/apache-jmeter-5.1.1/bin/jmeter.bat”,vbhide
9.

Post Author: admin

2 Replies to “为exe程序添加上相应的ico图标”

发表评论

电子邮件地址不会被公开。 必填项已用*标注