1

I'm juggling several different domain accounts these days and I've got about a dozen or so programs that need to be ran under specific ones. Some of them need to be ran under one domain account to access "this" and a different account to access "that". My solution has been to have shortcuts that leverage runas with the /user switch and that has worked fine.

I'd like to take it a step further, however. Is there a way to change the window title of the program I'm opening as well? For example, SSMS:

C:\Windows\System32\runas.exe /savecred /user:DOMAINA\username "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe"

I've tried a few variations of adding "title MYTITLE" and whatnot, but haven't found anything that works yet.

Maybe it's possible using Powershell?

tMole
  • 41
  • 3

2 Answers2

1

/savecred allows the account holder to run any command as you. Mightn't matter in your case but keep it in mind. It's only in Windows as a compatability thing. It will disappear in the future.

If it's a command prompt start cmd and use the title command then start your program.

C:\Users\User>title /?
Sets the window title for the command prompt window.

TITLE [string]

  string       Specifies the title for the command prompt window.

If a GUI program this sample VB6 code changes titles. You can use vb.net to make a program of it.

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Sub Main()
    On Error Resume Next
    hwindows = FindWindow(vbNullString, "Microsoft Works Calendar")
    Ret = SetWindowText(hwindows, "Calandar")
End Sub

This shows how to make vb.net programs and to convert vbs/vb6 http://social.msdn.microsoft.com/Forums/en-US/adcae113-4758-481a-a367-60d5d14d97d6/this-is-how-to-turn-vbs-and-js-files-into-exe-files-from-the-command-line-without-third-party-tools?forum=scripting

This is similar but is about manipulating Windows appactivate between multiple internet explorer instances (PS: On Win 7 and later sendmail is a reserved name so must be changed).

.NET framework (which powershell uses) doesn't have Windows commands in it, manipulating other program's windows is not in the .NET philosophy. This is probably the only area where .NET doesn't reflect the Window's API. .NET programs can manipulate their own windows through their forms object.

Community
  • 1
  • 1
Noodles
  • 1,981
  • 1
  • 11
  • 4
0

Since you mentioned powershell, it is very easy to control it's title, just plop this command at the top of any ps1 script. When it runs, you'll see the changed title.

$host.ui.RawUI.WindowTitle = "Changed Title"

or here is a re-useable powershell function.

Function Change_Console_Title ($title) {$host.ui.RawUI.WindowTitle = "$title"}

Usage

Change_Console_Title -title "Woot"
Knuckle-Dragger
  • 6,644
  • 4
  • 26
  • 41