将脚本蝙蝠转换为c# [英] Convert Script Bat to c#

查看:61
本文介绍了将脚本蝙蝠转换为c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi



我需要帮助如何将脚本蝙蝠转换为c#


 @shift / 0 
@echo off

reg query HKEY_LOCAL_MACHINE \Software \ imotech
if% ERRORLEVEL%EQU 0转到DELREG

reg查询HKEY_CURRENT_USER \Software \ imotech
如果%ERRORLEVEL%EQU 0转到DELREG2

转到BIT

:DELREG
reg DELETE HKEY_LOCAL_MACHINE \Software \imotech / f
rem等待20

reg query HKEY_CURRENT_USER \Software \ imotech
if% ERRORLEVEL%EQU 0转到DELREG2
转到BIT

:DELREG2
reg DELETE HKEY_CURRENT_USER \Software \ imotech / f
rem等待20
转到BIT

:BIT
(如果存在)"%PROGRAMFILES(X86)%" goto RUN64
goto RUN32

:RUN32
"%CD%\ x86.exe" 24 \\\\2500"%CD%\ xXX.exe"
goto关于

:RUN64
"%CD%\ x64.exe" 24 \\\\2500"%CD%\ xXX.exe"
goto关于

:关于
cls
echo ------------------------ -------------
echo - 软件名称:XXX 1.5.x -
echo - 版本:v1.2 -
echo ------ -------------------------------
超时3

解决方案

请问为什么?您是否考虑过使用PowerShell?


否则,您可以使用can RegistryKey.DeleteSubKe y删除整个注册表子项。你可以使用

处理类
以启动程序。


类似

 namespace ConsoleCS 
{
使用系统;
使用System.Diagnostics;
使用Microsoft.Win32;

公共课程
{
public static void Main(string [] args)
{
Registry.LocalMachine.DeleteSubKeyTree(@" Software \\ \\imotech");
Registry.CurrentUser.DeleteSubKeyTree(@" Software \imotech");
if(Environment.Is64BitOperatingSystem)
{
StartExecutable(@"%CD%\ x64.exe",@" 24 \\\\\\\\\\&&;"%CD %\XXX.exe""");
}
其他
{
StartExecutable(@"%CD%\ x86.exe",@" 24 \\\\\\\\&& %\XXX.exe""");
}

Console.WriteLine(" Done。");
Console.ReadLine();
}

private static void StartExecutable(string fileName,string arguments)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = fileName;
startInfo.Arguments = arguments;
using(Process process = new Process())
{
Process.Start(startInfo);
}
}
}
}

显然,您需要添加错误处理。


ps当您控制安装程序并且%CD%指向硬盘或SSD上的路径时,您应该使用正确的路径。 X86程序安装在
%PROGRAMFILES(X86)%(通常是 C:\Program Files(x86))中,并且在 中安装了64位程序。 %PROGRAMFILES%(通常为
C:\Program Files )。 



hi

i need help how to converting script bat to c#

@shift /0
@echo off

reg query HKEY_LOCAL_MACHINE\Software\imotech
if %ERRORLEVEL% EQU 0 goto DELREG

reg query HKEY_CURRENT_USER\Software\imotech
if %ERRORLEVEL% EQU 0 goto DELREG2

goto BIT

:DELREG
reg DELETE HKEY_LOCAL_MACHINE\Software\imotech /f
rem Wait 20

reg query HKEY_CURRENT_USER\Software\imotech
if %ERRORLEVEL% EQU 0 goto DELREG2
goto BIT

:DELREG2
reg DELETE HKEY_CURRENT_USER\Software\imotech /f
rem Wait 20
goto BIT

:BIT
if exist "%PROGRAMFILES(X86)%" goto RUN64
goto RUN32

:RUN32
"%CD%\x86.exe" 24\10\2500 "%CD%\XXX.exe"
goto ABOUT

:RUN64
"%CD%\x64.exe" 24\10\2500 "%CD%\XXX.exe"
goto ABOUT

:ABOUT
cls
echo -------------------------------------
echo - Software Name : XXX 1.5.x -
echo -           Version : v1.2          -
echo -------------------------------------
timeout 3

解决方案

May I ask why? And did you consider using PowerShell?

Otherwise, you use can RegistryKey.DeleteSubKey to remove an entire registry subkey. And you can use the Process class to start programs.

Something like

namespace ConsoleCS
{
    using System;
    using System.Diagnostics;
    using Microsoft.Win32;

    public class Program
    {
        public static void Main(string[] args)
        {
            Registry.LocalMachine.DeleteSubKeyTree(@"Software\imotech");
            Registry.CurrentUser.DeleteSubKeyTree(@"Software\imotech");
            if (Environment.Is64BitOperatingSystem)
            {
                StartExecutable(@"%CD%\x64.exe", @"24\10\2500 ""%CD%\XXX.exe""");
            }
            else
            {
                StartExecutable(@"%CD%\x86.exe", @"24\10\2500 ""%CD%\XXX.exe""");
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }

        private static void StartExecutable(string fileName, string arguments)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = fileName;
            startInfo.Arguments = arguments;
            using (Process process = new Process())
            {
                Process.Start(startInfo);
            }
        }
    }
}

Obviously, you need to add error handling.

p.s. when you control the installer and %CD% points to a path on hard disk or SSD, then you should use the correct paths. X86 programs are installed in %PROGRAMFILES(X86)% (normally C:\Program Files (x86)) and 64-bit programs are installed in %PROGRAMFILES% (normally C:\Program Files). 


这篇关于将脚本蝙蝠转换为c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆