2011-05-16 4 views
2

프로그래밍 방식으로 procmon.exe를 실행하는 AutoIt 코드가 있습니다. 이제 Microsoft Visual Studio를 통해 실행할 수 있도록 코드를 C#으로 변환하여 누군가가이를 완료하도록 안내 할 수 있습니까? C#을 사용하여 프로그래밍 방식으로 procmon.exe 실행

{ 

Global $scriptDir = FileGetShortName(@ScriptDir) 

Global $logDir = "C:\\log\\registry\\" 

Global $date = @YEAR & @MON & @MDAY 

Global $time = @HOUR & @MIN & @SEC 

$ReadUsername = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\COM\Upload", "I") 

Run("procmon.exe /LoadConfig " & $scriptDir 
    & "\\registrymonitoring.pmc /Quiet /AcceptEula /BackingFile " 
    & $logDir & $ReadUsername & "-" & $date & "-" & $time, "", @SW_HIDE) 

} 

어떤 조언 AutoIt을

에서

코드는 C 번호로 번역되어?

답변

4

이 그것을해야한다 :

using System; 
using System.IO; 
using System.Diagnostics; 
using System.Text; 
using System.Runtime.InteropServices; 
using Microsoft.Win32; 

class Program 
{ 
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)] 
    public static extern int GetShortPathName(
     [MarshalAs(UnmanagedType.LPTStr)] 
     string path, 
     [MarshalAs(UnmanagedType.LPTStr)] 
     StringBuilder shortPath, 
     int shortPathLength 
     ); 

    static void Main(string[] args) 
    { 
     string scriptDirLong = Directory.GetParent(Process.GetCurrentProcess().MainModule.FileName).FullName; 
     StringBuilder scriptDir = new StringBuilder(255); 
     GetShortPathName(scriptDirLong, scriptDir, 255); 

     string logDir = @"C:\log\registry\"; 
     string date = System.DateTime.Now.ToString("yyyyMMdd"); 
     string time = System.DateTime.Now.ToString("HHmmss"); 

     string ReadUsername = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\COM\Upload", "I", null); 

     Console.WriteLine(scriptDir + "\r\n" + logDir + "\r\n" + date + "\r\n" + time); 
     Console.ReadKey(); 

     Process.Start("procmon.exe", 
      "/LoadConfig '" + scriptDir.ToString() + "\\registrymonitoring.pmc' /Quiet /AcceptEula /BackingFile " + 
      logDir + ReadUsername + "-" + date + "-" + time); 
    } 
} 

내가 그것에게 그것의 권리를보고 난 Console.WriteLine에 의존하고있어 너무 손이 레지스트리 키 또는 procmon이 없습니다. 내가 할 수있는 유일한 방법은 짧은 이름을 얻는 것이었기 때문에 winapi 함수를 가져 와서 이것을 사용했습니다 (here에서 가져옴).

+0

고마워요. 매트! 당신은 충고가 내게 큰 도움이되었습니다! 건배! – Derek

1

Process 클래스를 살펴보십시오. 당신은이 같은를 시작 정적 인 방법을 사용할 수 있습니다 : 커맨드 당신이 당신의 실행에서 사용하는 문자열입니다

Process.Start(commandLine);

.

관련 문제