2014-09-25 36 views
0

這幾天我在處理幾個不同的域帳戶,並且我有大約十幾個程序需要在特定的程序下運行。其中一些需要在一個域帳戶下運行以訪問「this」和另一個帳戶以訪問「該」。我的解決方案是有快捷鍵,可以利用runas和/ user開關並且工作正常。使用runas執行程序並更改窗口標題

但是,我想更進一步。有沒有辦法改變我打開的程序的窗口標題?例如,SSMS:

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

我已經嘗試添加「稱號MYTITLE」和諸如此類的一些變化,但沒有發現任何的作品呢。

也許有可能使用Powershell?

回答

1

/savecred允許帳戶持有人像您一樣運行任何命令。可能無關緊要,但請記住它。它只是在Windows中作爲兼容性的東西。它將在未來消失。

如果是命令提示符啓動cmd並使用title命令,然後啓動您的程序。

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

TITLE [string] 

    string  Specifies the title for the command prompt window. 

如果一個GUI程序本示例VB6代碼更改標題。你可以使用vb.net來製作一個程序。

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 

這表明如何使vb.net程序和轉換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

這是類似的,但大約是操作Windows appactivate between multiple internet explorer instances(PS:在Win 7和更高版本的sendmail是一個保留名稱,以便必須改變)。

.NET框架(其中powershell使用)沒有Windows命令,操縱其他程序的窗口不在.NET哲學。這可能是.NET不能反映Window API的唯一領域。 .NET程序可以通過它們的窗體對象來操作自己的窗口。

0

既然您提到了powershell,那麼控制它的標題非常容易,只需在ps1腳本的頂部放置此命令即可。運行時,您會看到更改後的標題。

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

或者這裏是一個可重複使用的powershell函數。

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

使用

Change_Console_Title -title "Woot"