2016-08-18 29 views
0

我是具有兩個獨立環境的應用程序的業務用戶:測試和生產。重要的是我知道我在任何時候使用哪種環境,但應用程序沒有提供任何指示。窗口標題,佈局和所有功能都是相同的,程序中沒有功能來識別環境,所以我有責任記住我當前使用的是哪個.exe。從命令提示符啓動時更改應用程序的標題

我想到我可以修改快捷方式或使用命令提示符打開窗口,使標題清楚地標明「測試」或「生產」。

我嘗試了下面的內容,但是,當它按預期啓動應用程序時,窗口標題沒有改變。 (我啓動命令提示符時,懷疑這只是作品)

start "different title" fake.exe 

有沒有辦法做到這一點?任何想法將非常感激。

回答

0

您需要製作一個程序來執行此操作。

您需要調用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" 
相關問題