简体   繁体   English

从C#表单应用程序中执行远程批处理文件

[英]Execute remote batch file from within a C# forms application

I am working on a VPN dialer that will execute a login script when the connection is successfull using the following method. 我正在使用以下将在连接成功后执行登录脚本的VPN拨号程序。

        Process p = new Process();
        try
        {
            p.StartInfo.UseShellExecute = true;
            p.StartInfo.FileName = @"\\serverName\NETLOGON\Script Test.cmd";
            p.Start();
            p.WaitForExit();
            }
        }

        catch (Exception ex)
        {

        }

The batch file execute properly according to the logging methods in the batch file, but the drives are not acctualy mapped for the user to use. 批处理文件将根据该批处理文件中的日志记录方法正确执行,但是驱动器未强制映射为供用户使用。 Other batch files tested (local & remote) have the same result. 测试的其他批处理文件(本地和远程)具有相同的结果。

I am assuming this has something to do with the application domain or UAC. 我假设这与应用程序域或UAC有关。 The finished application will run on Viata/7 and is being tested on Windows 7. 完成的应用程序将在Viata / 7上运行,并在Windows 7上进行测试。

Any help here would be greatly appreciated. 在这里的任何帮助将不胜感激。

Regards Bert 关于伯特

Mapped Drives are stored in a users profile. 映射的驱动器存储在用户配置文件中。 Which typically gets loaded when the person logs in. The most common way to get access to profile associated resources is to impersonate the user. 当用户登录时,通常会加载该资源。访问配置文件相关资源的最常见方法是模拟用户。

There is a relationally poor (PInvoke) example of how to do this here: http://support.microsoft.com/kb/306158#4 有一个相对较差的(PInvoke)示例,可在此处执行此操作: http : //support.microsoft.com/kb/306158#4

But generally using mapped drives from a script is asking for trouble. 但是通常使用脚本中的映射驱动器会带来麻烦。 IMHO :) 恕我直言 :)

Hope that helps, 希望能有所帮助,

Jan 一月

You can check if there is any exception happened. 您可以检查是否发生任何异常。 I see catch(exception ex) swallows you exception. 我看到catch(except ex)吞噬了您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM