开发者

After updating EnvironmentVariable - PATH - I still get a FileNotFoundException on Windows 2003 Server

I'm just starting with a new product and I guess I don't understand the PATH variable. My documentation says to update the PATH like this which I do successfully in a little console application:

using HP.HPTRIM.SDK;

namespace TestSDKforTRIM71
{
class Program
{
    static void Main(string[] args)
    {
        string trimInstallDir = @"C:\Program Files\Hewlett-Packard\HP TRIM";
        string temp = Environment.GetEnvironmentVariable("PATH") + ";" + trimInstallDir;
        Environment.SetEnvironmentVariable("PATH", temp);
        DoTrimStuff();
    }
    public static void DoTrimStuff()
    {
        using (Databa开发者_开发技巧se db = new Database())
        {
            db.Connect();
            Console.WriteLine(db.Id);
        }
        Console.ReadKey();
    }
}
}

In the above project, I have a reference to HP.HPTRIM.SDK which exists at: C:\Program Files\Hewlett-Packard\HP TRIM\HP.HPTRIM.SDK.dll

After the above ran successfully, I tried to permanently change the PATH by using Control Panel:System:Advanced:Environment Variables. I verified the above PATH by examining the registry at HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment. I see the following as the last entry in the PATH value: ;C:\Program Files\Hewlett-Packard\HP TRIM\

I thought this would permanently SET this at the end of the PATH but when I run the above console program with a few lines commented out I get the FileNotFoundException (see below). I am confused about how to get this in the PATH and not have to worry about it anymore.

using HP.HPTRIM.SDK;

namespace TestSDKforTRIM71
{
class Program
{
    static void Main(string[] args)
    {
        //string trimInstallDir = @"C:\Program Files\Hewlett-Packard\HP TRIM";
        //string temp = Environment.GetEnvironmentVariable("PATH") + ";" + trimInstallDir;
        //Environment.SetEnvironmentVariable("PATH", temp);
        DoTrimStuff();     // without setting the PATH this fails despite being in REGISTRY...
    }
    public static void DoTrimStuff()
    {
        using (Database db = new Database())
        {
            db.Connect();
            Console.WriteLine(db.Id);
        }
        Console.ReadKey();
    }
}
}


Only newly started processes that don't inherit their environment from their parent will have the updated PATH. You'll have to at least restart the Visual Studio hosting process, close and re-open your solution. To cover all possible corners, log out and log back in so that Windows Explorer (and thus Visual Studio) also start using the updated environment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜