vbscript 的Microsoft.Win32

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 的Microsoft.Win32相关的知识,希望对你有一定的参考价值。

using Microsoft.Win32;

public string FindWinrar(){
  string winrarPath= string.Empty;
  RegistryKey key = Registry.LocalMachine;
  //加载x86路径:在64bit系统中,x86程序注册在Wow6432Node下。
  RegistryKey key32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
  //加载x64路径:在64bit系统中,x64程序在原路径节点下。
  RegistryKey key64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

  RegistryKey subkey = key.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\winrar.EXE", true);
  //获得WINRAR路径
  if (subkey != null)
    winrarPath = subkey.GetValue("Path");
  else
    winrarPath  = My.Computer.Registry.GetValue(@"HKEY_CURRENT_USER\Software\WinRAR SFX", "C%%Program Files (x86)%WinRAR", string.Empty);
  return winrarpath;
  //string[] subKeyNames = spfKey.GetSubKeyNames()
}
using System;
using Microsoft.Win32;
 
public class GetDotNetVersion
{
    public static void Main()
    {
        Console.WriteLine(".NET框架版本:");
        using (RegistryKey ndpKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "").OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
        {
            foreach (string versionKeyName in ndpKey.GetSubKeyNames())
            {
                if (versionKeyName.StartsWith("v"))
                {
 
                    RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
                    string name = (string)versionKey.GetValue("Version", "");
                    string sp = versionKey.GetValue("SP", "").ToString();
                    string install = versionKey.GetValue("Install", "").ToString();
                    if (install == "") //no install info, ust be later
                        Console.WriteLine(versionKeyName + "  " + name);
                    else
                    {
                        if (sp != "" && install == "1")
                        {
                            Console.WriteLine(versionKeyName + "  " + name + "  SP" + sp);
                        }
                    }
                    if (name != "")
                    {
                        continue;
                    }
                    foreach (string subKeyName in versionKey.GetSubKeyNames())
                    {
                        RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
                        name = (string)subKey.GetValue("Version", "");
                        if (name != "")
                            sp = subKey.GetValue("SP", "").ToString();
                        install = subKey.GetValue("Install", "").ToString();
                        if (install == "") //no install info, ust be later
                            Console.WriteLine(versionKeyName + "  " + name);
                        else
                        {
                            if (sp != "" && install == "1")
                            {
                                Console.WriteLine("  " + subKeyName + "  " + name + "  SP" + sp);
                            }
                            else if (install == "1")
                            {
                                Console.WriteLine("  " + subKeyName + "  " + name);
                            }
                        }
                    }
                }
            }
        }
 
        Console.WriteLine();
        Console.WriteLine("操作系统版本:" + System.Environment.OSVersion.ToString());
        Console.WriteLine("当前.NET框架版本:" + System.Environment.Version.ToString());
        Console.ReadKey();
    }
}
Imports Microsoft.Win32
Imports System.Windows.Forms

Dim dialog As New Microsoft.Win32.FolderBrowserDialog
If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
   string txt = dialog.SelectedPath
End If

Dim dialog1 As New System.Windows.Forms.OpenFileDialog
dialog1.InitialDirectory = "C:\"
dialog1.Filter = "JPG|*.jpg|TIF|*.tif|BMP|*.bmp|DOC|*.doc|TXT|*.txt|RTF|*.rtf|PDF|*.pdf|XLS|*.xls|*|*.*"
dialog1.FilterIndex = 1
If dialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
   string txt =  dialog1.FileName
End If

以上是关于vbscript 的Microsoft.Win32的主要内容,如果未能解决你的问题,请参考以下文章

72注册表操作 Microsoft.Win32

如何在 C# 中删除注册表值

vbscript 使用OLE32生成GUID

如何在 64 位机器上以 32 位模式运行 VBScript?

vbscript 从32位应用程序读取和写入64位注册表

Registry.CurrentUser.CreateSubKey 没有创建任何子键?