Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing title of an application when launching from command prompt

Tags:

cmd

titlebar

I am a business user of an application that has two separate environments: test and production. It is important that I know which environment I'm using at all times, but the application gives no indication. Window title, layout, and all features are identical, and there is no function in the program to identify the environment, so it's my responsibility to remember which .exe I'm currently using.

I had the thought that I could modify the shortcut or use a command prompt to open the window such that the title clearly says "TEST" or "PRODUCTION".

I attempted the below, but, while it launches the application as expected, there is no change to the window title. (I suspect this only works when launching command prompts)

start "different title" fake.exe

Is there a way to accomplish this? Any ideas would be very much appreciated.

like image 928
Keppy Avatar asked Aug 18 '16 15:08

Keppy


1 Answers

You need to make a program to do this.

You need to call the Windows' API. This is how to make a title bar changing program.

Create a file using notepad and call it SetText.bas. Store it on your desktop.

Paste this into it.

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

Then type in a command prompt window.

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

A program has been created on your desktop called settext.exe. To use

"%userprofile%\desktop\settext" "Untitled - Notepad" "A Renamed Notepad"
like image 103
Ndlr Avatar answered Oct 17 '22 03:10

Ndlr