2015-02-08 90 views
0


我有一個很奇怪的問題,我的C#應用​​程序之一:
沒有顯示窗口C#應用程序處理中的telnet

它的主要目的是爲每[user32.dll] SendMessage發送命令。這在常規機器上或從批處理文件或命令行窗口啓動時沒有問題。

如果我從Telnet,SSH或PHP的shell_exec()執行我的應用程序,應用程序無法找到目標窗口句柄,即使它可以找到目標進程。

我已經寫了一段測試代碼向你展示我的問題:

public static int Main(string[] argv) 
{ 
    foreach (Process p in Process.GetProcesses()) 
     Console.Write(p.MainWindowHandle.ToInt32().ToString("x8") + " - " + p.ProcessName + "\n"); 

    Console.ReadKey(true); 

    return 0; 
} 

結果是在「正常」的方式執行時,以下幾點:

00000000 - BTTray 
00000000 - SkypeC2CAutoUpdateSvc 
00000000 - svchost 
00000000 - DLMSession 
00000000 - conhost 
00000000 - chrome 
00000000 - GoogleCrashHandler64 
000b0a58 - devenv 
00000000 - FreeSSHDService 
00000000 - GoogleCrashHandler 
00000000 - mDNSResponder 
00000000 - conhost 
00000000 - AcSvc 
00000000 - taskeng 
00000000 - lsm 
00000000 - chrome 
00000000 - UMVPFSrv 
00000000 - lsass 
00000000 - IntelliTrace 
00000000 - PresentationFontCache 
00000000 - conhost 
00000000 - smss 
00000000 - AppleMobileDeviceService 
00000000 - services 
00000000 - audiodg 
00000000 - RCIMGDIR 
00000000 - password_manager 
00000000 - chrome 
00000000 - tvt_reg_monitor_svc 
00000000 - netsession_win 
00030abe - devenv 
00000000 - chrome 
00000000 - WmiPrvSE 
00000000 - PrintIsolationHost 
00000000 - IpOverUsbSvc 
00000000 - msvsmon 
00000000 - WLIDSVC 
00000000 - UNS 
0003008a - tpnumlkd 
00000000 - chrome 
00000000 - mitsijm 
00000000 - cmd 
00000000 - svchost 
00000000 - httpd 
00000000 - QDLService2kLenovo 
00000000 - spoolsv 
00000000 - winlogon 
00000000 - TCPSVCS 
00000000 - WUDFHost 
00000000 - SynTPHelper 
00000000 - vmnat 
00000000 - conhost 
00000000 - chrome 
00000000 - NisSrv 
00000000 - svchost 
00000000 - netsession_win 
00000000 - mysqld 
00000000 - RegSrvc 
00000000 - vmnetdhcp 
00000000 - chrome 
00000000 - cmd 
00000000 - SynTPLpr 
00000000 - iPodService 
00000000 - rundll32 
00000000 - msseces 
00000000 - csrss 
00000000 - svchost 
00000000 - TrustedInstaller 
00000000 - nvvsvc 
000101aa - SynTPEnh 
00000000 - wininit 
00000000 - nvxdsync 
00000000 - btwdins 
00000000 - MFUSNM~1 
00000000 - chrome 
00000000 - EvtEng 
00000000 - dgnsvc 
00000000 - taskeng 
00000000 - vmware-tray 
00000000 - svchost 
00000000 - PrivacyIconClient 
00000000 - MSBuild 
00000000 - AcDeskBandHlpr 
00000000 - TpScrex 
00200738 - notepad++ 
00000000 - PnkBstrA 
00000000 - chrome 
00000000 - cssauth 
00000000 - chrome 
00000000 - SUService 
00000000 - svchost 
00000000 - chrome 
00000000 - AdAppMgrSvc 
00000000 - chrome 
00000000 - LMS 
00000000 - WmiPrvSE 
00000000 - IntelliTrace 
00000000 - svchost 
00000000 - csrss 
00000000 - DTLite 
00000000 - TPONSCR 
00000000 - iTunesHelper 
00000000 - agent 
00000000 - chrome 
00000000 - sqlwriter 
00000000 - DZSVC64 
00000000 - conhost 
00000000 - rundll32 
00000000 - sshd 
00000000 - acrotray 
00000000 - chrome 
00000000 - SvcGuiHlpr 
00000000 - telnet 
00000000 - tpnumlk 
00000000 - loggerservice 
00000000 - wlanext 
00000000 - svchost 
00000000 - explorer 
00000000 - TpShocks 
00000000 - micmute 
00000000 - mounter 
00000000 - AcPrfMgrSvc 
00000000 - TPOSDSVC 
00000000 - BlackGlassEnhanced 
00000000 - svchost 
002e03f6 - chrome 
00000000 - TPHKSVC 
00000000 - SpotifyWebHelper 
00000000 - unsecapp 
00000000 - ibmpmsvc 
00000000 - cammute 
000303d8 - clover 
00000000 - nvvsvc 
00000000 - svchost 
00000000 - ISUSPM 
00000000 - password_manager 
00000000 - wodCmdTerm 
00000000 - TeamViewer_Service 
00000000 - FLxHCIm 
00000000 - vmware-usbarbitrator64 
00000000 - rundll32 
00160f3c - wmplayer 
00000000 - conhost 
0002001c - explorer 
00000000 - dwm 
00000000 - CISVC 
00000000 - svchost 
00000000 - svchost 
00091068 - cmd 
00000000 - test implementation.vshost 
00000000 - svchost 
00000000 - chrome 
00000000 - taskhost 
00000000 - svchost 
00000000 - armsvc 
00000000 - OSPPSVC 
00000000 - conhost 
00000000 - MCPLaunch 
00000000 - svchost 
00030ff6 - WMP 
00000000 - vmware-authd 
00000000 - conhost 
00000000 - conhost 
00000000 - WUDFHost 
00000000 - chrome 
00000000 - SkypeC2CPNRSvc 
00000000 - iviRegMgr 
00000000 - vmware-hostd 
00000000 - chrome 
00000000 - wuauclt 
00000000 - httpd 
00000000 - taskhost 
00000000 - cygrunsrv 
00000000 - UnsignedThemesSvc 
00000000 - MsMpEng 
00000000 - WLIDSVCM 
00000000 - System 
00000000 - DLG 
00000000 - SearchIndexer 
00000000 - Idle 

正如你所看到的 - 有很多沒有窗口句柄的進程,但像VisualStudio(devnev)這樣的進程有一個。
如果我運行相同的命令通過量的Telnet,SSH等我得到以下結果:

00000000 - BTTray 
00000000 - SkypeC2CAutoUpdateSvc 
00000000 - svchost 
00000000 - DLMSession 
00000000 - conhost 
00000000 - chrome 
00000000 - GoogleCrashHandler64 
00000000 - devenv 
00000000 - FreeSSHDService 
00000000 - GoogleCrashHandler 
00000000 - mDNSResponder 
00000000 - conhost 
00000000 - AcSvc 
00000000 - taskeng 
00000000 - lsm 
00000000 - chrome 
00000000 - UMVPFSrv 
00000000 - lsass 
00000000 - IntelliTrace 
00000000 - PresentationFontCache 
00000000 - conhost 
00000000 - smss 
00000000 - AppleMobileDeviceService 
00000000 - services 
00000000 - audiodg 
00000000 - RCIMGDIR 
00000000 - password_manager 
00000000 - chrome 
00000000 - tvt_reg_monitor_svc 
00000000 - netsession_win 
00000000 - devenv 
00000000 - chrome 
00000000 - WmiPrvSE 
00000000 - PrintIsolationHost 
00000000 - IpOverUsbSvc 
00000000 - msvsmon 
00000000 - WLIDSVC 
00000000 - UNS 
00000000 - tpnumlkd 
00000000 - chrome 
00000000 - mitsijm 
00000000 - cmd 
00000000 - svchost 
00000000 - httpd 
00000000 - QDLService2kLenovo 
00000000 - spoolsv 
00000000 - winlogon 
00000000 - TCPSVCS 
00000000 - WUDFHost 
00000000 - SynTPHelper 
00000000 - vmnat 
00000000 - conhost 
00000000 - chrome 
00000000 - NisSrv 
00000000 - svchost 
00000000 - netsession_win 
00000000 - mysqld 
00000000 - RegSrvc 
00000000 - vmnetdhcp 
00000000 - chrome 
00020062 - cmd 
00000000 - SynTPLpr 
00000000 - iPodService 
00000000 - rundll32 
00000000 - msseces 
00000000 - csrss 
00000000 - svchost 
00000000 - TrustedInstaller 
00000000 - nvvsvc 
00000000 - SynTPEnh 
00000000 - wininit 
00000000 - nvxdsync 
00000000 - btwdins 
00000000 - MFUSNM~1 
00000000 - chrome 
00000000 - EvtEng 
00000000 - dgnsvc 
00000000 - taskeng 
00000000 - vmware-tray 
00000000 - svchost 
00000000 - PrivacyIconClient 
00000000 - MSBuild 
00000000 - AcDeskBandHlpr 
00000000 - TpScrex 
00000000 - notepad++ 
00000000 - PnkBstrA 
00000000 - chrome 
00000000 - cssauth 
00000000 - chrome 
00000000 - SUService 
00000000 - svchost 
00000000 - chrome 
00000000 - AdAppMgrSvc 
00000000 - chrome 
00000000 - LMS 
00000000 - WmiPrvSE 
00000000 - IntelliTrace 
00000000 - svchost 
00000000 - csrss 
00000000 - DTLite 
00000000 - TPONSCR 
00000000 - iTunesHelper 
00000000 - agent 
00000000 - chrome 
00000000 - sqlwriter 
00000000 - DZSVC64 
00000000 - conhost 
00000000 - rundll32 
00000000 - sshd 
00000000 - acrotray 
00000000 - chrome 
00000000 - SvcGuiHlpr 
00000000 - telnet 
00000000 - tpnumlk 
00000000 - loggerservice 
00000000 - wlanext 
00000000 - svchost 
00000000 - explorer 
00000000 - TpShocks 
00000000 - micmute 
00000000 - mounter 
00000000 - AcPrfMgrSvc 
00000000 - TPOSDSVC 
00000000 - BlackGlassEnhanced 
00000000 - svchost 
00000000 - chrome 
00000000 - TPHKSVC 
00000000 - SpotifyWebHelper 
00000000 - unsecapp 
00000000 - ibmpmsvc 
00000000 - cammute 
00000000 - clover 
00000000 - nvvsvc 
00000000 - svchost 
00000000 - ISUSPM 
00000000 - password_manager 
00000000 - wodCmdTerm 
00000000 - TeamViewer_Service 
00000000 - FLxHCIm 
00000000 - vmware-usbarbitrator64 
00000000 - rundll32 
00000000 - wmplayer 
00000000 - conhost 
00000000 - explorer 
00000000 - dwm 
00000000 - CISVC 
00000000 - svchost 
00000000 - svchost 
00000000 - cmd 
00000000 - test implementation.vshost 
00000000 - svchost 
00000000 - chrome 
00000000 - taskhost 
00000000 - svchost 
00000000 - armsvc 
00000000 - OSPPSVC 
00000000 - conhost 
00000000 - MCPLaunch 
00000000 - svchost 
00000000 - WMP 
00000000 - vmware-authd 
00000000 - conhost 
00000000 - conhost 
00000000 - WUDFHost 
00000000 - chrome 
00000000 - SkypeC2CPNRSvc 
00000000 - iviRegMgr 
00000000 - vmware-hostd 
00000000 - chrome 
00000000 - wuauclt 
00000000 - httpd 
00000000 - taskhost 
00000000 - cygrunsrv 
00000000 - UnsignedThemesSvc 
00000000 - MsMpEng 
00000000 - WLIDSVCM 
00000000 - System 
00000000 - DLG 
00000000 - SearchIndexer 
00000000 - Idle 

正如你可以看到,每一道工序 - 除了cmd - 已經沒有窗口句柄。
我的問題是:我該如何解決這個問題?或者Windows以某種方式阻止通過Telnet訪問窗口?

非常感謝你

回答

2

Telnet運行在與你的用戶會話不同的Windows會話中。通常,所有服務都在會話0上運行,並且所有用戶應用程序都在會話1+中運行。當您運行應用程序時,您只能看到與您的應用程序在同一個會話中運行的那些窗口名稱。閱讀更多關於惱人的Windows'會話機制(嘗試谷歌它)。

相關問題