C#-域内-远程机-文件信息-注册表-访问。
来源:互联网 发布:linux 网络配置文件 编辑:程序博客网 时间:2024/05/29 09:26
1. 获取远程机IP地址。
代码
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;
}
{
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;
}
2. 判断系统类型32/64.
代码
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$"; // 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[i].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;
}
}
{
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$"; // 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[i].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;
}
}
3. 从注册表获取某个文件的安装路径信息。
代码
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.
{
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;
}
}
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;
}
}
4. 读取远程机某文件版本信息。
代码
public string GetGenAppVersion(string sRemoteIP,string strDllFilePath)
{
string sGenVersion;
try
{
if (strDllFilePath == "No Geneva Install")
{
sGenVersion = "N/A";
}
else
{
string sDllPath = "\\" + sRemoteIP + "\\" + strDllFilePath.Replace(":", "$") + "AppServer\\ConfigurationManager.exe";
FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo("\\" + sDllPath);
sGenVersion = myFileVersion.FileVersion;
}
}
catch (Exception xe)
{
sGenVersion ="N/A";
}
return sGenVersion;
}
{
string sGenVersion;
try
{
if (strDllFilePath == "No Geneva Install")
{
sGenVersion = "N/A";
}
else
{
string sDllPath = "\\" + sRemoteIP + "\\" + strDllFilePath.Replace(":", "$") + "AppServer\\ConfigurationManager.exe";
FileVersionInfo myFileVersion = FileVersionInfo.GetVersionInfo("\\" + sDllPath);
sGenVersion = myFileVersion.FileVersion;
}
}
catch (Exception xe)
{
sGenVersion ="N/A";
}
return sGenVersion;
}
5. 远程计算机系统版信息。
代码
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;
}
{
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;
}
- C#-域内-远程机-文件信息-注册表-访问。
- 远程注册表访问
- 远程注册表访问
- 远程注册表访问
- 远程注册表访问
- 远程注册表访问
- 远程注册表访问
- 域内批量分发注册表设置
- 域内批量分发注册表设置
- 域内批量分发注册表设置
- 用C#读取注册表信息
- 用C#读取注册表信息
- [Powershell]导出域内主机信息
- mysql c远程访问
- 远程访问文件
- fopen访问远程文件
- PHP远程访问文件
- C#如何读取注册表中的注册信息
- 第五集 项目生命周期的建立
- 第六集 MSF构思阶段项目团队的组建
- Windows操作系统的保留字
- Windows 多批处理间调用.
- MS_HotFix
- C#-域内-远程机-文件信息-注册表-访问。
- Silk_ 运行时_控件_属性_捕捉.
- UNIX SSH 命令
- 使用 Windows service 访问域管理
- 访问 远程机 盘符 设置
- SQL Server 汉字 问号
- 解决 NET FTP Response error: (503) .
- [转 - 改] Perl初级教程 (一)
- [转 - 改] Perl初级教程 (二)