开发者

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.

        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 t开发者_JAVA百科o 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. The finished application will run on Viata/7 and is being tested on 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

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜