从命令提示符启动时更改应用程序的标题

时间:2016-08-18 15:22:14

标签: cmd titlebar

我是具有两个独立环境的应用程序的业务用户:测试和生产。重要的是,我知道我一直在使用哪种环境,但应用程序没有给出任何指示。窗口标题,布局和所有功能都是相同的,程序中没有用于识别环境的功能,因此我有责任记住我目前使用的.exe。

我认为我可以修改快捷方式或使用命令提示符打开窗口,使标题清楚地显示" TEST"或"生产"。

我尝试了下面的内容,但是,当它按预期启动应用程序时,窗口标题没有变化。 (我怀疑这只在启动命令提示时有效)

start "different title" fake.exe

有没有办法实现这个目标?任何想法都会非常感激。

1 个答案:

答案 0 :(得分:1)

你需要制作一个程序才能做到这一点。

您需要调用Windows的API。这是如何使标题栏更改程序。

使用记事本创建文件并将其命名为SetText.bas。将其存储在桌面上。

将其粘贴到其中。

Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Public Module MyApplication  

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Sub Main()
    On Error Resume Next
    Dim CmdLine As String
    Dim Ret as Long
    Dim A() as String
    Dim hwindows as long

    CmdLine = Command()
    If Left(CmdLine, 2) = "/?" Then
        MsgBox("Usage:" & vbCrLf & vbCrLf & "ChangeTitleBar Oldname NewName")
    Else
        A = Split(CmdLine, Chr(34), -1, vbBinaryCompare)
        hwindows = FindWindow(vbNullString, A(1))
        Ret = SetWindowText(hwindows, A(3))

    End If
End Sub
End Module

然后输入命令提示符窗口。

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%userprofile%\desktop\SetText.exe" "%userprofile%\desktop\settext.bas" /verbose

在桌面上创建了一个名为settext.exe的程序。使用

"%userprofile%\desktop\settext" "Untitled - Notepad" "A Renamed Notepad"