C#-域内-远程机-文件信息-注册表-访问。

  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;
        }

 

 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;
            }
            
        }

 

 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.
                    {
                        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; 
        }

 

 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;
        }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值