2014-09-05 34 views
1

上運行我編譯應用程序使用的.NET Framework 4,因爲我需要這在XP和Server 2003不支持.NET框架4.5的工作。問題是,現在運行良好的XP和2003點的服務器,但不是我的服務器上2012 Server 2012中具有.NET 4.5,從我讀過.NET 4.5是在.NET 4應用.NET 4的框架編譯不會Server 2012的

它下面的錯誤向後兼容我收到我的2012服務器上:如果您單擊繼續,應用程序將忽略此錯誤並嘗試繼續


未處理的異常發生在您的應用程序。如果您單擊退出,應用程序將立即關閉。

該系統找不到指定的文件。

詳情:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box. 

************** Exception Text ************** 
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified 
    at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) 
    at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) 
    at MyApplication.Form1.DirectoryExporter_Click(Object sender, EventArgs e) 
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
    at System.Windows.Forms.Button.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 


************** Loaded Assemblies ************** 
mscorlib 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18449 built by: FX451RTMGDR 
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll 
---------------------------------------- 
MyApplication 
    Assembly Version: 1.0.0.0 
    Win32 Version: 1.0.0.0 
    CodeBase: file:///C:/Users/administrator.DM/Desktop/MyApplication.exe 
---------------------------------------- 
System.Windows.Forms 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll 
---------------------------------------- 
System.Drawing 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll 
---------------------------------------- 
System 
    Assembly Version: 4.0.0.0 
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL 
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll 
---------------------------------------- 

************** JIT Debugging ************** 
To enable just-in-time (JIT) debugging, the .config file for this 
application or computer (machine.config) must have the 
jitDebugging value set in the system.windows.forms section. 
The application must also be compiled with debugging 
enabled. 

For example: 

<configuration> 
    <system.windows.forms jitDebugging="true" /> 
</configuration> 

When JIT debugging is enabled, any unhandled exception 
will be sent to the JIT debugger registered on the computer 
rather than be handled by this dialog box. 

這裏是被稱爲此時代碼:

public string get_regValue(string userroot, string subkey, string keyname, string app) 
     { 
      string userRoot = userroot; 
      string subKey = subkey; 
      string keyName = userRoot + "\\" + subKey; 

      string regValue = (string)Registry.GetValue(keyName, keyname, null); 
      regValue = regValue + app; 

      return regValue; 
     } 

     private void DirectoryExporter_Click(object sender, EventArgs e) 
     { 
      // Button to Launch the Directory Exporter 
      string regKey; 
      RegistryKey openKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Dell"); 
      // Checks for key, if null (empty) get 32 bit key 
      if (openKey == null) 
      { 
       // 32 bit key 
       regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Dell"; 
      } 
      else 
      { 
       // 64 bit key 
       regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Dell"; 
      } 

      var regvalue = get_regValue(regKey, "Migrator for GroupWise", "AdminInstallDir", "gwdirapp.exe"); 
      Process.Start(@regvalue); 
     } 
+1

@Cory:不,你不應該需要。 .NET 4.5是一個in-place升級爲.NET 4,所以它應該是罰款... – 2014-09-05 13:34:13

+0

我同意和服務器2012年,你甚至不能安裝.NET 4,因爲它是操作系統 – JRMackz 2014-09-05 14:14:16

回答

4

我強烈懷疑這無關,與.NET的版本,正在使用。畢竟,從堆棧跟蹤,你可以清楚地看到你的代碼執行:

at MyApplication.Form1.DirectoryExporter_Click(Object sender, EventArgs e) 

我懷疑,問題是權限之一 - 無論你正在試圖做在Windows Server 2012中失敗由於它運行在更加鎖定的環境中。

或者,它可能是你試圖啓動您的開發機器存在一個過程,而不是在服務器上。如果沒有看到代碼,我們無法確定 - 但您應該仔細查看DirectoryExporter_Click中正在執行的操作,特別是在撥打Process.Start時。檢查您嘗試運行的可執行文件,然後檢查它是否存在於服務器上,並且您正在運行的用戶有權執行它。

+0

此服務器的一部分應用程序存在的位置。如果我在.NET 4.5中編譯它,它可以在這臺服務器上運行,不會有其他更改,但是它不會在我的舊機器上運行 – JRMackz 2014-09-05 13:47:03

+1

@JRMackz很可能您嘗試啓動的進程的路徑在服務器上不同。異常消息表示無法找到該文件。它或者不在你期望的地方。 – Trevor 2014-09-05 13:52:28

+0

@JRMackz:這聽起來對我來說不太可能,因爲你收到的例外。這將有助於如果你願意告訴我們,雖然你的代碼... – 2014-09-05 13:55:51

0

我通過編輯代碼解決了這個,如下圖所示:

public string get_regValue(string userroot, string subkey, string keyname, string app) 
{ 
    string userRoot = userroot; 
    string subKey = subkey; 
    string keyName = userRoot + "\\" + subKey; 

    string regValue = (string)Registry.GetValue(keyName, keyname, null); 
    regValue = regValue + app; 

    return regValue; 
} 

private void DirectoryExporter_Click(object sender, EventArgs e) 
{ 
    // Button to Launch the Directory Exporter 
    string regKey; 
    RegistryKey openKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Dell"); 
    // Checks for key, if null (empty) get 32 bit key 

    if (openKey == null) 
    { 
     // 32 bit key 
     regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Dell"; 
    } 
    else 
    { 
     // 64 bit key 
     regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Dell";     
    } 

    var regvalue = get_regValue(regKey, "Migrator for GroupWise", "AdminInstallDir", "gwdirapp.exe"); 
    Process.Start(regvalue); 
+0

只是爲了清楚起見,從'Registry.LocalMachine.OpenSubKey'調用中刪除了'HKEY_LOCAL_MACHINE'。 – 2015-03-11 17:02:59

相關問題