1

以下のコードは32ビットマシンで完全に機能しますが、64ビットマシンでコードをテストしました。64ビットバージョンのcscript.exeを呼び出していたので、コードが機能することを期待していました。

代わりに、コードはスクリプトを実行するポイントに到達し、正確に30秒間待機してから、スクリプトを終了し、プログラムの残りの部分を続行します。ただし、スクリプトは実行されていないようです(手動で実行すると正常に動作します)。

   using (var ServerProcess = new System.Diagnostics.Process())
            {
                var fileInformation = new FileInfo(VBScriptToRun);
                string processFileName = IntPtr.Size == 8 ? @"c:\windows\sysWOW64\cscript.exe " : @"c:\windows\system32\cscript.exe ";
                string processWorkDir = IntPtr.Size == 8 ? @"c:\windows\sysWOW64\" : @"c:\windows\system32\";
                string processArguments = fileInformation.FullName;
                ServerProcess.StartInfo.FileName = processFileName;
                ServerProcess.StartInfo.WorkingDirectory = processWorkDir;
                ServerProcess.StartInfo.Arguments = processArguments;
                ServerProcess.StartInfo.CreateNoWindow = false;
                ServerProcess.StartInfo.UseShellExecute = false;
                ServerProcess.StartInfo.RedirectStandardOutput = true;
                ServerProcess.StartInfo.LoadUserProfile = true;

            EventLogger.Instance.WriteInformation("Total Integration Service Processing File:  Starting to launch the specified program");

            try
            {
                ServerProcess.Start();
                ServerProcess.WaitForExit();
            }catch(Exception e)
            {
            EventLogger.Instance.WriteInforamtion("Error running script: " + e)
            }
4

1 に答える 1

4
// Sample for the Environment.GetFolderPath method
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("GetFolderPath: {0}", 
                 Environment.GetFolderPath(Environment.SpecialFolder.System));
    }
}
/*
This example produces the following results:

GetFolderPath: C:\WINNT\System32
*/

sysWOW6432 ビット Windows アセンブリの場所であるフォルダーにアクセスしようとしないでください。あなたはそれcscript.exeが64ビットプロセスであることを示したのでcscript.exe、Windows 7 x64インストールの場所はSystemディレクトリになります

ソース: http://msdn.microsoft.com/en-us/library/system.environment.specialfolder

また、オペレーティング システムが 64 ビットかどうかを判断するには、以下を使用する必要があります。

public static bool Is64BitOperatingSystem { get; }

http://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem.aspx

[不足している情報に基づいて、これは推測にすぎません] 32 ビット プロセスを開始しようとしているため、現在の方法が失敗していることを指摘しておく必要があります。 IntPtr.Size機械ではなくプロセスに依存しています。

メソッドを使用する場合は、次のコードを使用することに限定されます。

[DllImport("kernel32.dll", SetLastError=true)]
  [return:MarshalAs(UnmanagedType.Bool)]
  extern static bool IsWow64Process(IntPtr hProcess, [MarshalAs(UnmanagedType.Bool)] out bool isWow64);
  [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError=true)]
  extern static IntPtr GetCurrentProcess();
  [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  extern static IntPtr GetModuleHandle(string moduleName);
  [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError=true)]
  extern static IntPtr GetProcAddress(IntPtr hModule, string methodName);

あなたが使用することができます

System.Environment.GetEnvironmentVariable( "PROCESSOR_ARCHITECTURE" )

ただし、プロセスが 32 ビット プロセスの場合は x86 が返されます。

.NET 4.0 メソッドを使用する方が適切です。

これを使用することもできます:

public static bool Is64BitProcess { get; }

cscript.exeこのようにして、実際に起動するものを知ることができます。プロセスが 64 ビットの場合は、64 ビット プロセスとのみ通信する必要があります。32 ビットの場合は、32 ビット プロセスのみを起動します。

Windows 7 x64 は、おそらくシステム ディレクトリSystemsysWOW64システム ディレクトリに、この正確なバージョンを複数保持していると思います。

プロセスが実際には 64 ビット プロセスでない場合c:\windows\system32、64 ビット インストールでは見つかりません。調べてみると[なぜあなたの代わりに私がこれを調査しなければならないのですか? ]Environment.SpecialFolder.SystemX86は正しい場所を指します。

于 2012-06-27T15:29:06.847 に答える