System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "Regsvr32.exe";
process.StartInfo.Arguments = Application.StartupPath + "\\" + @"MapWinGIS\MapWinGIS.ocx";
process.StartInfo.Verb = "RunAs";
process.Start();
Console.WriteLine("Registe Success");
因为路径中如果存在空格,路径会被截断。怎么解决?
Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"CLSID\{03A98C90-70FF-40C7-AD93-6BF8B41B170F}",Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);
if (registryKey != null)
{
Console.WriteLine("Start UnReg");
registryKey.DeleteSubKeyTree(@"CLSID\{03A98C90-70FF-40C7-AD93-6BF8B41B170F}");
registryKey.Close();
}
Microsoft.Win32.RegistryKey registryKey1 = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"CLSID\{03A98C90-70FF-40C7-AD93-6BF8B41B170F}",true);
if (registryKey1 != null)
{
registryKey.DeleteSubKeyTree(@"CLSID\{03A98C90-70FF-40C7-AD93-6BF8B41B170F}");
registryKey1.Close();
}
else
{
Console.WriteLine("Unregister success");
}
了解单双引号。
for /r %a in (*) do if exist "%a" echo %a
不是很懂
能说详细点吗?
因为路径不确定,所以使用Application.StartupPath
获取exe文件所在目录(这个目录可能会有空格),然后加上"MapWinGIS\MapWinGIS.ocx"
ocx文件的路径
您好,我明白你的意思了。搞定了!
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "Regsvr32.exe";
//就是这句话
process.StartInfo.Arguments ='"'+ "F:\\visual studio" + "\\" + @"MapWinGIS\MapWinGIS.ocx"+'"';
process.StartInfo.Verb = "RunAs";
process.Start();
Console.WriteLine("Registe Success");
就是用双引号把文件路径包裹住