1. 获取远程机IP地址
复制代码
2. 判断系统类型32/64
复制代码
3. 从注册表获取某个文件的安装路径信息
复制代码
4. 读取远程机某文件版本信息
复制代码
5. 远程计算机系统版信息
- public string GetMachineIPAddress(string strMachineName)
- {
- string strMachineIP;
- Ping oP = new Ping(); // Declare a ping hander object.
- PingReply oPR = oP.Send(strMachineName); // Get the return values from ping method.
- strMachineIP = oPR.Address.ToString(); // Get the target machine IP address.
- return strMachineIP;
- }
- public string GetMachineBit(string strMachineName) // Return the remoting machine system bit number.
- {
- string strReturnStatus;
- string strAccessPath;
- string sTempMCIP;
- string[] aFiles;
- bool bISBIT;
- strReturnStatus = "32";
- try
- {
-
- sTempMCIP = GetMachineIPAddress(strMachineName); // Call local method to get the remote machine IP address.
- strAccessPath = @"\\"+ sTempMCIP + @"\\C[ DISCUZ_CODE_10 ]quot;; // Access the remote serveer driver C:.
- aFiles = Directory.GetDirectories(strAccessPath); // Access to the target machine c$\Program Files folder.
- for (int i = 0; i < aFiles.Length - 1; i++) // Ergodic the folder info on remote driver C:
- {
- bISBIT = aFiles.ToString().Contains("Program Files (x86)");
- if (bISBIT) // It is a 64 bit system if contain the X86 folder.
- {
- strReturnStatus = "64"; // Return the judgement result.
- }
- }
-
- return strReturnStatus;
- }
- catch (Exception xe)
- {
- strReturnStatus = xe.Message;
- return strReturnStatus;
- }
-
- }
- public string GetRemoteMachinGenInstallPath(string sRemoteName)
- {
-
- remoteName = sRemoteName;
- strRemoteMCGenInsPath = "No Geneva Install";
-
- try
- {
- if ((GetMachineBit(remoteName) == "32")) //Call local method get the remote system bit info.
- {
- // The sub key path for 32bit system.
- strKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
- }
- else
- {
- if (GetRemoteOSVersion(remoteName).Contains("Microsoft Windows Server 2003")) // The WinServer2003 for 32 and 64 has the same key path, but other OS need access the WOW64 key node path.
- {
- strKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
- }
- else
- {
- // The sub key path for 64bit system.
- strKeyPath = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
- //strKeyPath = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{6F13B97D-6FA6-49A3-90D6-653099B9E7A7}";
- }
- }
- // Open the remote machine uninstall node subkey.
- environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, remoteName).OpenSubKey(strKeyPath);
- if (environmentKey != null)
- {
- lsRemoveSubKeys = environmentKey.GetSubKeyNames(); // Get the all the key name which under the uninstall node.
- if (lsRemoveSubKeys.Length > 0)
- {
- foreach (string uninstallKey in lsRemoveSubKeys) // Ergodic the keys under uninstall and pick up the subkey which has the Gen app install path attribute value.
- {
- RegistryKey rkUninstallKey = environmentKey.OpenSubKey(uninstallKey); // Open subkey node in order to get the attribute text.
- string installpath = (String)rkUninstallKey.GetValue("InstallLocation", String.Empty); // Get the attribute value from InstallLocation node.
- string strDisplayName = (String)rkUninstallKey.GetValue("DisplayName", String.Empty); // Get the attribute value from DisplayName node.
- //string uninstallString = (String)rkUninstallKey.GetValue("UninstallString", String.Empty);
- if (strDisplayName.Contains("Geneva Application Server"))// && !uninstallString.Contains("InstallShield Installation Information"))
- {
- if (CheckRemoteMachineInstallPath(installpath, remoteName))
- {
- strGenSubKey = uninstallKey; // The install key node.
- strRemoteMCGenInsPath = installpath; // The Gen app installed path on remote machine.
- }
-
- }
- }
- }
- }
- environmentKey.Close();
- return strRemoteMCGenInsPath;
- }
- catch (Exception xe)
- {
- string sXE = xe.Message;
- return sXE;
- }
- }
- public string GetGenAppVersion(string sRemoteIP,string strDllFilePath)
- {
- string sGenVersion;
- try
- {
- if (strDllFilePath == "No Geneva Install")
- {
- sGenVersion = "N/A";
- }
- else
- {
- string sDllPath = "\\" + sRemoteIP + "\\" + strDllFilePath.Replace(":", "[ DISCUZ_CODE_12 ]quot;) + "AppServer\\ConfigurationManager.exe";
- FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo("\\" + sDllPath);
-
- sGenVersion = myFileVersion.FileVersion;
- }
- }
- catch (Exception xe)
- {
-
- sGenVersion ="N/A";
- }
-
- return sGenVersion;
- }
- public string GetRemoteOSVersion(string sRemoteName)
- {
- string sVersion;
- sVersion = "NULL";
- strKeyPath = @"SOFTWARE\Microsoft\Windows NT";
- environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, sRemoteName).OpenSubKey(strKeyPath);
- lsRemoveSubKeys = environmentKey.GetSubKeyNames();
- foreach (string uninstallKey in lsRemoveSubKeys) // Ergodic the keys under uninstall and pick up the subkey which has the Gen app install path attribute value.
- {
- RegistryKey rkUninstallKey = environmentKey.OpenSubKey(uninstallKey); // Open subkey node in order to get the attribute text.
- sVersion = (String)rkUninstallKey.GetValue("ProductName", String.Empty);
- }
- return sVersion;
- }